Build and Push Docker image to GHCR #12
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker image to GHCR | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract tag | |
| id: vars | |
| run: echo "TAG=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" | |
| - name: Verify version matches tag | |
| run: | | |
| TAG="${{ steps.vars.outputs.TAG }}" | |
| # Read the version file that was committed with the tag | |
| VERSION_IN_FILE=$(cat internal/apiframework/version.txt | tr -d '\n' | tr -d '\r') | |
| # Compare with tag | |
| if [ "$VERSION_IN_FILE" != "$TAG" ]; then | |
| echo "ERROR: Version in file ($VERSION_IN_FILE) does NOT match tag ($TAG)" | |
| echo "This means the tag was created without updating the version file first." | |
| echo "Proper release process:" | |
| echo " 1. Update version file with new version" | |
| echo " 2. Commit the change" | |
| echo " 3. Create tag pointing to THAT commit" | |
| echo " 4. Push tag" | |
| echo "" | |
| echo "To fix this:" | |
| echo " git checkout $TAG" | |
| echo " echo -n '$TAG' > internal/apiframework/version.txt" | |
| echo " git commit -m 'Update version to $TAG' internal/apiframework/version.txt" | |
| echo " git tag -d $TAG" | |
| echo " git tag $TAG" | |
| echo " git push -f origin $TAG" | |
| exit 1 | |
| fi | |
| echo "✓ Version verification passed: $VERSION_IN_FILE matches tag" | |
| - name: Build and push to GHCR | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/runtime:${{ steps.vars.outputs.TAG }} | |
| ghcr.io/${{ github.repository_owner }}/runtime:latest |