|
| 1 | +name: Release on Deps Change |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - package.json |
| 9 | + - pnpm-lock.yaml |
| 10 | + workflow_dispatch: { } |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + check: |
| 17 | + name: Check Deps Change |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + changed: ${{ steps.check.outputs.changed }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v6 |
| 25 | + with: |
| 26 | + fetch-depth: 2 |
| 27 | + |
| 28 | + - name: Setup Node |
| 29 | + uses: actions/setup-node@v6 |
| 30 | + with: |
| 31 | + node-version: 24 |
| 32 | + |
| 33 | + - name: Setup pnpm |
| 34 | + uses: pnpm/action-setup@v4 |
| 35 | + with: |
| 36 | + version: 10 |
| 37 | + |
| 38 | + - name: Detect Deps version change |
| 39 | + id: check |
| 40 | + run: | |
| 41 | + old_version=$(git show HEAD^:package.json | jq -r '.devDependencies.vitepress // .dependencies.vitepress // empty') |
| 42 | + new_version=$(jq -r '.devDependencies.vitepress // .dependencies.vitepress // empty' package.json) |
| 43 | + |
| 44 | + echo "Old Deps: $old_version" |
| 45 | + echo "New Deps: $new_version" |
| 46 | + |
| 47 | + if [ "$old_version" != "$new_version" ]; then |
| 48 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | + |
| 53 | + release: |
| 54 | + name: Release NPM Package |
| 55 | + needs: check |
| 56 | + if: needs.check.outputs.changed == 'true' |
| 57 | + runs-on: ubuntu-latest |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Checkout |
| 61 | + uses: actions/checkout@v6 |
| 62 | + with: |
| 63 | + fetch-depth: 0 |
| 64 | + fetch-tags: true |
| 65 | + |
| 66 | + - name: Setup Node |
| 67 | + uses: actions/setup-node@v6 |
| 68 | + with: |
| 69 | + node-version: 24 |
| 70 | + registry-url: 'https://registry.npmjs.org/' |
| 71 | + |
| 72 | + - name: Setup pnpm |
| 73 | + uses: pnpm/action-setup@v4 |
| 74 | + with: |
| 75 | + version: 10 |
| 76 | + |
| 77 | + - name: Set Git Identity |
| 78 | + run: | |
| 79 | + git config --global user.name "github-actions[bot]" |
| 80 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 81 | + |
| 82 | + - name: Install dependencies |
| 83 | + run: pnpm install |
| 84 | + |
| 85 | + - name: Sync vite version |
| 86 | + run: pnpm sync:vite |
| 87 | + |
| 88 | + - name: Commit updated package.json |
| 89 | + run: | |
| 90 | + git add package.json pnpm-lock.yaml |
| 91 | + git commit -m "chore: sync vite version with vitepress" || echo "No changes" |
| 92 | + git push |
| 93 | + |
| 94 | + - name: Build project |
| 95 | + run: pnpm build |
| 96 | + |
| 97 | + - name: Release with release-it |
| 98 | + run: pnpm exec release-it --ci |
| 99 | + env: |
| 100 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments