|
1 | 1 | name: Release on npm |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - "main" |
7 | | - paths: |
8 | | - - package.json |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release-type: |
| 7 | + description: "Release type (major, minor, patch)" |
| 8 | + required: true |
| 9 | + default: "patch" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - major |
| 13 | + - minor |
| 14 | + - patch |
9 | 15 |
|
10 | 16 | permissions: |
11 | 17 | contents: write |
12 | | - pull-requests: read |
13 | 18 | id-token: write |
14 | 19 |
|
15 | 20 | jobs: |
16 | | - build_and_publish: |
| 21 | + release: |
17 | 22 | runs-on: ubuntu-latest |
18 | 23 |
|
19 | 24 | steps: |
20 | 25 | - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
21 | 28 |
|
22 | | - - name: Set up Node |
| 29 | + - name: Set up Node.js |
23 | 30 | uses: actions/setup-node@v4 |
24 | 31 | with: |
25 | 32 | node-version-file: ".nvmrc" |
| 33 | + registry-url: "https://registry.npmjs.org" |
26 | 34 |
|
27 | 35 | - name: Install dependencies |
28 | | - run: npm install |
29 | | - |
30 | | - - name: Build |
31 | | - run: | |
32 | | - npm run build |
33 | | -
|
34 | | - - id: publish |
35 | | - name: Publish to NPM |
36 | | - uses: JS-DevTools/npm-publish@v3 |
37 | | - with: |
38 | | - token: ${{ secrets.NPM_TOKEN }} |
39 | | - dry-run: false |
40 | | - provenance: true |
41 | | - access: public |
42 | | - |
43 | | - - name: Post-publish |
44 | | - if: steps.publish.outputs.type != 'none' |
45 | | - run: | |
46 | | - echo "Published ${{ steps.publish.outputs.type }} version: ${{ steps.publish.outputs.version }}" |
| 36 | + run: npm ci |
47 | 37 |
|
48 | | - - name: Publish skipped |
49 | | - if: steps.publish.outputs.type == 'none' |
| 38 | + - name: Configure Git |
50 | 39 | run: | |
51 | | - echo "Version in package.json has not changed. Skipping." |
52 | | - exit 0 |
| 40 | + git config user.name "github-actions[bot]" |
| 41 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
53 | 42 |
|
54 | | - - name: Configure changelog |
55 | | - if: steps.publish.outputs.type != 'none' |
56 | | - run: | |
57 | | - echo '{"categories": [], "template": "## Commits:\n\n${{ '${{UNCATEGORIZED}}' }}", "pr_template": ${{ '"- ${{MERGE_SHA}} ${{TITLE}}"' }} }' > changelog_config.json |
58 | | - echo "last_tag=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV |
59 | | - echo "curr_commit=$(git rev-parse HEAD)" >> $GITHUB_ENV |
60 | | -
|
61 | | - - name: Generate changelog |
62 | | - if: steps.publish.outputs.type != 'none' |
63 | | - id: github_release |
64 | | - |
| 43 | + - name: Release |
| 44 | + run: npm run release -- ${{ github.event.inputs.release-type }} --ci |
65 | 45 | env: |
66 | 46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
67 | | - with: |
68 | | - fromTag: "${{ env.last_tag }}" |
69 | | - toTag: ${{ github.ref }} |
70 | | - commitMode: true |
71 | | - configuration: changelog_config.json |
72 | | - |
73 | | - - name: Create release |
74 | | - if: steps.publish.outputs.type != 'none' |
75 | | - id: create_release |
76 | | - uses: actions/create-release@v1 |
77 | | - env: |
78 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
79 | | - with: |
80 | | - tag_name: v${{ steps.publish.outputs.version }} |
81 | | - release_name: v${{ steps.publish.outputs.version }} |
82 | | - commitish: ${{ github.ref }} |
83 | | - body: ${{ steps.github_release.outputs.changelog }} |
84 | | - draft: false |
85 | | - prerelease: false |
| 47 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 48 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments