|
| 1 | +name: Pre Release VSCode extension |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + # Every weekday at 9:00 UTC |
| 7 | + - cron: '0 2 * * 1-5' |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - 'packages/vscode-extension/**' |
| 13 | + |
| 14 | +env: |
| 15 | + NODE_OPTIONS: '--max_old_space_size=4096' |
| 16 | + |
| 17 | +jobs: |
| 18 | + pre-release-vscode-extension: |
| 19 | + name: 'Pre Release VSCode extension' |
| 20 | + environment: publish-vscode-extension |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Restore latest pre-released sha |
| 26 | + uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4 |
| 27 | + id: cache-pre-release-sha |
| 28 | + with: |
| 29 | + path: last-published-sha |
| 30 | + key: vs-code-extension-pre-release-sha- |
| 31 | + |
| 32 | + - name: Check for changes |
| 33 | + id: check_changes |
| 34 | + run: | |
| 35 | + CURRENT_SHA=$GITHUB_SHA |
| 36 | + echo "Current SHA: $CURRENT_SHA" |
| 37 | + echo "Last published SHA: $(cat last-published-sha 2>/dev/null || echo 'none')" |
| 38 | + if [[ ! -f last-published-sha || "$(cat last-published-sha 2>/dev/null)" != "$CURRENT_SHA" ]]; then |
| 39 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Setup and build project |
| 45 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 46 | + uses: ./.github/actions/setup-and-build |
| 47 | + |
| 48 | + - name: Set Up Git User |
| 49 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 50 | + run: | |
| 51 | + git config --global user.name "Pre-release Bot" |
| 52 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 53 | +
|
| 54 | + - name: Bump version (odd minor rule) |
| 55 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 56 | + run: | |
| 57 | + cd packages/vscode-extension |
| 58 | + # obtain current version as "x.y.z" |
| 59 | + CURRENT=$(node -p "require('./package.json').version") |
| 60 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" |
| 61 | +
|
| 62 | + if [ $((MINOR % 2)) -eq 0 ]; then |
| 63 | + # even minor => switch to pre-release track with next odd minor |
| 64 | + NEW_VERSION="$MAJOR.$((MINOR + 1)).0" |
| 65 | + else |
| 66 | + # already on pre-release track (odd minor) => bump patch |
| 67 | + NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" |
| 68 | + fi |
| 69 | +
|
| 70 | + echo "Bumping version from $CURRENT to $NEW_VERSION" |
| 71 | + pnpm version "$NEW_VERSION" --no-git-tag-version |
| 72 | + git add . |
| 73 | + git commit -m "bump pre-release version to $NEW_VERSION" |
| 74 | + git push |
| 75 | +
|
| 76 | + - name: Set the last published cached SHA |
| 77 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 78 | + run: | |
| 79 | + LATEST_SHA=$(git rev-parse HEAD) |
| 80 | + echo "$LATEST_SHA" > last-published-sha |
| 81 | + echo "Last published SHA set to: $LATEST_SHA" |
| 82 | +
|
| 83 | + - name: Cache the last published SHA |
| 84 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 85 | + uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4 |
| 86 | + with: |
| 87 | + path: last-published-sha |
| 88 | + key: vs-code-extension-pre-release-sha-${{ github.run_number }} |
| 89 | + |
| 90 | + - name: Publish pre-release |
| 91 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 92 | + env: |
| 93 | + VSX_PAT: ${{ secrets.VSX_PAT }} |
| 94 | + run: | |
| 95 | + cd packages/vscode-extension |
| 96 | + pnpm package --pre-release |
| 97 | + pnpm vsce publish --pre-release --no-dependencies --pat $VSX_PAT |
0 commit comments