|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: "Version bump type" |
| 8 | + required: true |
| 9 | + default: "patch" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: release |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +permissions: |
| 21 | + id-token: write |
| 22 | + contents: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + release: |
| 26 | + if: github.repository == 'bmad-code-org/bmad-module-game-dev-studio' && github.ref == 'refs/heads/main' |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Generate GitHub App token |
| 30 | + id: app-token |
| 31 | + uses: actions/create-github-app-token@v2 |
| 32 | + with: |
| 33 | + app-id: ${{ secrets.RELEASE_APP_ID }} |
| 34 | + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} |
| 35 | + |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + token: ${{ steps.app-token.outputs.token }} |
| 41 | + |
| 42 | + - name: Setup Node |
| 43 | + uses: actions/setup-node@v4 |
| 44 | + with: |
| 45 | + node-version-file: ".nvmrc" |
| 46 | + cache: "npm" |
| 47 | + |
| 48 | + - name: Configure git user |
| 49 | + run: | |
| 50 | + git config user.name "github-actions[bot]" |
| 51 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | +
|
| 53 | + - name: Install dependencies |
| 54 | + run: npm ci |
| 55 | + |
| 56 | + - name: Run validation |
| 57 | + run: npm test |
| 58 | + |
| 59 | + - name: Bump version |
| 60 | + run: | |
| 61 | + npm version ${{ inputs.bump }} -m "chore(release): v%s [skip ci]" |
| 62 | +
|
| 63 | + - name: Capture new version |
| 64 | + id: version |
| 65 | + run: | |
| 66 | + VERSION=$(node -p "require('./package.json').version") |
| 67 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 68 | + echo "tag=v${VERSION}" >> $GITHUB_OUTPUT |
| 69 | +
|
| 70 | + - name: Push version commit and tag |
| 71 | + run: git push origin main --follow-tags |
| 72 | + |
| 73 | + - name: Create GitHub Release |
| 74 | + run: | |
| 75 | + TAG="${{ steps.version.outputs.tag }}" |
| 76 | + VERSION="${{ steps.version.outputs.version }}" |
| 77 | + BODY=$(awk -v ver="$VERSION" ' |
| 78 | + /^## v/ { if (found) exit; if (index($0, "## v" ver)) found=1; next } |
| 79 | + found { print } |
| 80 | + ' CHANGELOG.md) |
| 81 | + if [ -z "$BODY" ]; then |
| 82 | + echo "::error::No CHANGELOG.md entry found for $TAG. Add a '## v${VERSION} - DATE' section before releasing." |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + gh release create "$TAG" \ |
| 86 | + --title "Game Dev Studio $TAG" \ |
| 87 | + --notes "$BODY" |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + |
| 91 | + - name: Notify Discord |
| 92 | + if: success() |
| 93 | + continue-on-error: true |
| 94 | + run: | |
| 95 | + set -o pipefail |
| 96 | + source .github/scripts/discord-helpers.sh |
| 97 | + [ -z "$WEBHOOK" ] && exit 0 |
| 98 | + TAG="${{ steps.version.outputs.tag }}" |
| 99 | + RELEASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/${TAG}" |
| 100 | + MSG=$(printf '🎮 **[Game Dev Studio %s released](<%s>)**' "$TAG" "$RELEASE_URL" | esc) |
| 101 | + jq -n --arg content "$MSG" '{content: $content}' | curl -sf --retry 2 -X POST "$WEBHOOK" -H "Content-Type: application/json" -d @- |
| 102 | + env: |
| 103 | + WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} |
| 104 | +
|
| 105 | + - name: Summary |
| 106 | + run: | |
| 107 | + TAG="${{ steps.version.outputs.tag }}" |
| 108 | + { |
| 109 | + echo "## Released ${TAG}" |
| 110 | + echo "" |
| 111 | + echo "- **GitHub Release:** https://github.com/${{ github.repository }}/releases/tag/${TAG}" |
| 112 | + } >> $GITHUB_STEP_SUMMARY |
0 commit comments