|
1 | 1 | name: Create new Release |
2 | | - |
3 | 2 | on: |
4 | 3 | push: |
5 | 4 | branches: [main] |
6 | | - pull_request: |
7 | | - branches: [main] |
| 5 | + workflow_dispatch: |
8 | 6 |
|
9 | 7 | jobs: |
10 | 8 | release: |
11 | 9 | runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: write |
| 12 | + id-token: write |
| 13 | + outputs: |
| 14 | + exists: ${{ steps.tag-check.outputs.exists }} |
| 15 | + version: ${{ steps.pkg.outputs.version }} |
12 | 16 |
|
13 | 17 | steps: |
14 | | - - name: Checkout repository |
15 | | - uses: actions/checkout@v4 |
| 18 | + - uses: actions/checkout@v4 |
16 | 19 | with: |
17 | 20 | fetch-depth: 0 |
18 | 21 |
|
19 | | - - name: Setup Node.js |
20 | | - uses: actions/setup-node@v4 |
| 22 | + - uses: actions/setup-node@v4 |
21 | 23 | with: |
22 | 24 | node-version: "18" |
23 | 25 | cache: "npm" |
| 26 | + registry-url: "https://registry.npmjs.org" |
24 | 27 |
|
25 | | - - name: Install dependencies |
26 | | - run: npm ci |
27 | | - |
28 | | - - name: Run type check |
29 | | - run: npm run check |
| 28 | + - run: npm ci |
| 29 | + - run: npm run check |
| 30 | + - run: npm run build |
30 | 31 |
|
31 | | - - name: Build package |
32 | | - run: npm run build |
| 32 | + - name: Get version from package.json |
| 33 | + id: pkg |
| 34 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
33 | 35 |
|
34 | | - - name: Check for version bump |
35 | | - id: version-check |
| 36 | + - name: Check if tag exists |
| 37 | + id: tag-check |
36 | 38 | run: | |
37 | | - CURRENT_VERSION=$(node -p "require('./package.json').version") |
38 | | -
|
39 | | - # Try to get npm version, if package doesn't exist, treat as 0.0.0 |
40 | | - if NPM_VERSION=$(npm view judgeval version 2>/dev/null); then |
41 | | - echo "npm_version=$NPM_VERSION" >> $GITHUB_OUTPUT |
42 | | - echo "Found published version: $NPM_VERSION" |
| 39 | + if git rev-parse "v${{ steps.pkg.outputs.version }}" >/dev/null 2>&1; then |
| 40 | + echo "exists=true" >> $GITHUB_OUTPUT |
43 | 41 | else |
44 | | - NPM_VERSION="0.0.0" |
45 | | - echo "npm_version=$NPM_VERSION" >> $GITHUB_OUTPUT |
46 | | - echo "Package not found on npm, treating as 0.0.0" |
| 42 | + echo "exists=false" >> $GITHUB_OUTPUT |
47 | 43 | fi |
48 | 44 |
|
49 | | - echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 45 | + - name: Create and push tag |
| 46 | + if: steps.tag-check.outputs.exists == 'false' |
| 47 | + run: | |
| 48 | + git config user.name "github-actions" |
| 49 | + git config user.email "github-actions@github.com" |
| 50 | + git tag v${{ steps.pkg.outputs.version }} |
| 51 | + git push origin v${{ steps.pkg.outputs.version }} |
50 | 52 |
|
51 | | - if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then |
52 | | - echo "version_changed=true" >> $GITHUB_OUTPUT |
53 | | - echo "Version bumped from $NPM_VERSION to $CURRENT_VERSION" |
54 | | - else |
55 | | - echo "version_changed=false" >> $GITHUB_OUTPUT |
56 | | - echo "Version $CURRENT_VERSION already published to npm" |
57 | | - exit 1 |
58 | | - fi |
| 53 | + publish: |
| 54 | + needs: release |
| 55 | + runs-on: ubuntu-latest |
| 56 | + permissions: |
| 57 | + contents: write |
| 58 | + id-token: write |
59 | 59 |
|
60 | | - - name: Create Release |
61 | | - if: steps.version-check.outputs.version_changed == 'true' |
62 | | - id: create_release |
63 | | - uses: actions/create-release@v1 |
64 | | - env: |
65 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
66 | | - with: |
67 | | - tag_name: v${{ steps.version-check.outputs.current_version }} |
68 | | - release_name: Release v${{ steps.version-check.outputs.current_version }} |
69 | | - body: | |
70 | | - ## Release v${{ steps.version-check.outputs.current_version }} |
| 60 | + if: needs.release.outputs.exists == 'false' |
71 | 61 |
|
72 | | - **Diff since previous release:** |
73 | | - [View changes](https://github.com/${{ github.repository }}/compare/v${{ steps.version-check.outputs.npm_version }}...v${{ steps.version-check.outputs.current_version }}) |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + fetch-depth: 0 |
74 | 66 |
|
75 | | - **Version changes:** |
76 | | - - Previous: ${{ steps.version-check.outputs.npm_version }} |
77 | | - - Current: ${{ steps.version-check.outputs.current_version }} |
78 | | - draft: false |
79 | | - prerelease: false |
| 67 | + - uses: actions/setup-node@v4 |
| 68 | + with: |
| 69 | + node-version: "18" |
| 70 | + registry-url: "https://registry.npmjs.org" |
| 71 | + cache: "npm" |
80 | 72 |
|
81 | | - - name: Create release package |
82 | | - if: steps.version-check.outputs.version_changed == 'true' |
83 | | - run: zip -r judgeval-v${{ steps.version-check.outputs.current_version }}.zip dist/ |
| 73 | + - run: npm ci |
| 74 | + - run: npm run check |
| 75 | + - run: npm run build |
84 | 76 |
|
85 | | - - name: Upload Release Assets |
86 | | - if: steps.version-check.outputs.version_changed == 'true' |
87 | | - uses: actions/upload-release-asset@v1 |
| 77 | + - name: Publish to npm |
| 78 | + run: npm publish |
88 | 79 | env: |
89 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 81 | + |
| 82 | + - name: Create GitHub Release |
| 83 | + uses: softprops/action-gh-release@v1 |
90 | 84 | with: |
91 | | - upload_url: ${{ steps.create_release.outputs.upload_url }} |
92 | | - asset_path: ./judgeval-v${{ steps.version-check.outputs.current_version }}.zip |
93 | | - asset_name: judgeval-v${{ steps.version-check.outputs.current_version }}.zip |
94 | | - asset_content_type: application/zip |
| 85 | + tag_name: v${{ needs.release.outputs.version }} |
| 86 | + name: Release v${{ needs.release.outputs.version }} |
| 87 | + generate_release_notes: true |
0 commit comments