-
Notifications
You must be signed in to change notification settings - Fork 11
159 lines (133 loc) · 5.06 KB
/
pr-build-and-check.yml
File metadata and controls
159 lines (133 loc) · 5.06 KB
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
name: PR Build and Check
on:
pull_request:
branches:
- main
jobs:
build:
name: Build and Check
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: yarn install --immutable
- name: Run Checks
run: yarn check
- name: Build
run: yarn build
- name: Run Tests
run: yarn test
docs-check:
name: Documentation Validation
runs-on: ubuntu-latest
defaults:
run:
working-directory: docs
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for docs changes
id: docs-changes
working-directory: .
run: |
DOCS_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/ | grep '\.md$' || true)
if [ -z "$DOCS_CHANGED" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "No markdown changes in docs/"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
DELIM=$(openssl rand -hex 8)
echo "changed_files<<$DELIM" >> "$GITHUB_OUTPUT"
echo "$DOCS_CHANGED" >> "$GITHUB_OUTPUT"
echo "$DELIM" >> "$GITHUB_OUTPUT"
echo "Changed docs files:"
echo "$DOCS_CHANGED"
fi
- name: Setup Node.js
if: steps.docs-changes.outputs.skip != 'true'
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Enable Corepack
if: steps.docs-changes.outputs.skip != 'true'
run: corepack enable
- name: Install docs dependencies
if: steps.docs-changes.outputs.skip != 'true'
run: yarn install --immutable
- name: Build documentation (validates internal links)
if: steps.docs-changes.outputs.skip != 'true'
run: yarn build
- name: Check external links in changed files
if: steps.docs-changes.outputs.skip != 'true'
run: |
FILES=$(echo "${{ steps.docs-changes.outputs.changed_files }}" | sed 's|^docs/||' | xargs)
echo "Checking files: $FILES"
yarn markdown-link-check --config .markdown-link-check.json $FILES
version-check:
name: Version Bump Check
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for source changes requiring version bump
id: changes
run: |
CHANGED_FILES=$(git diff --name-only origin/main...HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
NEEDS_BUMP=false
while IFS= read -r file; do
case "$file" in
src/*|tsconfig.build.json|tsconfig.base.json)
NEEDS_BUMP=true
break
;;
package.json)
# Check if anything other than "version" changed
OTHER_CHANGES=$(git diff origin/main...HEAD -- package.json | grep -E '^[+-]\s' | grep -v -E '^\+\+\+|^---' | grep -v '"version"' || true)
if [ -n "$OTHER_CHANGES" ]; then
NEEDS_BUMP=true
break
fi
;;
esac
done <<< "$CHANGED_FILES"
echo "needs_bump=$NEEDS_BUMP" >> "$GITHUB_OUTPUT"
- name: Verify version bump and changelog
if: steps.changes.outputs.needs_bump == 'true'
run: |
PR_VERSION=$(node -p "require('./package.json').version")
MAIN_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version")
echo "Main version: $MAIN_VERSION"
echo "PR version: $PR_VERSION"
if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
echo "::error::Source files or dependencies changed but package version was not bumped. Please update the version in package.json."
exit 1
fi
HIGHER=$(node -e "
const [a, b] = ['$PR_VERSION', '$MAIN_VERSION'].map(v => v.split('.').map(Number));
const isHigher = a[0] > b[0] || (a[0] === b[0] && a[1] > b[1]) || (a[0] === b[0] && a[1] === b[1] && a[2] > b[2]);
process.exit(isHigher ? 0 : 1);
" && echo "true" || echo "false")
if [ "$HIGHER" != "true" ]; then
echo "::error::PR version ($PR_VERSION) must be higher than main version ($MAIN_VERSION)."
exit 1
fi
echo "Version bumped from $MAIN_VERSION to $PR_VERSION"
CHANGELOG_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/changelog.md)
if [ -z "$CHANGELOG_CHANGED" ]; then
echo "::error::Version was bumped but docs/changelog.md was not updated. Please add a changelog entry for version $PR_VERSION."
exit 1
fi
echo "Changelog updated for version bump"