From 60bf48c1030d8004901dab900614cdc3c2872115 Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Mon, 9 Dec 2024 18:35:43 +0800 Subject: [PATCH] test: ci --- .github/workflows/publish-vscode.yml | 58 +++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-vscode.yml b/.github/workflows/publish-vscode.yml index 8470ec6..9c44801 100644 --- a/.github/workflows/publish-vscode.yml +++ b/.github/workflows/publish-vscode.yml @@ -4,7 +4,9 @@ name: Publish Cardano Devkit VSCode Extension on: - push: + pull_request: + types: + - closed branches: - main release: @@ -32,6 +34,60 @@ jobs: if: runner.os == 'Linux' - run: yarn test if: runner.os != 'Linux' + + check-version: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + outputs: + version-updated: ${{ steps.compare-versions.outputs.version-updated }} + steps: + - name: Checkout main branch at commit before merge + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.base.sha }} + + - name: Get package version from main branch before merge + id: pre-merge-version + run: | + PRE_MERGE_VERSION=$(node -p "require('./vscode-extension/package.json').version") + + - name: Checkout main branch at commit after merge + uses: actions/checkout@v4 + with: + ref: "main" + + - name: Get package version from main branch after merge + id: post-merge-version + run: | + POST_MERGE_VERSION=$(node -p "require('./vscode-extension/package.json').version") + + - name: Compare versions + id: compare-versions + run: | + if [[ "${{ steps.pre-merge-version.outputs.pre_merge_version }}" != "${{ steps.post-merge-version.outputs.post_merge_version }}" ]]; then + echo "version-updated=true" >> "$GITHUB_OUTPUT" + else + echo "version-updated=false" >> "$GITHUB_OUTPUT" + fi + + publish: + needs: [build, check-version] + if: needs.check-version.outputs.version-updated == 'true' || github.event_name == 'release' + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + defaults: + run: + working-directory: vscode-extension + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 18.x + - run: yarn install - name: Publish if: success() && startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest' run: yarn deploy