|
| 1 | +name: Release and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - "Test" |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Node.js |
| 20 | + uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + node-version: 18 |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: npm install |
| 26 | + |
| 27 | + - name: Get version and name from package.json |
| 28 | + id: meta |
| 29 | + run: | |
| 30 | + VERSION=$(node -p "require('./package.json').version") |
| 31 | + NAME=$(node -p "require('./package.json').name") |
| 32 | + VSIX_FILE="$NAME-$VERSION.vsix" |
| 33 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "name=$NAME" >> $GITHUB_OUTPUT |
| 35 | + echo "vsix_file=$VSIX_FILE" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Check if tag already exists |
| 38 | + id: tag_check |
| 39 | + run: | |
| 40 | + TAG=v${{ steps.meta.outputs.version }} |
| 41 | + if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then |
| 42 | + echo "Tag $TAG already exists. Skipping tag creation." |
| 43 | + echo "skip_tag=true" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "skip_tag=false" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Create Git tag |
| 49 | + if: steps.tag_check.outputs.skip_tag == 'false' |
| 50 | + run: | |
| 51 | + git config user.name "github-actions" |
| 52 | + git config user.email "[email protected]" |
| 53 | + git tag v${{ steps.meta.outputs.version }} |
| 54 | + git push origin v${{ steps.meta.outputs.version }} |
| 55 | +
|
| 56 | + - name: Package VS Code Extension |
| 57 | + run: npx vsce package -o ${{ steps.meta.outputs.vsix_file }} |
| 58 | + |
| 59 | + - name: Upload VSIX to GitHub Release |
| 60 | + uses: softprops/action-gh-release@v2 |
| 61 | + with: |
| 62 | + tag_name: v${{ steps.meta.outputs.version }} |
| 63 | + files: ${{ steps.meta.outputs.vsix_file }} |
| 64 | + |
| 65 | + - name: Publish to VS Code Marketplace |
| 66 | + run: npx vsce publish ${{ steps.meta.outputs.vsix_file }} --pat ${{ secrets.VSCE_TOKEN }} |
| 67 | + |
| 68 | + - name: Post release summary |
| 69 | + run: | |
| 70 | + echo "✅ Extension v${{ steps.meta.outputs.version }} released and published to the VS Code Marketplace." |
| 71 | + echo "🔗 GitHub Release: https://github.com/${{ github.repository }}/releases/tag/v${{ steps.meta.outputs.version }}" |
0 commit comments