|
| 1 | +name: Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'package.json' |
| 9 | + |
| 10 | +jobs: |
| 11 | + check-version: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + version-changed: ${{ steps.check.outputs.changed }} |
| 15 | + new-version: ${{ steps.check.outputs.version }} |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 2 |
| 20 | + |
| 21 | + - name: Check if version changed |
| 22 | + id: check |
| 23 | + run: | |
| 24 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 25 | + git checkout HEAD~1 -- package.json 2>/dev/null || echo "First commit" |
| 26 | + PREVIOUS_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0") |
| 27 | + git checkout HEAD -- package.json |
| 28 | +
|
| 29 | + echo "Current version: $CURRENT_VERSION" |
| 30 | + echo "Previous version: $PREVIOUS_VERSION" |
| 31 | +
|
| 32 | + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then |
| 33 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 34 | + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 35 | + else |
| 36 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 37 | + fi |
| 38 | +
|
| 39 | + ci: |
| 40 | + needs: check-version |
| 41 | + if: needs.check-version.outputs.version-changed == 'true' |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: 20 |
| 49 | + cache: npm |
| 50 | + |
| 51 | + - run: npm ci |
| 52 | + |
| 53 | + - name: Lint |
| 54 | + run: npm run lint |
| 55 | + |
| 56 | + - name: Format check |
| 57 | + run: npm run format:check |
| 58 | + |
| 59 | + - name: Build |
| 60 | + run: npm run build |
| 61 | + |
| 62 | + - name: Test |
| 63 | + run: npx vitest --run |
| 64 | + |
| 65 | + create-release: |
| 66 | + needs: [check-version, ci] |
| 67 | + if: needs.check-version.outputs.version-changed == 'true' |
| 68 | + runs-on: ubuntu-latest |
| 69 | + permissions: |
| 70 | + contents: write |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Create Release |
| 75 | + uses: softprops/action-gh-release@v2 |
| 76 | + with: |
| 77 | + tag_name: v${{ needs.check-version.outputs.new-version }} |
| 78 | + name: Release v${{ needs.check-version.outputs.new-version }} |
| 79 | + body: | |
| 80 | + ## Changes in v${{ needs.check-version.outputs.new-version }} |
| 81 | +
|
| 82 | + See [commits](https://github.com/${{ github.repository }}/commits/v${{ needs.check-version.outputs.new-version }}) for details. |
| 83 | +
|
| 84 | + ## Installation |
| 85 | +
|
| 86 | + ```bash |
| 87 | + npm install -g eff-u-code@${{ needs.check-version.outputs.new-version }} |
| 88 | + ``` |
| 89 | + draft: false |
| 90 | + prerelease: false |
| 91 | + generate_release_notes: true |
| 92 | + make_latest: true |
0 commit comments