Skip to content

Commit 55c93f4

Browse files
authored
Merge pull request #91 from nanotaboada/ci/normalize-cd-pipeline
ci(cd): normalize and align CD pipeline (#90)
2 parents 70e1f68 + b2fe4be commit 55c93f4

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

.github/workflows/rust-cd.yml

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ env:
1414

1515
jobs:
1616
test:
17-
name: Test before deployment
1817
runs-on: ubuntu-latest
1918
permissions:
2019
contents: read
2120
steps:
2221
- name: Checkout repository
23-
uses: actions/checkout@v6.0.2
22+
uses: actions/checkout@v6
2423

2524
- name: Set up Rust
2625
uses: dtolnay/rust-toolchain@stable
@@ -49,30 +48,31 @@ jobs:
4948
- name: Run tests
5049
run: cargo test --verbose
5150

52-
deploy:
53-
name: Build and publish Docker image
51+
release:
5452
needs: test
5553
runs-on: ubuntu-latest
5654
permissions:
5755
contents: write
5856
packages: write
57+
id-token: write
58+
attestations: write
5959
steps:
6060
- name: Checkout repository
61-
uses: actions/checkout@v6.0.2
61+
uses: actions/checkout@v6
6262
with:
6363
fetch-depth: 0
6464

6565
- name: Verify tag commit is reachable from master
6666
run: |
67-
if ! git branch -r --contains "${{ github.sha }}" | grep -q "origin/master"; then
67+
if ! git merge-base --is-ancestor "${{ github.sha }}" origin/master; then
6868
echo "Error: Commit ${{ github.sha }} is not reachable from origin/master"
6969
echo "Ensure the PR is merged into master before pushing a release tag"
7070
exit 1
7171
fi
7272
echo "Commit ${{ github.sha }} is reachable from origin/master"
7373
7474
- name: Extract version and nominee name from tag
75-
id: extract_tag
75+
id: version
7676
run: |
7777
# Tag format: v1.0.0-benzema
7878
TAG_NAME=${GITHUB_REF#refs/tags/}
@@ -127,18 +127,26 @@ jobs:
127127
uses: docker/setup-buildx-action@v4.0.0
128128

129129
- name: Build and push Docker image to GitHub Container Registry
130+
id: push
130131
uses: docker/build-push-action@v7.1.0
131132
with:
132133
context: .
133134
push: true
134-
platforms: linux/amd64
135-
provenance: false
135+
platforms: linux/amd64,linux/arm64
136+
provenance: mode=max
136137
cache-from: type=gha
137138
cache-to: type=gha,mode=max
138139
tags: |
139140
ghcr.io/${{ github.repository }}:latest
140-
ghcr.io/${{ github.repository }}:${{ steps.extract_tag.outputs.semver }}
141-
ghcr.io/${{ github.repository }}:${{ steps.extract_tag.outputs.nominee }}
141+
ghcr.io/${{ github.repository }}:${{ steps.version.outputs.semver }}
142+
ghcr.io/${{ github.repository }}:${{ steps.version.outputs.nominee }}
143+
144+
- name: Attest build provenance
145+
uses: actions/attest-build-provenance@v4.1.0
146+
with:
147+
subject-name: ghcr.io/${{ github.repository }}
148+
subject-digest: ${{ steps.push.outputs.digest }}
149+
push-to-registry: true
142150

143151
- name: Generate changelog
144152
id: changelog
@@ -148,15 +156,15 @@ jobs:
148156
149157
if [ -z "$PREVIOUS_TAG" ]; then
150158
echo "First release - no previous tag found"
151-
CHANGELOG="Initial release"
159+
CHANGELOG="No changes (first release)"
152160
else
153-
echo "Generating changelog from $PREVIOUS_TAG to ${{ steps.extract_tag.outputs.tag_name }}"
154-
CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${PREVIOUS_TAG}..${{ steps.extract_tag.outputs.tag_name }})
155-
fi
161+
echo "Generating changelog from $PREVIOUS_TAG to ${{ steps.version.outputs.tag_name }}"
162+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges ${PREVIOUS_TAG}..${{ steps.version.outputs.tag_name }})
156163
157-
# Write changelog to file
158-
echo "$CHANGELOG" > changelog.txt
159-
cat changelog.txt
164+
if [ -z "$CHANGELOG" ]; then
165+
CHANGELOG="No new changes since $PREVIOUS_TAG"
166+
fi
167+
fi
160168
161169
# Set output for use in release body
162170
{
@@ -168,32 +176,26 @@ jobs:
168176
- name: Create GitHub Release
169177
uses: softprops/action-gh-release@v2.6.1
170178
with:
171-
name: "v${{ steps.extract_tag.outputs.semver }} - ${{ steps.extract_tag.outputs.nominee }} 🏅"
172-
tag_name: ${{ steps.extract_tag.outputs.tag_name }}
179+
name: "v${{ steps.version.outputs.semver }} - ${{ steps.version.outputs.nominee }} 🏅"
180+
tag_name: ${{ steps.version.outputs.tag_name }}
173181
body: |
174-
# Release ${{ steps.extract_tag.outputs.semver }} - ${{ steps.extract_tag.outputs.nominee }} 🏅
182+
# Release ${{ steps.version.outputs.semver }} - ${{ steps.version.outputs.nominee }} 🏅
175183
176184
## Docker Images
177185
178186
Pull this release using any of the following tags:
179187
180188
```bash
181189
# By semantic version (recommended)
182-
docker pull ghcr.io/${{ github.repository }}:${{ steps.extract_tag.outputs.semver }}
190+
docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.semver }}
183191
184192
# By nominee name
185-
docker pull ghcr.io/${{ github.repository }}:${{ steps.extract_tag.outputs.nominee }}
193+
docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.nominee }}
186194
187195
# Latest
188196
docker pull ghcr.io/${{ github.repository }}:latest
189197
```
190198
191-
## Quick Start
192-
193-
```bash
194-
docker run -p 9000:9000 ghcr.io/${{ github.repository }}:${{ steps.extract_tag.outputs.semver }}
195-
```
196-
197199
## Changes
198200
199201
${{ steps.changelog.outputs.changelog }}

0 commit comments

Comments
 (0)