-
Notifications
You must be signed in to change notification settings - Fork 12
177 lines (176 loc) · 5.31 KB
/
build.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
name: build
on:
merge_group: {}
pull_request: {}
workflow_dispatch: {}
push:
branches:
- main
- maintenance/*
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
self-mutation-needed: ${{ steps.self-mutation.outputs.needed }}
env:
CI: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: yarn
- name: Cache build outputs
if: github.event_name == 'pull_request'
uses: actions/cache@v3
with:
key: build-outputs-${{ hashFiles('tsconfig.json', 'build-tools/**/*.ts', 'src/**/*.ts', 'package.json', 'yarn.lock') }}
path: |-
tsconfig.tsbuildinfo
lib/**/*
restore-keys: build-outputs-
- name: Install dependencies
run: yarn install --check-files
- name: compile
run: npx projen && npx projen pre-compile && npx projen compile && npx projen post-compile
- name: test
run: npx projen test
- name: Find mutations
id: self-mutation
run: |-
git add .
git diff --staged --patch --exit-code > .repo.patch || echo "needed=true" >> $GITHUB_OUTPUT
- name: Upload patch
if: steps.self-mutation.outputs.needed
uses: actions/[email protected]
with:
name: .repo.patch
path: .repo.patch
overwrite: true
- name: Fail if self-mutation is needed
if: steps.self-mutation.outputs.needed
run: |-
echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch."
cat .repo.patch
exit 1
- name: Upload artifact
uses: actions/[email protected]
with:
name: build-output
path: |-
${{ github.workspace }}
!${{ github.workspace }}/node_modules
!${{ github.workspace }}/fixtures/node_modules
overwrite: true
self-mutation:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
env:
CI: "true"
if: always() && (github.event_name == 'pull_request') && needs.build.outputs.self-mutation-needed && (github.event.pull_request.head.repo.full_name == github.repository)
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
- name: Download patch
uses: actions/download-artifact@v4
with:
name: .repo.patch
path: ${{ runner.temp }}
- name: Apply patch
run: '[ -s ${{ runner.temp }}/.repo.patch ] && git apply ${{ runner.temp }}/.repo.patch || echo "Empty patch. Skipping."'
- name: Set git identity
run: |-
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Push changes
run: |-
git add .
git commit -s -m "chore: self-mutation"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
matrix-test:
name: test (node ${{ matrix.node-version }})
needs: build
runs-on: ubuntu-latest
permissions: {}
env:
CI: "true"
if: success()
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: ${{ github.workspace }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Re-run post-compile
run: npx projen post-compile
- name: Test
run: npx projen test
- name: Assert clean working directory
run: git diff --staged --exit-code
strategy:
fail-fast: false
matrix:
node-version:
- 18.x
- 20.x
- 22.x
matrix-clear:
name: Unit Tests
needs: matrix-test
runs-on: ubuntu-latest
permissions: {}
env:
CI: "true"
if: always()
steps:
- name: Build result
run: echo ${{needs.matrix-test.result}}
- name: Set status based on matrix build
if: ${{ needs.matrix-test.result != 'success' }}
run: exit 1
package:
name: package
needs: build
runs-on: ubuntu-latest
permissions: {}
env:
CI: "true"
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: ${{ github.workspace }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Package
run: npx projen package
- name: Upload artifact
uses: actions/[email protected]
with:
name: release-package
path: ${{ github.workspace }}/dist
overwrite: true