Skip to content

Commit ca62f34

Browse files
authored
fix: only push images and charts on releases with proper package association (#217)
- Build job now only tests Docker builds (no pushing) - Release job pushes images only when release-please creates a release - Added comprehensive OCI labels for proper GitHub package association - Images will be properly linked to repository in GitHub packages - Helm charts published to ghcr.io/weaveworks/charts only on releases
1 parent ca47fe6 commit ca62f34

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

.github/workflows/ci.yaml

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,9 @@ on:
1111

1212
env:
1313
REGISTRY: ghcr.io
14-
IMAGE_NAME: ${{ github.repository }}
1514
GOPRIVATE: github.com/weaveworks/cluster-controller
1615

1716
jobs:
18-
release-please:
19-
runs-on: ubuntu-latest
20-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
21-
permissions:
22-
contents: write
23-
pull-requests: write
24-
issues: write
25-
repository-projects: write
26-
outputs:
27-
release_created: ${{ steps.release.outputs.release_created }}
28-
tag_name: ${{ steps.release.outputs.tag_name }}
29-
steps:
30-
- name: Run release-please
31-
id: release
32-
uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
33-
with:
34-
release-type: go
35-
3617
test:
3718
runs-on: ubuntu-latest
3819
permissions:
@@ -88,7 +69,6 @@ jobs:
8869
needs: [test]
8970
permissions:
9071
contents: read # for actions/checkout to fetch code
91-
packages: write # for pushing to ghcr.io
9272
steps:
9373
- name: Checkout
9474
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -100,43 +80,42 @@ jobs:
10080
id: get_version
10181
run: echo "VERSION=$(make version)" >> $GITHUB_OUTPUT
10282

103-
- name: Log in to the Container registry
104-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
105-
with:
106-
registry: ${{ env.REGISTRY }}
107-
username: ${{ github.actor }}
108-
password: ${{ secrets.GITHUB_TOKEN }}
109-
110-
- name: Extract metadata (tags, labels) for Docker
111-
id: meta
112-
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
113-
with:
114-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
115-
tags: |
116-
type=ref,event=branch
117-
type=ref,event=pr
118-
type=semver,pattern={{version}}
119-
type=semver,pattern={{major}}.{{minor}}
120-
type=raw,value=latest,enable={{is_default_branch}}
121-
12283
- name: Configure git for private modules
12384
env:
12485
GITHUB_BUILD_USERNAME: ${{ secrets.BUILD_BOT_USER }}
12586
GITHUB_BUILD_TOKEN: ${{ secrets.BUILD_BOT_PERSONAL_ACCESS_TOKEN }}
12687
run: git config --global url."https://${GITHUB_BUILD_USERNAME}:${GITHUB_BUILD_TOKEN}@github.com".insteadOf "https://github.com"
12788

128-
- name: Build and push Docker image
89+
- name: Build Docker image (test only)
12990
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
13091
with:
13192
context: .
132-
push: true
133-
tags: ${{ steps.meta.outputs.tags }}
134-
labels: ${{ steps.meta.outputs.labels }}
93+
push: false
94+
tags: gitopssets-controller:test
13595
build-args: VERSION=${{ steps.get_version.outputs.VERSION }}
13696

97+
release-please:
98+
runs-on: ubuntu-latest
99+
needs: [build]
100+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
101+
permissions:
102+
contents: write
103+
pull-requests: write
104+
issues: write
105+
repository-projects: write
106+
outputs:
107+
release_created: ${{ steps.release.outputs.release_created }}
108+
tag_name: ${{ steps.release.outputs.tag_name }}
109+
steps:
110+
- name: Run release-please
111+
id: release
112+
uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
113+
with:
114+
release-type: go
115+
137116
release:
138117
runs-on: ubuntu-latest
139-
needs: [build, test, release-please]
118+
needs: [release-please]
140119
# only run when release-please creates a release
141120
if: needs.release-please.outputs.release_created == 'true'
142121
permissions:
@@ -170,6 +149,31 @@ jobs:
170149
username: ${{ github.actor }}
171150
password: ${{ secrets.GITHUB_TOKEN }}
172151

152+
- name: Configure git for private modules
153+
env:
154+
GITHUB_BUILD_USERNAME: ${{ secrets.BUILD_BOT_USER }}
155+
GITHUB_BUILD_TOKEN: ${{ secrets.BUILD_BOT_PERSONAL_ACCESS_TOKEN }}
156+
run: git config --global url."https://${GITHUB_BUILD_USERNAME}:${GITHUB_BUILD_TOKEN}@github.com".insteadOf "https://github.com"
157+
158+
- name: Build and push release Docker image
159+
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
160+
with:
161+
context: .
162+
push: true
163+
tags: |
164+
ghcr.io/weaveworks/gitopssets-controller:${{ steps.get_version.outputs.VERSION }}
165+
ghcr.io/weaveworks/gitopssets-controller:latest
166+
labels: |
167+
org.opencontainers.image.title=GitOpsSet Controller
168+
org.opencontainers.image.description=A controller for managing GitOpsSet resources
169+
org.opencontainers.image.source=https://github.com/weaveworks/gitopssets-controller
170+
org.opencontainers.image.url=https://github.com/weaveworks/gitopssets-controller
171+
org.opencontainers.image.documentation=https://github.com/weaveworks/gitopssets-controller
172+
org.opencontainers.image.version=${{ steps.get_version.outputs.VERSION }}
173+
org.opencontainers.image.revision=${{ github.sha }}
174+
org.opencontainers.image.licenses=Apache-2.0
175+
build-args: VERSION=${{ steps.get_version.outputs.VERSION }}
176+
173177
- name: Build and publish Helm chart
174178
run: |
175179
make publish-helm-chart

0 commit comments

Comments
 (0)