Skip to content

Commit f3a1749

Browse files
committed
dependencies and CI/CD
1 parent d4e7504 commit f3a1749

4 files changed

Lines changed: 7938 additions & 2674 deletions

File tree

.github/workflows/ci.yml

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
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-
41
name: CI
52
permissions:
63
contents: write
74
pull-requests: write
85
on:
96
push:
107
branches:
11-
- "**"
8+
- main
129
pull_request:
1310
branches:
14-
- "**"
15-
workflow_dispatch:
11+
- main
1612

1713
jobs:
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

.github/workflows/dependabot.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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}}

0 commit comments

Comments
 (0)