|
1 | | -name: publish |
2 | | - |
| 1 | +name: Node.js Package |
3 | 2 | on: |
4 | | - pull_request: |
5 | | - branches: |
6 | | - - master |
7 | | - types: [closed] |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - v[0-9]+.[0-9]+.[0-9]+ |
8 | 6 |
|
9 | | -env: |
10 | | - CI: true |
11 | | - ACTIONS_ALLOW_UNSECURE_COMMANDS: true |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + packages: write |
12 | 10 |
|
13 | 11 | jobs: |
14 | 12 | publish: |
15 | 13 | runs-on: ubuntu-latest |
16 | | - env: |
17 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
18 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
19 | 14 | steps: |
20 | | - - name: Pull Request Merged |
21 | | - if: github.event.pull_request.merged == false |
22 | | - run: | |
23 | | - echo 'The pull request has not been merged' |
24 | | - exit 1 |
25 | | -
|
26 | | - - uses: actions/checkout@v4 |
| 15 | + - uses: actions/checkout@v5 |
27 | 16 | with: |
28 | 17 | fetch-depth: 0 |
29 | 18 |
|
30 | | - - name: Set git config |
31 | | - run: | |
32 | | - git config user.name github-actions |
33 | | - git config user.email github-actions@github.com |
34 | | -
|
35 | | - - name: Use Node.js |
36 | | - uses: actions/setup-node@v4 |
| 19 | + - uses: actions/setup-node@v6 |
37 | 20 | with: |
38 | | - node-version: 20.x |
| 21 | + node-version: "22.x" |
| 22 | + cache: "yarn" |
39 | 23 | registry-url: "https://registry.npmjs.org" |
40 | 24 |
|
41 | | - - name: Setup .npmrc |
42 | | - shell: bash |
43 | | - run: | |
44 | | - npm set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN |
45 | | - env: |
46 | | - NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} |
47 | | - |
48 | | - - name: Ensure access |
49 | | - shell: bash |
50 | | - run: npm whoami --registry https://registry.npmjs.org/ |
51 | | - env: |
52 | | - NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} |
53 | | - |
54 | | - - name: Install global dependencies |
55 | | - run: npm i standard-version yarn -g |
56 | | - |
57 | 25 | - name: Install dependencies |
58 | | - run: yarn |
59 | | - |
60 | | - - name: Get Prev Version |
61 | | - shell: bash -ex {0} |
62 | | - run: | |
63 | | - PREV_VERSION=$(node -p 'require("./package.json").version') |
64 | | - echo "::set-env name=PREV_VERSION::${PREV_VERSION}" |
| 26 | + run: npm ci |
65 | 27 |
|
66 | | - - name: Bump version |
67 | | - run: | |
68 | | - standard-version |
| 28 | + - name: Build |
| 29 | + run: npm run build |
69 | 30 |
|
70 | | - - name: Get Current Version |
71 | | - shell: bash -ex {0} |
72 | | - run: | |
73 | | - CURRENT_VERSION=$(node -p 'require("./package.json").version') |
74 | | - echo "::set-env name=CURRENT_VERSION::${CURRENT_VERSION}" |
| 31 | + - name: Run tests |
| 32 | + run: npm test |
75 | 33 |
|
76 | | - - name: Publish |
77 | | - if: env.PREV_VERSION != env.CURRENT_VERSION |
78 | | - run: | |
79 | | - npm run build |
80 | | - npm publish |
| 34 | + - name: Publish to NPM |
| 35 | + run: npm publish --access public |
81 | 36 | env: |
82 | 37 | NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} |
83 | 38 |
|
84 | | - - name: Push changes |
85 | | - uses: ad-m/github-push-action@v0.6.0 |
86 | | - if: env.PREV_VERSION != env.CURRENT_VERSION |
| 39 | + - name: Create GitHub Release |
| 40 | + uses: softprops/action-gh-release@v2 |
87 | 41 | with: |
88 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
89 | | - branch: ${{ github.ref }} |
90 | | - tags: true |
91 | | - |
92 | | - - name: Create comment |
93 | | - uses: actions/github-script@0.8.0 |
94 | | - if: env.PREV_VERSION != env.CURRENT_VERSION |
95 | | - with: |
96 | | - github-token: ${{secrets.GITHUB_TOKEN}} |
97 | | - script: | |
98 | | - github.issues.createComment({ |
99 | | - issue_number: context.issue.number, |
100 | | - owner: context.repo.owner, |
101 | | - repo: context.repo.repo, |
102 | | - body: 'NPM package v${{ env.CURRENT_VERSION }} has been published 🎉' |
103 | | - }) |
| 42 | + tag_name: ${{ github.ref_name }} |
| 43 | + name: Release ${{ github.ref_name }} |
| 44 | + generate_release_notes: true |
| 45 | + draft: false |
| 46 | + prerelease: false |
| 47 | + env: |
| 48 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments