-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (117 loc) · 3.71 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Node.js CI
on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
pull_request:
branches:
- main
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Install dependencies
run: npm ci
- name: Lint with ESLint
run: npm run lint
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Build and test
run: npm run build
- run: npm run test
- name: Upload coverage reports to Codecov
if: matrix.node-version == '20.x' && github.repository == 'tsutsu3/unbound-control-ts'
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
changelog:
name: Generate Changelog
runs-on: ubuntu-latest
if: startsWith(github.ref_name, 'release-v')
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Extract version from branch
id: extract_version
run: |
branch_name="${{ github.ref_name }}"
version="${branch_name#release-v}"
echo "version=v$version" >> $GITHUB_ENV
- name: Generate Changelog
run: |
git cliff --tag ${{ env.version }} --output CHANGELOG.md
git add CHANGELOG.md
git commit -m "chore: update CHANGELOG for version ${{ env.version }}"
git push origin ${{ github.ref_name }}
# After the PR is merged to the main branch, create a new tag and release
release:
name: Create Tag and Release
needs: test
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Extract version from branch
id: extract_version
run: |
branch_name=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
version=${branch_name#release-v}
echo "version=${version}" >> $GITHUB_ENV
- name: Generate Latest Changelog
run: |
git cliff --tag ${{ env.version }} --output CHANGELOG_DIFF.md --latest
- name: Create and push tag
run: |
git tag -a "v${{ env.version }}" -m "Release v${{ env.version }}"
git push origin "v${{ env.version }}"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "v${{ env.version }}"
release_name: "Release v${{ env.version }}"
body_path: CHANGELOG_DIFF.md
draft: false
prerelease: false
publish:
needs: [release]
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}