Update CHANGELOG.md #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build & Publish Extension | |
| on: | |
| push: | |
| branches: ["main", "master"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| name: Build and package | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Use Node.js 22 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: "yarn" | |
| registry-url: https://registry.npmjs.org/ | |
| - name: Install dependencies | |
| run: | | |
| npm install -g @vscode/vsce | |
| yarn install --frozen-lockfile | |
| - name: Get NPM Version | |
| id: package-version | |
| uses: martinbeentjes/[email protected] | |
| - name: Run Tests | |
| run: xvfb-run -a yarn test | |
| - name: Check if version exists | |
| id: check-version | |
| env: | |
| VERSION: ${{ steps.package-version.outputs.current-version }} | |
| run: | | |
| echo "Checking version $VERSION..." | |
| # Check VS Marketplace | |
| VS_Response=$(curl -s --location 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \ | |
| --header 'Accept: application/json; api-version=7.2-preview.1' \ | |
| --header 'Content-Type: application/json' \ | |
| --data '{ | |
| "filters": [ | |
| { | |
| "criteria": [ | |
| { | |
| "filterType": 7, | |
| "value": "ahnafnafee.postscript-preview" | |
| } | |
| ] | |
| } | |
| ], | |
| "flags": 915 | |
| }') | |
| # Check if version exists (robust jq boolean) | |
| if echo "$VS_Response" | jq -e --arg v "$VERSION" '.results[0].extensions[0].versions | map(select(.version == $v)) | length > 0' > /dev/null; then | |
| echo "Version $VERSION already exists in VS Marketplace." | |
| echo "VS_EXISTS=true" >> $GITHUB_ENV | |
| else | |
| echo "Version $VERSION not found in VS Marketplace." | |
| echo "VS_EXISTS=false" >> $GITHUB_ENV | |
| fi | |
| # Check Open VSX | |
| OVSX_Status=$(curl -o /dev/null -s -w "%{http_code}" https://open-vsx.org/api/ahnafnafee/postscript-preview/$VERSION) | |
| if [ "$OVSX_Status" = "200" ]; then | |
| echo "Version $VERSION already exists in Open VSX." | |
| echo "OVSX_EXISTS=true" >> $GITHUB_ENV | |
| else | |
| echo "Version $VERSION not found in Open VSX." | |
| echo "OVSX_EXISTS=false" >> $GITHUB_ENV | |
| fi | |
| - name: Validate Version Status | |
| run: | | |
| if [ "$VS_EXISTS" = "true" ] && [ "$OVSX_EXISTS" = "true" ]; then | |
| echo "::warning::Version $VERSION is already published to both VS Marketplace and Open VSX. Skipping publish." | |
| echo "Please bump the version in package.json to release a new version." | |
| fi | |
| - name: Build extension | |
| if: env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false' | |
| run: vsce package -o postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix | |
| - name: Upload a Build Artifact | |
| if: env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix | |
| path: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix | |
| if-no-files-found: error | |
| - name: Create release with artifact | |
| if: (env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false') && success() | |
| uses: softprops/[email protected] | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.github_token }} | |
| with: | |
| name: Release v${{ steps.package-version.outputs.current-version }} | |
| tag_name: v${{ steps.package-version.outputs.current-version }} | |
| draft: false | |
| files: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix | |
| - name: Publish to Open VSX Registry | |
| if: env.OVSX_EXISTS == 'false' | |
| uses: HaaLeo/publish-vscode-extension@v1 | |
| with: | |
| pat: ${{ secrets.OPEN_VSX_TOKEN }} | |
| extensionFile: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix | |
| - name: Publish to Visual Studio Marketplace | |
| if: env.VS_EXISTS == 'false' | |
| uses: HaaLeo/publish-vscode-extension@v1 | |
| with: | |
| pat: ${{ secrets.VS_MARKETPLACE_TOKEN }} | |
| registryUrl: https://marketplace.visualstudio.com | |
| extensionFile: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix |