|
| 1 | +name: Release Extension |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [release] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + name: Build and Publish Extension |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Setup Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: "20" |
| 26 | + |
| 27 | + - name: Install just |
| 28 | + uses: extractions/setup-just@v2 |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: just deps |
| 32 | + |
| 33 | + - name: Get version |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + VERSION=$(node -p "require('./package.json').version") |
| 37 | + echo "version=v$VERSION" >> $GITHUB_OUTPUT |
| 38 | + echo "version_number=$VERSION" >> $GITHUB_OUTPUT |
| 39 | + echo "📦 Version: v$VERSION" |
| 40 | +
|
| 41 | + - name: Check if release exists |
| 42 | + id: check |
| 43 | + run: | |
| 44 | + if gh release view "v$(node -p "require('./package.json').version")" &>/dev/null; then |
| 45 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 46 | + echo "⚠️ Release already exists, skipping" |
| 47 | + else |
| 48 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | + env: |
| 51 | + GH_TOKEN: ${{ github.token }} |
| 52 | + |
| 53 | + - name: Build extension |
| 54 | + if: steps.check.outputs.exists == 'false' |
| 55 | + run: just package |
| 56 | + |
| 57 | + - name: Generate changelog |
| 58 | + id: changelog |
| 59 | + if: steps.check.outputs.exists == 'false' |
| 60 | + run: | |
| 61 | + CURRENT="v$(node -p "require('./package.json').version")" |
| 62 | + PREVIOUS=$(git tag --sort=-v:refname | grep -v "$CURRENT" | head -1 || echo "") |
| 63 | +
|
| 64 | + if [ -z "$PREVIOUS" ]; then |
| 65 | + echo "changelog=Initial release of quick command buttons extension" >> $GITHUB_OUTPUT |
| 66 | + else |
| 67 | + CHANGELOG=$(git log $PREVIOUS..HEAD --pretty=format:"- %s" --no-merges) |
| 68 | + echo "changelog<<EOF" >> $GITHUB_OUTPUT |
| 69 | + echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 70 | + echo "EOF" >> $GITHUB_OUTPUT |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Create GitHub Release |
| 74 | + if: steps.check.outputs.exists == 'false' |
| 75 | + uses: softprops/action-gh-release@v1 |
| 76 | + with: |
| 77 | + tag_name: ${{ steps.version.outputs.version }} |
| 78 | + name: ${{ steps.version.outputs.version }} |
| 79 | + body: | |
| 80 | + ## 🎉 What's New in ${{ steps.version.outputs.version }} |
| 81 | +
|
| 82 | + ${{ steps.changelog.outputs.changelog }} |
| 83 | + files: | |
| 84 | + quick-command-buttons-${{ steps.version.outputs.version_number }}.vsix |
| 85 | + generate_release_notes: true |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + |
| 89 | + - name: Publish to marketplaces |
| 90 | + if: steps.check.outputs.exists == 'false' |
| 91 | + run: just publish both |
| 92 | + env: |
| 93 | + VSCE_ACCESS_TOKEN: ${{ secrets.VSCE_PAT }} |
| 94 | + OVSX_ACCESS_TOKEN: ${{ secrets.OVSX_PAT }} |
| 95 | + |
| 96 | + - name: Update release with success status |
| 97 | + if: success() && steps.check.outputs.exists == 'false' |
| 98 | + run: | |
| 99 | + TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 100 | + gh release view "${{ steps.version.outputs.version }}" --json body -q .body > body.txt |
| 101 | + echo "" >> body.txt |
| 102 | + echo "---" >> body.txt |
| 103 | + echo "" >> body.txt |
| 104 | + echo "✅ **Successfully published to both marketplaces!**" >> body.txt |
| 105 | + echo "" >> body.txt |
| 106 | + echo "- VSCode Marketplace: https://marketplace.visualstudio.com/items?itemName=KubrickCode.quick-command-buttons" >> body.txt |
| 107 | + echo "- Open VSX Registry: https://open-vsx.org/extension/KubrickCode/quick-command-buttons" >> body.txt |
| 108 | + echo "" >> body.txt |
| 109 | + echo "🕐 Published at: $TIMESTAMP" >> body.txt |
| 110 | + gh release edit "${{ steps.version.outputs.version }}" --notes-file body.txt |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + |
| 114 | + - name: Update release on failure |
| 115 | + if: failure() && steps.check.outputs.exists == 'false' |
| 116 | + run: | |
| 117 | + gh release view "${{ steps.version.outputs.version }}" --json body -q .body > body.txt |
| 118 | + echo "" >> body.txt |
| 119 | + echo "---" >> body.txt |
| 120 | + echo "" >> body.txt |
| 121 | + echo "❌ **Marketplace publishing failed!**" >> body.txt |
| 122 | + echo "" >> body.txt |
| 123 | + echo "Please check the GitHub Actions logs for details." >> body.txt |
| 124 | + gh release edit "${{ steps.version.outputs.version }}" --notes-file body.txt |
| 125 | + env: |
| 126 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments