-
Notifications
You must be signed in to change notification settings - Fork 2
170 lines (162 loc) · 6.03 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
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
name: CI
on:
push:
branches: ["master", "feature/*"]
pull_request:
branches: ["master"]
schedule:
# Run hourly at 22 minutes past the hour
- cron: "22 * * * *"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
HOWDJU_RUNNING_IN_GITHUB_WORKFLOW:
TEST_POSTGRES_PASSWORD: "TEST_POSTGRES_PASSWORD"
NODE_VERSION: 18.18.2
YARN_VERSION: 4.5.3
jobs:
premerge-checks:
runs-on: ubuntu-latest
services:
howdju-db:
image: postgres:12.5
env:
POSTGRES_PASSWORD: ${{ env.TEST_POSTGRES_PASSWORD }}
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.JS
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
- name: Install Yarn
run: |
corepack enable
yarn set version ${{ env.YARN_VERSION }}
- name: Install dependencies
run: yarn install
- name: Check format
run: yarn run check-format:all
- name: Typecheck
run: |
echo tsc version: $(yarn run tsc -v)
yarn run typecheck:all
- name: Lint
# Lint must come after typecheck to rely on the types
run: yarn run lint:all
- name: Test & coverage
env:
DB_USER: postgres
DB_PASSWORD: ${{ env.TEST_POSTGRES_PASSWORD }}
DB_HOST: localhost
DB_PORT: 5432
LOG_LEVEL: silly
NODE_ENV: test
run: yarn run test:all:coverage
- name: Create merged coverage
run: |
yarn run merge:coverage
yarn run nyc report -t coverage --report-dir coverage/html --reporter=html-spa --reporter=text-summary
- name: Archive coverage results
uses: actions/upload-artifact@v3
if: ${{ github.ref == 'refs/heads/master' }}
with:
name: coverage-report
path: |
coverage/**
!coverage/workspaces/**
if-no-files-found: error
- name: Custom checks
run: yarn run custom-check:all
- name: Check TODO format
run: |
git fetch origin ${{ github.event.pull_request.base.sha }}
git fetch origin ${{ github.event.pull_request.head.sha }}
yarn run check:todo-format ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
- name: Check do-not-merge
run: yarn run check:do-not-merge
changed-files-coverage-check:
# Only run on PRs && don't run on dependant CLs
# Don't run on dependabot CLs because 1) the PR comment step below fails, I think because we
# can't comment on dependabot PRs, and 2) dependabot PRs only change dependencies and so can't
# affect code coverage. The premerge-checks job should ensure that the upgrade didn't break anything.
if: github.ref != 'refs/heads/master' && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
services:
howdju-db:
image: postgres:12.5
env:
POSTGRES_PASSWORD: ${{ env.TEST_POSTGRES_PASSWORD }}
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# During a pre-merge check, Github creates and checks out an temporary merge commit. That
# commit won't work as the HEAD for yarn --changedSince
ref: ${{ github.event.pull_request.head.sha }}
- name: Fetch merge base commits
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch commits to a depth so that head and base reach their merge base.
comparison=$(gh api\
repos/Howdju/howdju/compare/${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }})
behind_by=$(echo -E $comparison | jq -r '.behind_by')
ahead_by=$(echo -E $comparison | jq -r '.ahead_by')
echo "ahead_by: $ahead_by; behind by: $behind_by"
# +1 because fetch depth=1 is the commit itself.
if [[ $behind_by -gt 0 ]]; then
base_depth=$((behind_by+1))
echo Fetching base to depth $base_depth
git -c protocol.version=2 fetch --no-tags --no-recurse-submodules\
--depth=$base_depth origin ${{ github.event.pull_request.base.sha }}
fi
if [[ $ahead_by -gt 0 ]]; then
head_depth=$((ahead_by+1))
echo Fetching head to depth $head_depth
git -c protocol.version=2 fetch --no-tags --no-recurse-submodules\
--depth=$head_depth origin ${{ github.event.pull_request.head.sha }}
fi
- name: Setup Node.JS
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
- name: Install Yarn
run: |
corepack enable
yarn set version ${{ env.YARN_VERSION }}
- name: Install dependencies
run: yarn install
- name: Changed-files test coverage
env:
DB_USER: postgres
DB_PASSWORD: ${{ env.TEST_POSTGRES_PASSWORD }}
DB_HOST: localhost
DB_PORT: 5432
LOG_LEVEL: silly
NODE_ENV: test
run: yarn run test:all:coverage:changed ${{ github.event.pull_request.base.sha }}
- name: Output merged changed-files coverage summary
id: changed-files-coverage-summary
run: |
yarn run merge:coverage
output=$(yarn run nyc report -t coverage --reporter=text-summary)
delimiter="$(openssl rand -hex 8)"
echo "coverage_summary<<${delimiter}" >> $GITHUB_OUTPUT
echo "${output}" >> $GITHUB_OUTPUT
echo "${delimiter}" >> $GITHUB_OUTPUT
- name: Create changed-files coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Changed-files coverage
message: |
# Changed-files coverage summary
```
${{ steps.changed-files-coverage-summary.outputs.coverage_summary }}
```