|
1 | | -name: status |
2 | | -on: push |
| 1 | +name: Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write # Required for OIDC |
| 10 | + contents: read |
3 | 11 |
|
4 | 12 | jobs: |
5 | | - npm: |
6 | | - name: Publish to NPM |
| 13 | + release: |
| 14 | + # Prevent infinite loop |
| 15 | + if: github.actor != 'github-actions[bot]' |
7 | 16 | runs-on: ubuntu-latest |
| 17 | + |
8 | 18 | steps: |
9 | | - - uses: actions/checkout@master |
10 | | - - uses: actions/setup-node@master |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + # ✅ Ensure merge came from development |
| 25 | + - name: Ensure merge came from development |
| 26 | + id: check_merge |
| 27 | + run: | |
| 28 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 29 | +
|
| 30 | + echo "$COMMIT_MSG" |
| 31 | +
|
| 32 | + if echo "$COMMIT_MSG" | grep -q "development"; then |
| 33 | + echo "merged=true" >> $GITHUB_OUTPUT |
| 34 | + else |
| 35 | + echo "merged=false" >> $GITHUB_OUTPUT |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Stop if not a development merge |
| 39 | + if: steps.check_merge.outputs.merged != 'true' |
| 40 | + run: | |
| 41 | + echo "Not a development merge. Skipping." |
| 42 | + exit 0 |
| 43 | +
|
| 44 | + - name: Setup Node |
| 45 | + uses: actions/setup-node@v4 |
11 | 46 | with: |
12 | | - node-version: "12.x" |
| 47 | + node-version: 22 |
| 48 | + - run: npm install |
| 49 | + - run: npm run format |
| 50 | + - run: npm run lint |
| 51 | + - run: npm run build |
| 52 | + |
| 53 | + # ✅ Detect bump type from commit message |
| 54 | + - name: Detect version bump type |
| 55 | + id: bump_type |
| 56 | + run: | |
| 57 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 58 | +
|
| 59 | + if echo "$COMMIT_MSG" | grep -qi "^refactor:"; then |
| 60 | + echo "type=major" >> $GITHUB_OUTPUT |
| 61 | + elif echo "$COMMIT_MSG" | grep -qi "^feat:"; then |
| 62 | + echo "type=minor" >> $GITHUB_OUTPUT |
| 63 | + elif echo "$COMMIT_MSG" | grep -qi "^fix:"; then |
| 64 | + echo "type=patch" >> $GITHUB_OUTPUT |
| 65 | + else |
| 66 | + echo "type=patch" >> $GITHUB_OUTPUT |
| 67 | + fi |
13 | 68 |
|
14 | | - - name: install |
15 | | - run: npm install |
| 69 | + # ✅ Bump version |
| 70 | + - name: Bump version |
| 71 | + run: | |
| 72 | + npm version ${{ steps.bump_type.outputs.type }} --no-git-tag-version |
16 | 73 |
|
17 | | - - name: format |
18 | | - run: npm run format |
| 74 | + git config user.name "github-actions[bot]" |
| 75 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
19 | 76 |
|
20 | | - - name: lint |
21 | | - run: npm run lint |
| 77 | + git add package.json |
| 78 | + if [ -f package-lock.json ]; then |
| 79 | + git add package-lock.json |
| 80 | + fi |
22 | 81 |
|
23 | | - - name: build |
24 | | - run: scripts/build_and_move |
| 82 | + git commit -m "ci: bump ${{ steps.bump_type.outputs.type }} version [skip ci]" |
| 83 | + git push |
25 | 84 |
|
26 | | - - name: publish (npm) |
27 | | - uses: primer/publish@v2.0.0 |
28 | | - env: |
29 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
30 | | - NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} |
31 | | - args: "--dry-run -- --unsafe-perm" |
| 85 | + # ✅ Get new version |
| 86 | + - name: Get final version |
| 87 | + id: final_version |
| 88 | + run: | |
| 89 | + VERSION=$(node -p "require('./package.json').version") |
| 90 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 91 | +
|
| 92 | + # ✅ Create tag |
| 93 | + - name: Create tag |
| 94 | + run: | |
| 95 | + git tag v${{ steps.final_version.outputs.version }} |
| 96 | + git push origin v${{ steps.final_version.outputs.version }} |
| 97 | +
|
| 98 | + # ✅ Create GitHub Release |
| 99 | + - name: Create GitHub Release |
| 100 | + uses: softprops/action-gh-release@v2 |
| 101 | + with: |
| 102 | + tag_name: v${{ steps.final_version.outputs.version }} |
| 103 | + name: Release v${{ steps.final_version.outputs.version }} |
0 commit comments