Skip to content

Commit c27959f

Browse files
committed
add ci.yml
1 parent d8dc909 commit c27959f

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/workflows/ci.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
4+
name: CI
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
on:
9+
push:
10+
branches:
11+
- "**"
12+
pull_request:
13+
branches:
14+
- "**"
15+
workflow_dispatch:
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix:
24+
node-version:
25+
- 18.x
26+
- 20.x
27+
- 22.x
28+
29+
steps:
30+
- uses: actions/checkout@v5
31+
- name: Use Node.js ${{ matrix.node-version }}
32+
uses: actions/setup-node@v6
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
- run: npm ci
36+
- run: npm run lint --if-present
37+
- run: npm test
38+
- run: npm run build --if-present
39+
- name: Save build
40+
if: matrix.node-version == '20.x'
41+
uses: actions/upload-artifact@v5
42+
with:
43+
name: build
44+
path: |
45+
.
46+
!node_modules
47+
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.
52+
runs-on: ubuntu-latest
53+
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}} # Detect that the PR author is dependabot
54+
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}}
60+
61+
npm-publish-build:
62+
needs: build
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/download-artifact@v6
66+
with:
67+
name: build
68+
- uses: actions/setup-node@v6
69+
with:
70+
node-version: 20.x
71+
- uses: rlespinasse/[email protected]
72+
- name: Append commit hash to package version
73+
run: 'sed -i -E "s/(\"version\": *\"[^\"]+)/\1-${GITHUB_SHA_SHORT}/" package.json'
74+
- name: Disable pre- and post-publish actions
75+
run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
76+
- uses: JS-DevTools/[email protected]
77+
if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
78+
with:
79+
token: ${{ secrets.NPM_TOKEN }}
80+
tag: ${{ env.GITHUB_REF_SLUG }}
81+
82+
npm-publish-latest:
83+
needs: [build, npm-publish-build]
84+
runs-on: ubuntu-latest
85+
if: github.ref == 'refs/heads/main'
86+
steps:
87+
- uses: actions/download-artifact@v6
88+
with:
89+
name: build
90+
- uses: actions/setup-node@v6
91+
with:
92+
node-version: 20.x
93+
- name: Disable pre- and post-publish actions
94+
run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
95+
- uses: JS-DevTools/[email protected]
96+
if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
97+
with:
98+
token: ${{ secrets.NPM_TOKEN }}
99+
tag: latest

0 commit comments

Comments
 (0)