|
7 | 7 | tags: ["v*"]
|
8 | 8 | branches: [ main ]
|
9 | 9 | workflow_dispatch:
|
10 |
| - # Run on pull requests to test docker build. |
11 |
| - # We explicitly do not push on pull requests (the job below is ended early). |
| 10 | + # Run on pull requests so that the docker build is tested. |
| 11 | + # |
| 12 | + # We explicitly do not push on pull requests (see `if` conditionals and `push` |
| 13 | + # attribute of `docker/build-push-action` below). This prevents us from filling |
| 14 | + # up the container registries with in-progress builds. |
12 | 15 | #
|
13 | 16 | # note: secrets will not be populated on pull requests from external authors.
|
14 | 17 | pull_request:
|
@@ -38,32 +41,35 @@ jobs:
|
38 | 41 | type=sha,prefix=,format=long
|
39 | 42 | type=semver,pattern=v{{version}}
|
40 | 43 | type=semver,pattern=v{{major}}.{{minor}}
|
41 |
| - |
42 |
| - - name: Don't push to registry if this is a PR |
43 |
| - if: "${{ github.event_name }}" = "pull_request" |
44 |
| - run: | |
45 |
| - echo "Not pushing the image to any container registry as this workflow is running on a pull request" |
46 |
| - exit 0 |
47 | 44 |
|
48 | 45 | - name: Log in to DockerHub
|
| 46 | + if: github.event_name != 'pull_request' |
49 | 47 | uses: docker/login-action@v2
|
50 | 48 | with:
|
51 | 49 | username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
52 | 50 | password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
53 | 51 |
|
54 | 52 | - name: Log in to GHCR
|
| 53 | + if: github.event_name != 'pull_request' |
55 | 54 | uses: docker/login-action@v2
|
56 | 55 | with:
|
57 | 56 | registry: ghcr.io
|
58 | 57 | username: ${{ github.repository_owner }}
|
59 | 58 | password: ${{ secrets.GITHUB_TOKEN }}
|
60 | 59 |
|
61 | 60 | - name: Build and push all platforms
|
62 |
| - uses: docker/build-push-action@v4 |
| 61 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
63 | 62 | with:
|
64 |
| - push: true |
| 63 | + # Always build, but don't push to container registries on PRs. |
| 64 | + push: ${{ github.event_name != 'pull_request' }} |
65 | 65 | labels: "gitsha1=${{ github.sha }}"
|
66 | 66 | tags: "${{ steps.set-tag.outputs.tags }}"
|
67 | 67 | platforms: linux/amd64,linux/arm64
|
68 |
| - cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache |
69 |
| - cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max |
| 68 | + # Cache to GitHub Actions backend (which is evicted after 7 days). |
| 69 | + # This doesn't require authentication (unlike a registry), so works |
| 70 | + # well with external PRs. |
| 71 | + # |
| 72 | + # This backend does prevent workflows on other repos from accessing it, |
| 73 | + # but that is not necessary right now. |
| 74 | + cache-from: type=gha |
| 75 | + cache-to: type=gha,mode=max |
0 commit comments