|
| 1 | +# This workflow automates the release process for a VS Code extension. |
| 2 | +# It runs on pushes to the 'develop' and 'main' branches. |
| 3 | +# The version number must be manually updated in the package.json file before pushing. |
| 4 | + |
| 5 | +name: Release VS Code Extension |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - develop |
| 11 | + - main |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + # Set the runner environment. |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + # Define environment variables for the release process |
| 19 | + # Note: The HaaLeo action uses different secret names. |
| 20 | + # The 'publish_token' is for VS Code Marketplace, and 'ovsx_token' is for Open VSX. |
| 21 | + env: |
| 22 | + publish_token: ${{ secrets.VSCE_TOKEN }} |
| 23 | + ovsx_token: ${{ secrets.OPEN_VSIX_TOKEN }} |
| 24 | + |
| 25 | + steps: |
| 26 | + # Step 1: Checkout the repository code. |
| 27 | + - name: Checkout Repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + # Step 2: Set up Node.js environment. |
| 31 | + - name: Setup Node.js |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: "20.x" # Use a stable Node.js version. |
| 35 | + cache: "npm" |
| 36 | + |
| 37 | + # Step 3: Install project dependencies. |
| 38 | + - name: Install Dependencies |
| 39 | + run: npm ci |
| 40 | + |
| 41 | + # Step 4: Handle prerelease logic for pushes to 'develop'. |
| 42 | + - name: Publish Prerelease |
| 43 | + if: github.ref == 'refs/heads/develop' |
| 44 | + uses: HaaLeo/publish-vscode-extension@v2 |
| 45 | + with: |
| 46 | + pat: ${{ env.publish_token }} |
| 47 | + ovsxPat: ${{ env.ovsx_token }} |
| 48 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + preRelease: true |
| 50 | + updateRelease: true |
| 51 | + |
| 52 | + # Step 5: Handle official release logic for pushes to 'main'. |
| 53 | + - name: Publish Official Release |
| 54 | + if: github.ref == 'refs/heads/main' |
| 55 | + uses: HaaLeo/publish-vscode-extension@v2 |
| 56 | + with: |
| 57 | + pat: ${{ env.publish_token }} |
| 58 | + ovsxPat: ${{ env.ovsx_token }} |
| 59 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + preRelease: false |
| 61 | + updateRelease: true |
0 commit comments