Skip to content

Commit 9326a01

Browse files
committed
add workflow
1 parent fd0687d commit 9326a01

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
- package-ecosystem: "github-actions"
13+
directory: "/"
14+
schedule:
15+
# Check for updates to GitHub Actions every week
16+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: CI
2+
permissions:
3+
contents: write
4+
pull-requests: write
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
node-version:
20+
- 20.x
21+
- 22.x
22+
steps:
23+
- uses: actions/checkout@v5
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v6
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
- run: npm ci
29+
- run: npm run build
30+
- run: npm run test
31+
- name: Save build
32+
if: matrix.node-version == '20.x'
33+
uses: actions/upload-artifact@v5
34+
with:
35+
name: build
36+
path: |
37+
.
38+
!node_modules
39+
retention-days: 1
40+
41+
gh-pages:
42+
needs: build
43+
runs-on: ubuntu-latest
44+
if: github.ref == 'refs/heads/main'
45+
steps:
46+
- uses: actions/download-artifact@v6
47+
with:
48+
name: build
49+
- uses: peaceiris/actions-gh-pages@v4
50+
with:
51+
github_token: ${{ secrets.GITHUB_TOKEN }}
52+
publish_dir: .
53+
54+
dependabot:
55+
name: 'Dependabot'
56+
needs: build # After the E2E and build jobs, if one of them fails, it won't merge the PR.
57+
runs-on: ubuntu-latest
58+
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}} # Detect that the PR author is dependabot
59+
steps:
60+
- name: Enable auto-merge for Dependabot PRs
61+
run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR
62+
env:
63+
PR_URL: ${{github.event.pull_request.html_url}}
64+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
65+
66+
npm-publish-build:
67+
needs: build
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/download-artifact@v6
71+
with:
72+
name: build
73+
- uses: actions/setup-node@v6
74+
with:
75+
node-version: 20.x
76+
- uses: rlespinasse/github-slug-action@v3.x
77+
- name: Append commit hash to package version
78+
run: 'sed -i -E "s/(\"version\": *\"[^\"]+)/\1-${GITHUB_SHA_SHORT}/" package.json'
79+
- name: Disable pre- and post-publish actions
80+
run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
81+
- uses: JS-DevTools/npm-publish@v4.1.1
82+
if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
83+
with:
84+
token: ${{ secrets.NPM_TOKEN }}
85+
tag: ${{ env.GITHUB_REF_SLUG }}
86+
87+
npm-publish-latest:
88+
needs: [build, npm-publish-build]
89+
runs-on: ubuntu-latest
90+
if: github.ref == 'refs/heads/main'
91+
steps:
92+
- uses: actions/download-artifact@v6
93+
with:
94+
name: build
95+
- uses: actions/setup-node@v6
96+
with:
97+
node-version: 20.x
98+
- name: Disable pre- and post-publish actions
99+
run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json'
100+
- uses: JS-DevTools/npm-publish@v4.1.1
101+
if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
102+
with:
103+
token: ${{ secrets.NPM_TOKEN }}
104+
tag: latest

0 commit comments

Comments
 (0)