|
6 | 6 | tags: ["v*"] |
7 | 7 | pull_request: |
8 | 8 | branches: ["*"] |
9 | | - workflow_call: |
10 | 9 |
|
11 | 10 | permissions: |
12 | 11 | contents: read |
|
63 | 62 |
|
64 | 63 | - run: make lint |
65 | 64 | name: Lint |
| 65 | + |
| 66 | + release: |
| 67 | + name: Release |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: [build, lint] # Only run after build and lint pass |
| 70 | + if: | |
| 71 | + github.event_name == 'push' && |
| 72 | + github.ref == 'refs/heads/main' && |
| 73 | + !contains(github.event.head_commit.message, 'skip ci') && |
| 74 | + !contains(github.event.head_commit.message, 'skip release') |
| 75 | +
|
| 76 | + permissions: |
| 77 | + contents: write |
| 78 | + pull-requests: write |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: Checkout |
| 82 | + uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + fetch-depth: 0 |
| 85 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + |
| 87 | + - name: Setup Go |
| 88 | + uses: actions/setup-go@v5 |
| 89 | + with: |
| 90 | + go-version: 1.24.x |
| 91 | + |
| 92 | + # Configure git to use GitHub Actions bot |
| 93 | + - name: Configure Git |
| 94 | + run: | |
| 95 | + git config user.name 'github-actions[bot]' |
| 96 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 97 | +
|
| 98 | + - name: Check for conventional commits |
| 99 | + id: check_commits |
| 100 | + run: | |
| 101 | + # Get commits since last tag |
| 102 | + LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 103 | +
|
| 104 | + if [ -z "$LAST_TAG" ]; then |
| 105 | + echo "No previous tag found, checking all commits" |
| 106 | + COMMITS=$(git log --pretty=format:"%s") |
| 107 | + else |
| 108 | + echo "Checking commits since $LAST_TAG" |
| 109 | + COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"%s") |
| 110 | + fi |
| 111 | +
|
| 112 | + # Check if any commits are releasable (feat, fix, or breaking change) |
| 113 | + RELEASABLE=false |
| 114 | + while IFS= read -r commit; do |
| 115 | + if [[ "$commit" =~ ^(feat|fix)(\(.+\))?!?:|BREAKING\ CHANGE: ]] || [[ "$commit" =~ ^[a-z]+(\(.+\))?!: ]]; then |
| 116 | + RELEASABLE=true |
| 117 | + break |
| 118 | + fi |
| 119 | + done <<< "$COMMITS" |
| 120 | +
|
| 121 | + echo "releasable=$RELEASABLE" >> $GITHUB_OUTPUT |
| 122 | +
|
| 123 | + if [ "$RELEASABLE" = "false" ]; then |
| 124 | + echo "No releasable changes found. Skipping release." |
| 125 | + fi |
| 126 | +
|
| 127 | + - name: Conventional Changelog Action |
| 128 | + id: changelog |
| 129 | + if: steps.check_commits.outputs.releasable == 'true' |
| 130 | + uses: TriPSs/conventional-changelog-action@v5.3.0 |
| 131 | + with: |
| 132 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 133 | + git-message: | |
| 134 | + chore(release): v{version} [skip ci] |
| 135 | +
|
| 136 | + - Update changelog |
| 137 | + - Bump version |
| 138 | + preset: "angular" |
| 139 | + tag-prefix: "v" |
| 140 | + output-file: "docs/reference/changelog.md" |
| 141 | + version-file: "version.json" |
| 142 | + skip-on-empty: "true" |
| 143 | + skip-version-file: "false" |
| 144 | + skip-git-pull: "false" |
| 145 | + create-summary: "true" |
| 146 | + |
| 147 | + - name: Create Release |
| 148 | + if: | |
| 149 | + steps.check_commits.outputs.releasable == 'true' && |
| 150 | + steps.changelog.outputs.skipped == 'false' |
| 151 | + uses: ncipollo/release-action@v1 |
| 152 | + with: |
| 153 | + tag: ${{ steps.changelog.outputs.tag }} |
| 154 | + name: ${{ steps.changelog.outputs.tag }} |
| 155 | + body: ${{ steps.changelog.outputs.clean_changelog }} |
| 156 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments