1- # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
41name : CI
52permissions :
63 contents : write
74 pull-requests : write
85on :
96 push :
107 branches :
11- - " ** "
8+ - main
129 pull_request :
1310 branches :
14- - " **"
15- workflow_dispatch :
11+ - main
1612
1713jobs :
1814 build :
19-
2015 runs-on : ubuntu-latest
21-
2216 strategy :
2317 matrix :
24- node-version :
25- - 18.x
18+ node-version :
2619 - 20.x
2720 - 22.x
28-
2921 steps :
30- - uses : actions/checkout@v5
22+ - uses : actions/checkout@v2
3123 - name : Use Node.js ${{ matrix.node-version }}
3224 uses : actions/setup-node@v6
3325 with :
3426 node-version : ${{ matrix.node-version }}
3527 - run : npm ci
36- - run : npm run lint --if-present
3728 - run : npm test
38- - run : npm run build --if-present
29+ - run : npm run build
3930 - name : Save build
4031 if : matrix.node-version == '20.x'
4132 uses : actions/upload-artifact@v5
@@ -45,15 +36,43 @@ jobs:
4536 .
4637 !node_modules
4738 retention-days : 1
48-
49- dependabot :
50- name : ' Dependabot'
51- needs : build # After the E2E and build jobs, if one of them fails, it won't merge the PR.
39+
40+ npm-publish-build :
41+ needs : build
42+ runs-on : ubuntu-latest
43+ steps :
44+ - uses : actions/download-artifact@v6
45+ with :
46+ name : build
47+ - uses : actions/setup-node@v6
48+ with :
49+ node-version : 20.x
50+ - uses : rlespinasse/github-slug-action@v3.x
51+ - name : Append commit hash to package version
52+ run : ' sed -i -E "s/(\"version\": *\"[^\"]+)/\1-${GITHUB_SHA_SHORT}/" package.json'
53+ - name : Disable pre- and post-publish actions
54+ run : ' sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
55+ - uses : JS-DevTools/npm-publish@v4.1.0
56+ if : github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
57+ with :
58+ token : ${{ secrets.NPM_TOKEN }}
59+ tag : ${{ env.GITHUB_REF_SLUG }}
60+
61+ npm-publish-latest :
62+ needs : [build, npm-publish-build]
5263 runs-on : ubuntu-latest
53- if : ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}} # Detect that the PR author is dependabot
64+ if : github.ref == 'refs/heads/main'
5465 steps :
55- - name : Enable auto-merge for Dependabot PRs
56- run : gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR
57- env :
58- PR_URL : ${{github.event.pull_request.html_url}}
59- GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
66+ - uses : actions/download-artifact@v6
67+ with :
68+ name : build
69+ - uses : actions/setup-node@v6
70+ with :
71+ node-version : 20.x
72+ - name : Disable pre- and post-publish actions
73+ run : ' sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
74+ - uses : JS-DevTools/npm-publish@v4.1.0
75+ if : github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
76+ with :
77+ token : ${{ secrets.NPM_TOKEN }}
78+ tag : latest
0 commit comments