|
11 | 11 | - patch |
12 | 12 | - minor |
13 | 13 | - major |
| 14 | + push: |
| 15 | + branches: |
| 16 | + - main |
14 | 17 |
|
15 | 18 | jobs: |
| 19 | + detect-version: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + version_type: ${{ steps.detect.outputs.version_type }} |
| 23 | + should_release: ${{ steps.detect.outputs.should_release }} |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 1 |
| 29 | + |
| 30 | + - name: Detect version type from commit |
| 31 | + id: detect |
| 32 | + run: | |
| 33 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 34 | + echo "version_type=${{ github.event.inputs.version_type }}" >> $GITHUB_OUTPUT |
| 35 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 36 | + else |
| 37 | + COMMIT_MSG=$(git log -1 --pretty=%s) |
| 38 | + echo "Commit message: $COMMIT_MSG" |
| 39 | + if echo "$COMMIT_MSG" | grep -qE '^[a-z]+(\(.+\))?!:'; then |
| 40 | + echo "Detected: major (breaking change)" |
| 41 | + echo "version_type=major" >> $GITHUB_OUTPUT |
| 42 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 43 | + elif echo "$COMMIT_MSG" | grep -qE '^feat(\(.+\))?:'; then |
| 44 | + echo "Detected: minor (new feature)" |
| 45 | + echo "version_type=minor" >> $GITHUB_OUTPUT |
| 46 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 47 | + elif echo "$COMMIT_MSG" | grep -qE '^fix(\(.+\))?:'; then |
| 48 | + echo "Detected: patch (bug fix)" |
| 49 | + echo "version_type=patch" >> $GITHUB_OUTPUT |
| 50 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 51 | + else |
| 52 | + echo "No release needed for this commit type" |
| 53 | + echo "version_type=none" >> $GITHUB_OUTPUT |
| 54 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 55 | + fi |
| 56 | + fi |
| 57 | +
|
16 | 58 | release: |
| 59 | + needs: detect-version |
| 60 | + if: needs.detect-version.outputs.should_release == 'true' |
17 | 61 | runs-on: ubuntu-latest |
18 | 62 | permissions: |
19 | 63 | contents: write |
|
38 | 82 | - name: Bump npm version |
39 | 83 | id: version |
40 | 84 | run: | |
41 | | - NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version) |
| 85 | + NEW_VERSION=$(npm version ${{ needs.detect-version.outputs.version_type }} --no-git-tag-version) |
42 | 86 | echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT |
43 | 87 | echo "version_number=${NEW_VERSION#v}" >> $GITHUB_OUTPUT |
44 | 88 |
|
|
0 commit comments