fix: release on pr merge #4
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: Update Buildpack and Run Image Versions | |
| on: | |
| push: | |
| tags: | |
| - '*' | |
| pull_request: | |
| types: [closed] | |
| jobs: | |
| validate-tag: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.get_version.outputs.VERSION }} | |
| repo_lower: ${{ steps.lowercase_repo.outputs.REPO }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get tag version | |
| id: get_version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" | |
| - name: lowercase REPO | |
| id: lowercase_repo | |
| run: | | |
| echo "REPO=${GITHUB_REPOSITORY@L}" >> "${GITHUB_OUTPUT}" | |
| - name: Verify tag originates from main branch | |
| id: check_branch | |
| run: | | |
| TAG_COMMIT=$(git rev-list -n 1 ${{ steps.get_version.outputs.VERSION }}) | |
| echo "Tag points to commit: $TAG_COMMIT" | |
| if ! git merge-base --is-ancestor $TAG_COMMIT origin/main; then | |
| echo "❌ Error: Tag ${{ steps.get_version.outputs.VERSION }} does not originate from main branch" | |
| exit 1 | |
| fi | |
| echo "✅ Tag ${{ steps.get_version.outputs.VERSION }} originates from main branch" | |
| build-and-push-run-image: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| needs: validate-tag | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver: docker-container | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push run-image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./run-image | |
| file: ./run-image/Dockerfile | |
| push: true | |
| tags: ghcr.io/${{ needs.validate-tag.outputs.repo_lower }}/base-image:${{ needs.validate-tag.outputs.version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| create-version-update-pr: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| needs: [validate-tag, build-and-push-run-image] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update buildpack.toml versions | |
| run: make update-buildpack-versions RELEASE_VERSION=${{ needs.validate-tag.outputs.version }} | |
| - name: Update builder.toml | |
| run: make update-builder-versions RELEASE_VERSION=${{ needs.validate-tag.outputs.version }} | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "chore(release): Update buildpack and run-image versions to ${{ needs.validate-tag.outputs.version }}" | |
| title: "chore(release): Update versions to ${{ needs.validate-tag.outputs.version }}" | |
| body: | | |
| Automated version update for release ${{ needs.validate-tag.outputs.version }} | |
| - Updated buildpack.toml versions | |
| - Updated builder.toml versions | |
| This PR was created automatically by the release workflow. | |
| **Please review and merge to complete the release process.** | |
| branch: update-versions-${{ needs.validate-tag.outputs.version }} | |
| base: main | |
| delete-branch: true | |
| release: | |
| if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.head_ref, 'update-versions-') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Extract version from branch name | |
| id: extract_version | |
| run: | | |
| VERSION=${GITHUB_HEAD_REF#update-versions-} | |
| echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Move tag to merged commit | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -f ${{ steps.extract_version.outputs.VERSION }} | |
| git push origin ${{ steps.extract_version.outputs.VERSION }} --tags | |
| - name: publish buildpacks | |
| run: make publish_buildpacks | |
| - name: publish builders | |
| run: make publish_builders | |
| - name: Create Release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: '${{ steps.extract_version.outputs.VERSION }}', | |
| name: 'Release ${{ steps.extract_version.outputs.VERSION }}', | |
| draft: false, | |
| prerelease: false, | |
| }); | |
| - name: Cleanup branch | |
| run: | | |
| git push origin --delete update-versions-${{ steps.extract_version.outputs.VERSION }} |