feat: add automatic tag creation on chart PR merge #2
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: Auto Tag Chart Release on PR Merge | ||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: [main] | ||
| jobs: | ||
| auto-tag: | ||
| name: Create Chart Release Tag | ||
| if: | | ||
| github.event.pull_request.merged == true && | ||
| contains(github.event.pull_request.labels.*.name, 'chart-update') | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Extract chart info from PR | ||
| id: extract | ||
| run: | | ||
| PR_TITLE="${{ github.event.pull_request.title }}" | ||
| PR_BRANCH="${{ github.event.pull_request.head.ref }}" | ||
| # Extract chart name and version from branch name | ||
| # Format: update-vault-transit-unseal-operator-1.0.5 | ||
| if [[ "$PR_BRANCH" =~ ^update-([a-zA-Z0-9-]+)-([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then | ||
| CHART_NAME="${BASH_REMATCH[1]}" | ||
| APP_VERSION="${BASH_REMATCH[2]}" | ||
| echo "chart_name=$CHART_NAME" >> $GITHUB_OUTPUT | ||
| echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT | ||
| # Get the chart version from Chart.yaml | ||
| CHART_VERSION=$(yq '.version' "./charts/$CHART_NAME/Chart.yaml") | ||
| echo "chart_version=$CHART_VERSION" >> $GITHUB_OUTPUT | ||
| echo "Chart: $CHART_NAME" | ||
| echo "Chart Version: $CHART_VERSION" | ||
| echo "App Version: $APP_VERSION" | ||
| else | ||
| echo "ERROR: Could not parse chart info from PR branch: $PR_BRANCH" | ||
| exit 1 | ||
| fi | ||
| - name: Create and push tag | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
| TAG_NAME="${{ steps.extract.outputs.chart_name }}-v${{ steps.extract.outputs.chart_version }}" | ||
| # Check if tag already exists | ||
| if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | ||
| echo "Tag $TAG_NAME already exists, skipping..." | ||
| exit 0 | ||
| fi | ||
| # Create and push tag | ||
| git tag -a "$TAG_NAME" -m "Release ${{ steps.extract.outputs.chart_name }} v${{ steps.extract.outputs.chart_version }} | ||
| Chart version: ${{ steps.extract.outputs.chart_version }} | ||
| App version: ${{ steps.extract.outputs.app_version }} | ||
| Automated release from PR #${{ github.event.pull_request.number }}" | ||
| git push origin "$TAG_NAME" | ||
| echo "✅ Created tag: $TAG_NAME" | ||
| - name: Comment on PR | ||
| if: success() | ||
| uses: peter-evans/create-or-update-comment@v4 | ||
| with: | ||
| issue-number: ${{ github.event.pull_request.number }} | ||
| body: | | ||
| 🎉 **Chart Release Tag Created!** | ||
| Tag: `${{ steps.extract.outputs.chart_name }}-v${{ steps.extract.outputs.chart_version }}` | ||
| The Helm chart release workflow will now automatically: | ||
| - Package the chart | ||
| - Update the repository index | ||
| - Create a GitHub release | ||
| - Publish to https://fredericrous.github.io/charts/ | ||
| Monitor progress: [Release Workflow](https://github.com/fredericrous/charts/actions/workflows/helm-release.yaml) | ||