Skip to content

Commit c114833

Browse files
committed
new release workflow
1 parent 8e94436 commit c114833

File tree

2 files changed

+134
-2
lines changed

2 files changed

+134
-2
lines changed

.github/workflows/release.yml

+110-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ name: Automatic Release Creation
22

33
on:
44
workflow_dispatch:
5+
schedule:
6+
- cron: '0 10 * * *'
57

68
jobs:
79
create-metadata:
810
runs-on: ubuntu-latest
911
outputs:
1012
hash: ${{ steps.last-release.outputs.hash }}
1113
version: ${{ steps.create-version.outputs.version}}
14+
npm_packages: ${{ steps.create-npm-packages.outputs.npm_packages}}
15+
pypi_packages: ${{ steps.create-pypi-packages.outputs.pypi_packages}}
1216
steps:
1317
- uses: actions/checkout@v4
1418
with:
@@ -43,8 +47,25 @@ jobs:
4347
name: release-notes
4448
path: RELEASE_NOTES.md
4549

50+
- name: Create python matrix
51+
id: create-pypi-packages
52+
run: |
53+
HASH="${{ steps.last-release.outputs.hash }}"
54+
PYPI=$(uv run --script scripts/release.py generate-matrix --pypi --directory src $HASH)
55+
echo "pypi_packages $PYPI"
56+
echo "pypi_packages=$PYPI" >> $GITHUB_OUTPUT
57+
58+
- name: Create npm matrix
59+
id: create-npm-packages
60+
run: |
61+
HASH="${{ steps.last-release.outputs.hash }}"
62+
NPM=$(uv run --script scripts/release.py generate-matrix --npm --directory src $HASH)
63+
echo "npm_packages $NPM"
64+
echo "npm_packages=$NPM" >> $GITHUB_OUTPUT
65+
4666
update-packages:
4767
needs: [create-metadata]
68+
if: ${{ needs.create-metadata.outputs.npm_packages != '[]' || needs.create-metadata.outputs.pypi_packages != '[]' }}
4869
runs-on: ubuntu-latest
4970
outputs:
5071
changes_made: ${{ steps.commit.outputs.changes_made }}
@@ -80,8 +101,95 @@ jobs:
80101
echo "changes_made=true" >> $GITHUB_OUTPUT
81102
fi
82103
83-
create-release:
104+
publish-pypi:
105+
needs: [update-packages, create-metadata]
106+
strategy:
107+
fail-fast: false
108+
matrix:
109+
package: ${{ fromJson(needs.create-metadata.outputs.pypi_packages) }}
110+
name: Build ${{ matrix.package }}
111+
environment: release
112+
permissions:
113+
id-token: write # Required for trusted publishing
114+
runs-on: ubuntu-latest
115+
steps:
116+
- uses: actions/checkout@v4
117+
with:
118+
ref: ${{ needs.create-metadata.outputs.version }}
119+
120+
- name: Install uv
121+
uses: astral-sh/setup-uv@v5
122+
123+
- name: Set up Python
124+
uses: actions/setup-python@v5
125+
with:
126+
python-version-file: "src/${{ matrix.package }}/.python-version"
127+
128+
- name: Install dependencies
129+
working-directory: src/${{ matrix.package }}
130+
run: uv sync --frozen --all-extras --dev
131+
132+
- name: Run pyright
133+
working-directory: src/${{ matrix.package }}
134+
run: uv run --frozen pyright
135+
136+
- name: Build package
137+
working-directory: src/${{ matrix.package }}
138+
run: uv build
139+
140+
- name: Publish package to PyPI
141+
uses: pypa/gh-action-pypi-publish@release/v1
142+
with:
143+
skip-existing: true
144+
packages-dir: src/${{ matrix.package }}/dist
145+
146+
publish-npm:
84147
needs: [update-packages, create-metadata]
148+
strategy:
149+
fail-fast: false
150+
matrix:
151+
package: ${{ fromJson(needs.create-metadata.outputs.npm_packages) }}
152+
name: Build ${{ matrix.package }}
153+
environment: release
154+
runs-on: ubuntu-latest
155+
steps:
156+
- uses: actions/checkout@v4
157+
with:
158+
ref: ${{ needs.create-metadata.outputs.version }}
159+
160+
- uses: actions/setup-node@v4
161+
with:
162+
node-version: 22
163+
cache: npm
164+
registry-url: 'https://registry.npmjs.org'
165+
166+
- name: Install dependencies
167+
working-directory: src/${{ matrix.package }}
168+
run: npm ci
169+
170+
- name: Check if version exists on npm
171+
working-directory: src/${{ matrix.package }}
172+
run: |
173+
VERSION=$(jq -r .version package.json)
174+
if npm view --json | jq --arg version "$VERSION" '[.[]][0].versions | contains([$version])'; then
175+
echo "Version $VERSION already exists on npm"
176+
exit 1
177+
fi
178+
echo "Version $VERSION is new, proceeding with publish"
179+
180+
- name: Build package
181+
working-directory: src/${{ matrix.package }}
182+
run: npm run build
183+
184+
- name: Publish package
185+
working-directory: src/${{ matrix.package }}
186+
run: |
187+
npm publish --access public
188+
env:
189+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
190+
191+
create-release:
192+
needs: [update-packages, create-metadata, publish-pypi, publish-npm]
85193
if: needs.update-packages.outputs.changes_made == 'true'
86194
runs-on: ubuntu-latest
87195
environment: release
@@ -97,7 +205,7 @@ jobs:
97205

98206
- name: Create release
99207
env:
100-
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
208+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN}}
101209
run: |
102210
VERSION="${{ needs.create-metadata.outputs.version }}"
103211
gh release create "$VERSION" \

scripts/release.py

+24
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,29 @@ def generate_version() -> int:
182182
return 0
183183

184184

185+
@cli.command("generate-matrix")
186+
@click.option(
187+
"--directory", type=click.Path(exists=True, path_type=Path), default=Path.cwd()
188+
)
189+
@click.option("--npm", is_flag=True, default=False)
190+
@click.option("--pypi", is_flag=True, default=False)
191+
@click.argument("git_hash", type=GIT_HASH)
192+
def generate_matrix(directory: Path, git_hash: GitHash, pypi: bool, npm: bool) -> int:
193+
# Detect package type
194+
path = directory.resolve(strict=True)
195+
version = gen_version()
196+
197+
changes = []
198+
for package in find_changed_packages(path, git_hash):
199+
pkg = package.path.relative_to(path)
200+
if npm and isinstance(package, NpmPackage):
201+
changes.append(str(pkg))
202+
if pypi and isinstance(package, PyPiPackage):
203+
changes.append(str(pkg))
204+
205+
click.echo(json.dumps(changes))
206+
return 0
207+
208+
185209
if __name__ == "__main__":
186210
sys.exit(cli())

0 commit comments

Comments
 (0)