|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version to release (e.g., 1.0.0)" |
| 8 | + required: true |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Validate Version |
| 19 | + run: | |
| 20 | + if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 21 | + echo "::error::Version must be in format X.Y.Z (e.g., 1.0.0)" |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + echo "VERSION=${{ inputs.version }}" >> $GITHUB_ENV |
| 25 | + echo "MAJOR_VERSION=$(echo ${{ inputs.version }} | cut -d. -f1)" >> $GITHUB_ENV |
| 26 | +
|
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Generate Changelog |
| 33 | + id: changelog |
| 34 | + uses: mikepenz/release-changelog-builder-action@v5 |
| 35 | + with: |
| 36 | + # Using default configuration since configuration.json does not exist |
| 37 | + mode: "COMMIT" |
| 38 | + env: |
| 39 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Create Changelog PR |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + git config user.name "github-actions[bot]" |
| 46 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 47 | +
|
| 48 | + BRANCH_NAME="chore/changelog-v$VERSION" |
| 49 | + git checkout -b "$BRANCH_NAME" |
| 50 | +
|
| 51 | + # Append changelog to CHANGELOG.md (create if not exists) |
| 52 | + touch CHANGELOG.md |
| 53 | + echo -e "\n## [$VERSION] - $(date +%Y-%m-%d)\n" >> CHANGELOG.md.tmp |
| 54 | + echo "${{ steps.changelog.outputs.changelog }}" >> CHANGELOG.md.tmp |
| 55 | + cat CHANGELOG.md >> CHANGELOG.md.tmp |
| 56 | + mv CHANGELOG.md.tmp CHANGELOG.md |
| 57 | +
|
| 58 | + git add CHANGELOG.md |
| 59 | + git commit -m "chore: update changelog for v$VERSION" |
| 60 | + git push origin "$BRANCH_NAME" |
| 61 | +
|
| 62 | + gh pr create \ |
| 63 | + --title "chore: update changelog for v$VERSION" \ |
| 64 | + --body "Automated changelog update for release v$VERSION" \ |
| 65 | + --base main \ |
| 66 | + --head "$BRANCH_NAME" |
| 67 | +
|
| 68 | + - name: Create Release Branch |
| 69 | + run: | |
| 70 | + git checkout main |
| 71 | + git pull origin main |
| 72 | + git checkout -b "release/v$VERSION" |
| 73 | +
|
| 74 | + - name: Update References |
| 75 | + run: | |
| 76 | + # Replace @main with @v{major} in action.yml and sub-actions |
| 77 | + # We use a broad sed to catch occurrences in both action.yml and sub-action files |
| 78 | + find . -name "action.yml" -print0 | xargs -0 sed -i "s|@main|@v$MAJOR_VERSION|g" |
| 79 | +
|
| 80 | + # Verify if any changes were made |
| 81 | + git diff |
| 82 | +
|
| 83 | + - name: Commit and Push Release Branch |
| 84 | + run: | |
| 85 | + git add . |
| 86 | + # Only commit if there are changes |
| 87 | + if ! git diff --quiet --cached; then |
| 88 | + git commit -m "chore: prepare release v$VERSION" |
| 89 | + git push origin "release/v$VERSION" |
| 90 | + else |
| 91 | + echo "No changes to commit (references might already be correct or using relative paths)." |
| 92 | + # We still push the branch to tag it |
| 93 | + git push origin "release/v$VERSION" |
| 94 | + fi |
| 95 | +
|
| 96 | + - name: Tagging |
| 97 | + run: | |
| 98 | + # Tag specific version |
| 99 | + git tag "v$VERSION" |
| 100 | + git push origin "v$VERSION" |
| 101 | +
|
| 102 | + # Tag/Move major version |
| 103 | + # Force update the major tag to point to this new release |
| 104 | + git tag -f "v$MAJOR_VERSION" |
| 105 | + git push -f origin "v$MAJOR_VERSION" |
| 106 | +
|
| 107 | + - name: Create Release |
| 108 | + uses: softprops/action-gh-release@v2 |
| 109 | + with: |
| 110 | + tag_name: "v${{ inputs.version }}" |
| 111 | + name: "v${{ inputs.version }}" |
| 112 | + body: ${{ steps.changelog.outputs.changelog }} |
| 113 | + prerelease: false |
| 114 | + env: |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + |
| 117 | + - name: Cleanup |
| 118 | + if: always() |
| 119 | + run: | |
| 120 | + # Delete the release branch |
| 121 | + git push origin --delete "release/v$VERSION" || true |
0 commit comments