|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - 'package.json' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.ref == 'refs/heads/master' |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 21 | + with: |
| 22 | + fetch-depth: 2 |
| 23 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + |
| 25 | + - name: Detect version change |
| 26 | + id: version |
| 27 | + run: | |
| 28 | + current=$(jq -r '.version' package.json) |
| 29 | + previous=$(git show HEAD~1:package.json | jq -r '.version // "0.0.0"') |
| 30 | + echo "current=$current" >> "$GITHUB_OUTPUT" |
| 31 | + echo "previous=$previous" >> "$GITHUB_OUTPUT" |
| 32 | + if [ "$current" != "$previous" ]; then |
| 33 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 34 | + echo "Version changed: $previous → $current" |
| 35 | + else |
| 36 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 37 | + echo "Version unchanged ($current), skipping release" |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Check if tag already exists |
| 41 | + id: tag_check |
| 42 | + if: steps.version.outputs.changed == 'true' |
| 43 | + run: | |
| 44 | + tag="v${{ steps.version.outputs.current }}" |
| 45 | + if gh api "repos/${{ github.repository }}/git/refs/tags/$tag" >/dev/null 2>&1; then |
| 46 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 47 | + echo "Tag $tag already exists, skipping release" |
| 48 | + else |
| 49 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Create GitHub Release |
| 55 | + if: steps.version.outputs.changed == 'true' && steps.tag_check.outputs.exists == 'false' |
| 56 | + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 |
| 57 | + with: |
| 58 | + tag_name: "v${{ steps.version.outputs.current }}" |
| 59 | + name: "v${{ steps.version.outputs.current }}" |
| 60 | + generate_release_notes: true |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments