main
yml 77 lines 2.58 KB
Raw
1 name: Squad Release
2
3 on:
4 push:
5 branches: [main]
6
7 permissions:
8 contents: write
9
10 jobs:
11 release:
12 runs-on: ubuntu-latest
13 steps:
14 - uses: actions/checkout@v4
15 with:
16 fetch-depth: 0
17
18 - uses: actions/setup-node@v4
19 with:
20 node-version: 22
21
22 - name: Run tests
23 run: node --test test/*.test.cjs
24
25 - name: Validate version consistency
26 run: |
27 VERSION=$(node -e "console.log(require('./package.json').version)")
28 if ! grep -q "## \[$VERSION\]" CHANGELOG.md 2>/dev/null; then
29 echo "::error::Version $VERSION not found in CHANGELOG.md — update CHANGELOG.md before release"
30 exit 1
31 fi
32 echo "✅ Version $VERSION validated in CHANGELOG.md"
33
34 - name: Read version from package.json
35 id: version
36 run: |
37 VERSION=$(node -e "console.log(require('./package.json').version)")
38 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
39 echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
40 echo "📦 Version: $VERSION (tag: v$VERSION)"
41
42 - name: Check if tag already exists
43 id: check_tag
44 run: |
45 if git rev-parse "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then
46 echo "exists=true" >> "$GITHUB_OUTPUT"
47 echo "⏭️ Tag ${{ steps.version.outputs.tag }} already exists — skipping release."
48 else
49 echo "exists=false" >> "$GITHUB_OUTPUT"
50 echo "🆕 Tag ${{ steps.version.outputs.tag }} does not exist — creating release."
51 fi
52
53 - name: Create git tag
54 if: steps.check_tag.outputs.exists == 'false'
55 run: |
56 git config user.name "github-actions[bot]"
57 git config user.email "github-actions[bot]@users.noreply.github.com"
58 git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
59 git push origin "${{ steps.version.outputs.tag }}"
60
61 - name: Create GitHub Release
62 if: steps.check_tag.outputs.exists == 'false'
63 env:
64 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 run: |
66 gh release create "${{ steps.version.outputs.tag }}" \
67 --title "${{ steps.version.outputs.tag }}" \
68 --generate-notes \
69 --latest
70
71 - name: Verify release
72 if: steps.check_tag.outputs.exists == 'false'
73 env:
74 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75 run: |
76 gh release view "${{ steps.version.outputs.tag }}"
77 echo "✅ Release ${{ steps.version.outputs.tag }} created and verified."