-
Notifications
You must be signed in to change notification settings - Fork 70
138 lines (124 loc) · 4.66 KB
/
release-npm.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# This workflow reacts on a PR that is labeled with "automated pr", will automatically merge it and
# create a new release on npm.
name: Automatic Labeled Release
on:
pull_request:
types: [labeled]
# Cancel previous PR/branch runs when a new commit is pushed
concurrency:
group: ${{ github.ref }}-auto-npm-release
cancel-in-progress: true
jobs:
check-and-lint:
if: github.repository == 'project-chip/matter.js' && contains(github.event.pull_request.labels.*.name, 'automated pr')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare testing environment
uses: ./.github/actions/prepare-env
- run: npm run format-verify
- run: npm run lint
build-non-linux:
if: github.repository == 'project-chip/matter.js' && contains(github.event.pull_request.labels.*.name, 'automated pr')
needs: [ check-and-lint ]
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [ 18.x, 20.x, 22.x ]
os: [ macos-latest, windows-2019 ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
# needed as long as we test Node.js 16 and npm <10.2.2 is used for Node.js 18/20
with:
python-version: '3.11'
- name: Build on ${{ matrix.os }}
uses: ./.github/actions/prepare-env
with:
node-version: ${{ matrix.node-version }}
os: ${{ matrix.os }}
test:
if: github.repository == 'project-chip/matter.js' && contains(github.event.pull_request.labels.*.name, 'automated pr')
needs: [ check-and-lint ]
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x, 20.x, 22.x ]
steps:
- uses: actions/checkout@v4
- name: Prepare testing environment
uses: ./.github/actions/prepare-env
with:
node-version: ${{ matrix.node-version }}
- name: Prepare Webbrowser testing environment
uses: ./.github/actions/prepare-webtests
- name: Execute tests
run: npm run test
auto-merge:
if: |
always() &&
github.event_name == 'pull_request' &&
github.repository == 'project-chip/matter.js' &&
contains(github.event.pull_request.labels.*.name, 'automated pr')
needs: [ test, build-non-linux, check-and-lint ]
runs-on: ubuntu-latest
steps:
- id: automerge
name: automerge
uses: "pascalgn/[email protected]"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: "automated pr"
MERGE_FILTER_AUTHOR: "Automator77"
MERGE_FORKS: "false"
MERGE_DELETE_BRANCH: "false"
UPDATE_LABELS: "automated pr"
MERGE_METHOD: "squash"
MERGE_RETRIES: "50"
MERGE_RETRY_SLEEP: "60000"
- name: Checkout repository
if: steps.automerge.outputs.mergeResult == 'merged'
uses: actions/checkout@v4
- name: Use Node.js 20.x
if: steps.automerge.outputs.mergeResult == 'merged'
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies and build
if: steps.automerge.outputs.mergeResult == 'merged'
run: npm ci
- name: Determine version
if: steps.automerge.outputs.mergeResult == 'merged'
id: version
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const fs = require('fs');
return fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/version.txt`, "utf8");
- name: Apply new version to package files
if: steps.automerge.outputs.mergeResult == 'merged'
run: npm run version -- --apply
- name: Publish npm
if: steps.automerge.outputs.mergeResult == 'merged'
env:
PRERELEASE: ${{ contains(steps.version.outputs.result, '-') }}
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npm whoami
if [[ "$PRERELEASE" == "true" ]]; then
npm publish --workspaces --tag dev
else
npm publish --workspaces
fi
- name: Create Github Release
if: steps.automerge.outputs.mergeResult == 'merged'
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: v${{ steps.version.outputs.result }}
name: Release v${{ steps.version.outputs.result }}
draft: false
prerelease: ${{ contains(steps.version.outputs.result, '-') }}
body: "${{ contains(steps.version.outputs.result, '-') && 'Nightly release' || 'Official release, check CHANGELOG.md for details' }}"