Repository navigation
179 lines (171 loc) · 6.68 KB
/
Copy pathrelease.yml
File metadata and controls
179 lines (171 loc) · 6.68 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
name: Release
on:
push:
tags:
- 'v*.*.*'
# Least privilege at the top, escalation only where it is needed. A job-level
# block REPLACES this set rather than adding to it, so any job needing more
# states everything it needs.
#
# `id-token: write` is deliberately NOT here. It mints an OIDC token, and our npm
# trusted publisher accepts one to publish `refactron`. Granting it workflow-wide
# handed that capability to `test-before-release`, which installs the dependency
# tree with lifecycle scripts enabled on purpose (see #133). Only the two publish
# jobs get it now, via their own blocks.
permissions:
contents: read
jobs:
validate-tag:
name: Validate Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.tag.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: tag
run: |
TAG=${GITHUB_REF#refs/tags/v}
PKG=$(node -p "require('./package.json').version")
# The wrapper declares its version once, in __init__.py, and
# pyproject.toml reads it dynamically via setuptools `attr:`. Grepping
# pyproject for a literal finds the attr expression, not a version.
PY=$(grep -m1 '^__version__' refactron-py/refactron/__init__.py | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$PY" ]; then
echo "Could not read __version__ from refactron-py/refactron/__init__.py"
exit 1
fi
if [ "$TAG" != "$PKG" ]; then
echo "Tag $TAG does not match package.json version $PKG"
exit 1
fi
if [ "$TAG" != "$PY" ]; then
echo "Tag $TAG does not match refactron-py/pyproject.toml version $PY"
exit 1
fi
echo "version=$TAG" >> $GITHUB_OUTPUT
test-before-release:
name: Full Test Suite
needs: validate-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install pytest requests coverage
- run: npm ci
- run: npm run typecheck
# Build first: the CLI drift test asserts against dist/ and fails without it.
- run: npm run build
- run: npm test
- run: node dist/cli/index.js --version
publish-npm:
name: Publish to npm
needs: test-before-release
runs-on: ubuntu-latest
environment: npm-production
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
# --ignore-scripts, and NOT for tidiness. This job holds id-token:write for
# the npm trusted publisher, so it can mint a token that publishes
# `refactron`. A lifecycle script from any dependency at any depth would
# run right here, with that capability. The install is the window; the
# publish step below was already closed.
#
# Safe because `npm run build` is tsc plus a plain-node postbuild script,
# neither of which needs a dependency install hook, and this repo's own
# `prepare` only activates local githooks that a runner never uses.
# Verified rather than assumed: two clean clones, one installed each way,
# produced an IDENTICAL published tarball (149 files, same sizes, via
# `npm pack --dry-run --json`).
#
# test-before-release deliberately keeps its scripts: it runs the real
# suite, vitest reaches esbuild's postinstall-provided platform binary,
# and that job executes repository code by design anyway.
- run: npm ci --ignore-scripts
# npm OIDC trusted-publisher auth requires npm >= 11.5.1 and Node 20
# ships an older bundled npm, so this upgrade is mandatory. Pin the MAJOR
# rather than tracking `latest`: npm 12 dropped Node 20 (it requires
# ^22.22.2 || ^24.15.0 || >=26.0.0), so `latest` silently became
# uninstallable here and broke the release. npm 11 supports
# ^20.17.0 || >=22.9.0, which covers this runner either way.
- run: npm install -g npm@^11.5.1
- run: npm run build
# --ignore-scripts skips prepublishOnly (full test gate). We already
# ran the equivalent in test-before-release; re-running here would
# require Python and coverage on this minimal runner for no extra signal.
- run: npm publish --provenance --access public --ignore-scripts
publish-pypi:
name: Publish to PyPI
needs: test-before-release
runs-on: ubuntu-latest
environment:
name: pypi-production
url: https://pypi.org/p/refactron
permissions:
# A job-level permissions block REPLACES the default set rather than
# adding to it. Without contents:read, GITHUB_TOKEN cannot read this
# private repo and actions/checkout fails with "Repository not found".
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Build wrapper
working-directory: refactron-py
run: |
python -m pip install --upgrade build
python -m build
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: refactron-py/dist
skip-existing: true
github-release:
name: Create GitHub Release
needs: [publish-npm, publish-pypi]
runs-on: ubuntu-latest
# The one job that writes to the repository: action-gh-release creates the
# release. `write` implies read, so actions/checkout still works with only
# this line. No id-token: this job publishes nothing to a registry.
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
LOG=$(git log $PREV_TAG..HEAD --pretty=format:"- %s" --no-merges)
else
LOG=$(git log --pretty=format:"- %s" --no-merges | head -20)
fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$LOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- uses: softprops/action-gh-release@v2
with:
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}
## Install
```
npm install -g refactron@${{ needs.validate-tag.outputs.version }}
```
generate_release_notes: true