Merge pull request #162 from terraform-redhat/amandahla-patch-1 #1
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 Changelog | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| tag-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Validate stable release tag | |
| id: check-tag | |
| run: | | |
| set -euo pipefail | |
| echo "Tag validation" | |
| [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] \ | |
| || { echo "Tag '${GITHUB_REF_NAME}' doesn't match expected format"; exit 1; } | |
| update-changelog: | |
| needs: tag-check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Find previous release tag | |
| id: prev-tag | |
| run: | | |
| git fetch --tags --force | |
| CURRENT_TAG="${{ github.ref_name }}" | |
| PREV_TAG=$(git tag -l 'v*' | grep -v -E '(prerelease|test|hotfix)' | sort -V | grep -B1 "^${CURRENT_TAG}$" | head -1) | |
| if [ -z "$PREV_TAG" ]; then | |
| PREV_TAG=$(git tag -l 'v*' | grep -v -E '(prerelease|test|hotfix)' | sort -V | tail -1) | |
| fi | |
| echo "Auto-detected previous tag: $PREV_TAG" | |
| echo "prev_tag=$PREV_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Check if there are commits between tags | |
| id: check-commits | |
| run: | | |
| COUNT=$(git rev-list --count "${{ steps.prev-tag.outputs.prev_tag }}..${{ github.ref_name }}" || echo "0") | |
| echo "commit_count=$COUNT" >> "$GITHUB_OUTPUT" | |
| echo "Found $COUNT commit(s) between ${{ steps.prev-tag.outputs.prev_tag }} and ${{ github.ref_name }}" | |
| - name: Version without leading v | |
| run: echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" | |
| - name: Generate changelog | |
| if: steps.check-commits.outputs.commit_count != '0' | |
| uses: orhun/git-cliff-action@f50e11560dce63f7c33227798f90b924471a88b5 # v4.8.0 | |
| id: git-cliff | |
| with: | |
| config: cliff.toml | |
| args: --verbose ${{ steps.prev-tag.outputs.prev_tag }}..${{ github.ref_name }} --tag ${{ env.RELEASE_VERSION }} --prepend CHANGELOG.md | |
| - name: Create PR with changelog | |
| if: steps.check-commits.outputs.commit_count != '0' | |
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: changelog-${{ github.ref_name }} | |
| base: main | |
| title: "OCM-00000 | chore: add changelog for ${{ github.ref_name }}" | |
| body: | | |
| ## Changelog for ${{ github.ref_name }} | |
| Auto-generated changelog entry for release ${{ github.ref_name }}. | |
| **Release tag**: `${{ github.ref_name }}` | |
| **Previous tag**: `${{ steps.prev-tag.outputs.prev_tag }}` | |
| Auto-generated by GitHub Actions. | |
| commit-message: | | |
| OCM-00000 | chore: add changelog for ${{ github.ref_name }} | |
| Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | |
| labels: changelog | |
| delete-branch: true | |
| add-paths: "CHANGELOG.md" | |
| sign-commits: true |