|
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 |
|
8 | | -env: |
9 | | - REGISTRY: ghcr.io |
10 | | - IMAGE_NAME: ${{ github.repository }} |
11 | | - |
12 | 8 | permissions: |
13 | 9 | contents: write |
14 | 10 | packages: write |
@@ -52,69 +48,33 @@ jobs: |
52 | 48 | version=$(yq -r '.version' package.json) |
53 | 49 | echo "version=$version" >> $GITHUB_OUTPUT |
54 | 50 |
|
| 51 | + # Build the release image directly from the version-bump commit that triggered |
| 52 | + # this workflow, so the version baked into the image (src/version.ts, generated |
| 53 | + # from package.json at build time) matches the release tag. Previously this job |
| 54 | + # retagged the pre-bump `main` image, which left the image reporting the prior |
| 55 | + # version. Mirrors the build.yml invocation, adding the versioned + latest tags. |
55 | 56 | tag-release-image: |
56 | | - runs-on: ubuntu-22.04 |
57 | 57 | needs: [get-version] |
58 | | - steps: |
59 | | - - name: Log in to Container Registry |
60 | | - uses: docker/login-action@v3 |
61 | | - with: |
62 | | - registry: ${{ env.REGISTRY }} |
| 58 | + permissions: |
| 59 | + contents: read |
| 60 | + packages: write |
| 61 | + uses: docker/github-builder/.github/workflows/build.yml@v1 |
| 62 | + with: |
| 63 | + output: image |
| 64 | + push: true |
| 65 | + platforms: linux/amd64,linux/arm64 |
| 66 | + meta-images: ghcr.io/${{ github.repository }} |
| 67 | + meta-tags: | |
| 68 | + type=raw,value=v${{ needs.get-version.outputs.version }} |
| 69 | + type=raw,value=latest |
| 70 | + sign: false |
| 71 | + cache: true |
| 72 | + secrets: |
| 73 | + registry-auths: | |
| 74 | + - registry: ghcr.io |
63 | 75 | username: ${{ github.actor }} |
64 | 76 | password: ${{ secrets.GITHUB_TOKEN }} |
65 | 77 |
|
66 | | - - name: Get latest main SHA tag from package repository |
67 | | - id: get-sha |
68 | | - run: | |
69 | | - REPO_OWNER="${{ github.repository_owner }}" |
70 | | - REPO_NAME="$(basename ${{ github.repository }})" |
71 | | -
|
72 | | - # Check if the repo belongs to an org or user |
73 | | - TYPE_CHECK=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
74 | | - -H "Accept: application/vnd.github.v3+json" \ |
75 | | - "https://api.github.com/users/${REPO_OWNER}" | \ |
76 | | - jq -r '.type') |
77 | | -
|
78 | | - if [[ "$TYPE_CHECK" == "Organization" ]]; then |
79 | | - OWNER_TYPE="orgs" |
80 | | - else |
81 | | - OWNER_TYPE="users" |
82 | | - fi |
83 | | -
|
84 | | - MAIN_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
85 | | - -H "Accept: application/vnd.github.v3+json" \ |
86 | | - "https://api.github.com/${OWNER_TYPE}/${REPO_OWNER}/packages/container/${REPO_NAME}/versions" | \ |
87 | | - jq -r '.[] | select(.metadata.container.tags | index("main")) | .metadata.container.tags[]' | grep '^sha-') |
88 | | - echo "main_sha=$MAIN_SHA" >> $GITHUB_OUTPUT |
89 | | - echo "Main SHA: $MAIN_SHA" |
90 | | -
|
91 | | - - name: Pull, retag and push release image |
92 | | - run: | |
93 | | - # Ensure image names are all lowercase |
94 | | - REPO_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') |
95 | | -
|
96 | | - # Source image with SHA tag |
97 | | - SOURCE_IMAGE="${{ env.REGISTRY }}/${REPO_NAME_LOWER}:${{ steps.get-sha.outputs.main_sha }}" |
98 | | - # Target image with release tag |
99 | | - TARGET_IMAGE="${{ env.REGISTRY }}/${REPO_NAME_LOWER}:v${{ needs.get-version.outputs.version }}" |
100 | | - # Latest tag |
101 | | - LATEST_IMAGE="${{ env.REGISTRY }}/${REPO_NAME_LOWER}:latest" |
102 | | -
|
103 | | - echo "Pulling source image: $SOURCE_IMAGE" |
104 | | - docker pull $SOURCE_IMAGE |
105 | | -
|
106 | | - echo "Tagging as: $TARGET_IMAGE" |
107 | | - docker tag $SOURCE_IMAGE $TARGET_IMAGE |
108 | | -
|
109 | | - echo "Tagging as: $LATEST_IMAGE" |
110 | | - docker tag $SOURCE_IMAGE $LATEST_IMAGE |
111 | | -
|
112 | | - echo "Pushing release image: $TARGET_IMAGE" |
113 | | - docker push $TARGET_IMAGE |
114 | | -
|
115 | | - echo "Pushing latest image: $LATEST_IMAGE" |
116 | | - docker push $LATEST_IMAGE |
117 | | -
|
118 | 78 | add-release-artifacts: |
119 | 79 | runs-on: ubuntu-22.04 |
120 | 80 | needs: [tag-release-image, get-version] |
|
0 commit comments