Merge pull request #7 from wafflestudio/feat/gha #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-and-push-ghcr | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| dockerfile: | |
| description: "Dockerfile name under ./docker (e.g. isolate.Dockerfile)" | |
| required: true | |
| default: "isolate.Dockerfile" | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=sha | |
| type=ref,event=branch | |
| - name: Build (and push on main) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ${{ github.event_name == 'workflow_dispatch' && format('./docker/{0}', inputs.dockerfile) || './docker/isolate.Dockerfile' }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |