|
| 1 | +name: build-CI-container |
| 2 | + |
| 3 | +env: |
| 4 | + REGISTRY: ghcr.io |
| 5 | + # NOTE: IMAGE_NAME must be lowercase |
| 6 | + IMAGE_NAME: chai-github-ci |
| 7 | + # NOTE: if this filename changes, also update in the on.paths section below |
| 8 | + DOCKERFILE: .github/docker/Dockerfile |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: [ main ] |
| 13 | + # This limits the action so it only builds when this file changes |
| 14 | + paths: |
| 15 | + # unfortunately we can't use ${{env.DOCKERFILE}} here |
| 16 | + # see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability |
| 17 | + - .github/docker/Dockerfile |
| 18 | + # also trigger on changes to this workflow file itself |
| 19 | + - .github/workflows/build-CI-container.yml |
| 20 | + pull_request: |
| 21 | + paths: |
| 22 | + # same as for pushes above |
| 23 | + - .github/docker/Dockerfile |
| 24 | + - .github/workflows/build-CI-container.yml |
| 25 | + # Adds a "manual run" option in the GH UI |
| 26 | + workflow_dispatch: |
| 27 | + |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: write |
| 35 | + steps: |
| 36 | + - name: Checkout Code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + - name: Login to GitHub Container Registry |
| 39 | + uses: docker/login-action@v1.14.1 |
| 40 | + with: |
| 41 | + registry: ${{ env.REGISTRY }} |
| 42 | + username: ${{ github.actor }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + - name: Build Docker Image |
| 45 | + uses: docker/build-push-action@v2.9.0 |
| 46 | + with: |
| 47 | + file: ${{ env.DOCKERFILE }} |
| 48 | + # example: ghcr.io/chapel-lang/chapel-github-ci:latest |
| 49 | + tags: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest |
| 50 | + - name: Push Docker Image if on main |
| 51 | + uses: docker/build-push-action@v2.9.0 |
| 52 | + with: |
| 53 | + file: ${{ env.DOCKERFILE }} |
| 54 | + push: true |
| 55 | + tags: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest |
0 commit comments