-
Notifications
You must be signed in to change notification settings - Fork 4
173 lines (150 loc) · 4.87 KB
/
Copy pathrelease.yml
File metadata and controls
173 lines (150 loc) · 4.87 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
create_github_release:
description: "Create or update the GitHub release"
required: true
type: boolean
default: false
publish_npm:
description: "Publish to npm through trusted publishing"
required: true
type: boolean
default: false
publish_pypi:
description: "Publish to PyPI through trusted publishing"
required: true
type: boolean
default: true
permissions:
contents: read
jobs:
build:
name: Build and verify artifacts
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Determine release version
id: version
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
version="${GITHUB_REF_NAME#v}"
else
version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
fi
package_version="$(node -p "require('./package.json').version")"
python_version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
if [[ "${version}" != "${package_version}" || "${version}" != "${python_version}" ]]; then
echo "version mismatch: release=${version} package.json=${package_version} pyproject.toml=${python_version}" >&2
exit 1
fi
echo "version=${version}" >> "${GITHUB_OUTPUT}"
- name: Test Go packages
run: CGO_ENABLED=0 go test ./...
- name: Build Go release binaries
run: scripts/build-release.sh "${{ steps.version.outputs.version }}"
- name: Check npm package
run: npm pack --dry-run
- name: Build Python package
run: |
python -m pip install --upgrade build twine
python -m build
python -m twine check dist/subrouter-*.tar.gz dist/subrouter-*.whl
- name: Upload Go release artifacts
uses: actions/upload-artifact@v5
with:
name: release-assets
path: dist/release/*
if-no-files-found: error
- name: Upload Python distributions
uses: actions/upload-artifact@v5
with:
name: python-dist
path: |
dist/subrouter-*.tar.gz
dist/subrouter-*.whl
if-no-files-found: error
github-release:
name: Publish GitHub release
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event.inputs.create_github_release == 'true' }}
permissions:
contents: write
steps:
- name: Download Go release artifacts
uses: actions/download-artifact@v5
with:
name: release-assets
path: dist/release
- name: Create or update GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: v${{ needs.build.outputs.version }}
run: |
set -euo pipefail
if gh release view "${TAG_NAME}" >/dev/null 2>&1; then
gh release upload "${TAG_NAME}" dist/release/* --clobber
else
gh release create "${TAG_NAME}" dist/release/* \
--title "Subrouter ${TAG_NAME}" \
--notes "Subrouter ${TAG_NAME}"
fi
npm-publish:
name: Publish npm package
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event.inputs.publish_npm == 'true' }}
environment: npm
permissions:
contents: read
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Publish to npm
run: npm publish --access public
pypi-publish:
name: Publish PyPI package
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event.inputs.publish_pypi == 'true' }}
environment: pypi
permissions:
contents: read
id-token: write
steps:
- name: Download Python distributions
uses: actions/download-artifact@v5
with:
name: python-dist
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1