Skip to content

Commit b30746d

Browse files
authored
Use semver-prefixed tags for OCI artifacts: (tinkerbell#31)
## Description Tags now follow the vX.Y.Z-<sha> format (e.g. v0.1.0-abc1234), derived from the latest semver tag on main via git describe, falling back to v0.0.0 when no tag exists. Both ci.yml and release.yml are updated to produce and consume the new format. Fixes: # ## How Has This Been Tested? ## How are existing users impacted? What migration steps/scripts do we need? ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents 90e6f75 + adaf0b8 commit b30746d

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ jobs:
352352
steps:
353353
- name: Checkout code
354354
uses: actions/checkout@v6
355+
with:
356+
fetch-depth: 0
355357

356358
- name: Load shared config
357359
run: cat .github/config.env >> "$GITHUB_ENV"
@@ -402,17 +404,20 @@ jobs:
402404
if: github.ref == 'refs/heads/main'
403405
uses: oras-project/setup-oras@v1
404406

405-
- name: Compute short SHA
406-
id: short-sha
407-
run: echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
407+
- name: Compute version tag
408+
id: version-tag
409+
run: |
410+
VERSION=$(git describe --tags --first-parent --abbrev=0 --match 'v[0-9]*' 2>/dev/null || echo "v0.0.0")
411+
SHA=${GITHUB_SHA::7}
412+
echo "tag=${VERSION}-${SHA}" >> "$GITHUB_OUTPUT"
408413
409414
- name: Push artifacts to GHCR
410415
if: github.ref == 'refs/heads/main'
411416
working-directory: out
412417
run: |
413418
oras push \
414419
--artifact-platform linux/${{ matrix.arch }} \
415-
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.short-sha.outputs.sha }}-${{ matrix.arch }} \
420+
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.version-tag.outputs.tag }}-${{ matrix.arch }} \
416421
--annotation org.opencontainers.image.source=https://github.com/${{ github.repository }} \
417422
--annotation org.opencontainers.image.revision=${{ github.sha }} \
418423
vmlinuz-${{ matrix.arch }} \
@@ -430,6 +435,8 @@ jobs:
430435
steps:
431436
- name: Checkout code
432437
uses: actions/checkout@v6
438+
with:
439+
fetch-depth: 0
433440

434441
- name: Load shared config
435442
run: cat .github/config.env >> "$GITHUB_ENV"
@@ -444,15 +451,18 @@ jobs:
444451
- name: Install ORAS
445452
uses: oras-project/setup-oras@v1
446453

447-
- name: Compute short SHA
448-
id: short-sha
449-
run: echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
454+
- name: Compute version tag
455+
id: version-tag
456+
run: |
457+
VERSION=$(git describe --tags --first-parent --abbrev=0 --match 'v[0-9]*' 2>/dev/null || echo "v0.0.0")
458+
SHA=${GITHUB_SHA::7}
459+
echo "tag=${VERSION}-${SHA}" >> "$GITHUB_OUTPUT"
450460
451461
- name: Create multi-arch artifact index
452462
run: |
453463
REPO="ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}"
454-
SHA="${{ steps.short-sha.outputs.sha }}"
464+
TAG="${{ steps.version-tag.outputs.tag }}"
455465
oras manifest index create \
456-
"${REPO}:${SHA}" \
457-
"${REPO}:${SHA}-amd64" \
458-
"${REPO}:${SHA}-arm64"
466+
"${REPO}:${TAG}" \
467+
"${REPO}:${TAG}-amd64" \
468+
"${REPO}:${TAG}-arm64"

.github/workflows/release.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v6
17+
with:
18+
fetch-depth: 0
1719

1820
- name: Log in to GHCR
1921
uses: docker/login-action@v3
@@ -28,20 +30,23 @@ jobs:
2830
- name: Load shared config
2931
run: cat .github/config.env >> "$GITHUB_ENV"
3032

31-
- name: Compute short SHA
32-
id: short-sha
33-
run: echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
33+
- name: Compute version tag
34+
id: version-tag
35+
run: |
36+
VERSION=$(git describe --tags --first-parent --abbrev=0 --match 'v[0-9]*' --exclude='${{ github.ref_name }}' 2>/dev/null || echo "v0.0.0")
37+
SHA=${GITHUB_SHA::7}
38+
echo "tag=${VERSION}-${SHA}" >> "$GITHUB_OUTPUT"
3439
3540
- name: Pull release artifacts (amd64)
3641
run: |
3742
oras pull --platform linux/amd64 \
38-
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.short-sha.outputs.sha }} \
43+
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.version-tag.outputs.tag }} \
3944
-o artifacts/amd64/
4045
4146
- name: Pull release artifacts (arm64)
4247
run: |
4348
oras pull --platform linux/arm64 \
44-
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.short-sha.outputs.sha }} \
49+
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.version-tag.outputs.tag }} \
4550
-o artifacts/arm64/
4651
4752
- name: Create GitHub Release
@@ -57,5 +62,5 @@ jobs:
5762
- name: Tag OCI artifact index with version
5863
run: |
5964
oras tag \
60-
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.short-sha.outputs.sha }} \
65+
ghcr.io/${{ github.repository }}/${{ env.OCI_ARTIFACT_NAME }}:${{ steps.version-tag.outputs.tag }} \
6166
${{ github.ref_name }}

0 commit comments

Comments
 (0)