-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (165 loc) · 5.55 KB
/
Copy pathci.yml
File metadata and controls
185 lines (165 loc) · 5.55 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: CI
# Release topology: GitLab (origin, branch `master`) is primary; this repo is a GitHub MIRROR
# whose default branch is `main`. Each GitLab push mirrors a squashed snapshot to `main`, which
# triggers this workflow (lint/typecheck/test/build → CalVer npm publish). The `main` triggers
# below are CORRECT for the mirror — do NOT repoint them to `master`. See docs/project/runbook.md.
#
# Checks run for package code and their test/policy inputs. A separate job decides whether a
# push is publishable, so test-only and workflow-only changes cannot bump the npm CalVer version.
on:
workflow_dispatch:
push:
branches: [main]
paths:
- "src/**"
- "examples/**"
- "assets/**"
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- "tests/unit/**"
- "docs/**"
- "*.md"
- ".agents/**/*.md"
- ".claude/commands/**/*.md"
- "scripts/check-terminal-io.mjs"
- "scripts/check-markdown-links.mjs"
- "scripts/clean-build.mjs"
- "vitest.config.ts"
- "eslint.config.ts"
- ".prettierrc"
- "knip.json"
- ".dependency-cruiser.cjs"
- ".github/workflows/ci.yml"
pull_request:
branches: [main]
paths:
- "src/**"
- "examples/**"
- "assets/**"
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- "tests/unit/**"
- "docs/**"
- "*.md"
- ".agents/**/*.md"
- ".claude/commands/**/*.md"
- "scripts/check-terminal-io.mjs"
- "scripts/check-markdown-links.mjs"
- "scripts/clean-build.mjs"
- "vitest.config.ts"
- "eslint.config.ts"
- ".prettierrc"
- "knip.json"
- ".dependency-cruiser.cjs"
- ".github/workflows/ci.yml"
permissions:
contents: read
jobs:
package-changes:
name: Detect package changes
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
publish: ${{ steps.filter.outputs.publish }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check publishable paths
id: filter
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
exit 0
fi
BEFORE="${{ github.event.before }}"
if git cat-file -e "${BEFORE}^{commit}" 2>/dev/null && \
git diff --quiet "$BEFORE" "$GITHUB_SHA" -- \
src examples assets package.json package-lock.json tsconfig.json scripts/clean-build.mjs; then
echo "publish=false" >> "$GITHUB_OUTPUT"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi
check:
name: Lint & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
- name: Static checks
run: npm run lint:all
- name: Unit tests
run: npm run test:unit
- name: Build
run: npm run build
publish:
name: Publish to npm
needs: [check, package-changes]
if: needs.package-changes.outputs.publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- run: npm ci
- run: npm run build
- name: Set CalVer version from commit date
id: version
run: |
VERSION=$(git log -1 --format=%cd --date=format:%y.%-m%d.%H%M)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
npm version --no-git-tag-version "$VERSION" --allow-same-version
- name: Check if version exists on npm
id: check-npm
run: |
if npm view prompsit-cli@${{ steps.version.outputs.version }} version 2>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish
id: publish
if: steps.check-npm.outputs.exists == 'false'
run: npm publish --access public
- name: Extract release notes from CHANGELOG
if: steps.publish.outcome == 'success'
id: notes
run: |
sed -n '/^## Unreleased$/,/^## /{/^## /d;p}' CHANGELOG.md > /tmp/release-notes.md
if [ ! -s /tmp/release-notes.md ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub Release
if: steps.publish.outcome == 'success' && steps.notes.outputs.skip != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ steps.version.outputs.version }}" \
--title "v${{ steps.version.outputs.version }}" \
--notes-file /tmp/release-notes.md \
--latest
- name: Delete older GitHub Releases
if: steps.publish.outcome == 'success' && steps.notes.outputs.skip != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CURRENT="v${{ steps.version.outputs.version }}"
gh release list --limit 200 --json tagName --jq '.[].tagName' | while IFS= read -r tag; do
if [ -n "$tag" ] && [ "$tag" != "$CURRENT" ]; then
echo "Deleting old release: $tag"
gh release delete "$tag" --yes --cleanup-tag
fi
done