|
| 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.js |
| 24 | + |
| 25 | + - name: Read version from package.json |
| 26 | + id: version |
| 27 | + run: | |
| 28 | + VERSION=$(node -e "console.log(require('./package.json').version)") |
| 29 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 30 | + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" |
| 31 | + echo "📦 Version: $VERSION (tag: v$VERSION)" |
| 32 | +
|
| 33 | + - name: Check if tag already exists |
| 34 | + id: check_tag |
| 35 | + run: | |
| 36 | + if git rev-parse "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then |
| 37 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 38 | + echo "⏭️ Tag ${{ steps.version.outputs.tag }} already exists — skipping release." |
| 39 | + else |
| 40 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 41 | + echo "🆕 Tag ${{ steps.version.outputs.tag }} does not exist — creating release." |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Create git tag |
| 45 | + if: steps.check_tag.outputs.exists == 'false' |
| 46 | + run: | |
| 47 | + git config user.name "github-actions[bot]" |
| 48 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 49 | + git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}" |
| 50 | + git push origin "${{ steps.version.outputs.tag }}" |
| 51 | +
|
| 52 | + - name: Create GitHub Release |
| 53 | + if: steps.check_tag.outputs.exists == 'false' |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + run: | |
| 57 | + gh release create "${{ steps.version.outputs.tag }}" \ |
| 58 | + --title "${{ steps.version.outputs.tag }}" \ |
| 59 | + --generate-notes \ |
| 60 | + --latest |
| 61 | +
|
| 62 | + - name: Verify release |
| 63 | + if: steps.check_tag.outputs.exists == 'false' |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + run: | |
| 67 | + gh release view "${{ steps.version.outputs.tag }}" |
| 68 | + echo "✅ Release ${{ steps.version.outputs.tag }} created and verified." |
0 commit comments