-
Notifications
You must be signed in to change notification settings - Fork 96
194 lines (165 loc) · 5.76 KB
/
release.yml
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
186
187
188
189
190
191
192
193
194
name: 'release'
on:
workflow_dispatch:
inputs:
changelog:
type: string
description: 'The frontend changelog'
required: true
push:
branches:
- 'main'
- 'alpha'
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
NEXT_VERSION: ${{ steps.dry-run.outputs.NEXT_VERSION }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: 20.8.1
- name: Semantic Release dry-run
id: dry-run
uses: cycjimmy/semantic-release-action@v4
with:
dry_run: true
extra_plugins: |
@semantic-release/commit-analyzer
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
needs: prepare
if: ${{ needs.prepare.outputs.NEXT_VERSION != '' }}
strategy:
fail-fast: false
matrix:
python-version: [3.11]
poetry-version: ['1.2.2']
os: [ubuntu-20.04]
node-version: [20.8.1]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Get next version
id: get-next-version
run: |
echo "NEXT_VERSION=$(echo "${{ needs.prepare.outputs.NEXT_VERSION }}")" >> $GITHUB_ENV
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download frontend
env:
CURRENT_BRANCH: ${{ github.ref_name }}
run: |
sh ./scripts/resolve_frontend.sh true
# ====================== release ======================
- name: Set test pip url
if: ${{ github.ref_name == 'alpha' }}
env:
NEXT_VERSION: ${{ env.NEXT_VERSION }}
run: |
echo "PYPI_URL=https://test.pypi.org/project/labelu/${{ env.NEXT_VERSION }}" >> $GITHUB_ENV
- name: Set release pip url
if: ${{ github.ref_name == 'main' }}
env:
NEXT_VERSION: ${{ env.NEXT_VERSION }}
run: |
echo "PYPI_URL=https://pypi.org/project/labelu/${{ env.NEXT_VERSION }}" >> $GITHUB_ENV
- name: Show pypi url
run: |
echo $PYPI_URL
- name: Inject backend info into frontend
uses: satackey/[email protected]
id: InjectBackend
env:
NEXT_VERSION: ${{ env.NEXT_VERSION }}
with:
required-packages: '@iarna/toml'
script: |
const fs = require('fs');
const path = require('path');
const toml = require('@iarna/toml');
const rootPath = path.join(process.cwd(), '');
console.log('rootPath', rootPath);
try {
const projectInfo = toml.parse(
fs.readFileSync(path.join(rootPath, 'pyproject.toml'), 'utf8')
);
const backendInfo = {
version: process.env.NEXT_VERSION,
name: projectInfo.tool.poetry.name || 'LabelU',
build_time: new Date().toISOString(),
commit: process.env.GITHUB_SHA,
};
const code = `
(function () {
window.__backend = ${JSON.stringify(backendInfo, null, 2)};
})();
`;
fs.writeFileSync(
path.join(rootPath, 'labelu/internal/statics/backend_version.js'),
code,
'utf-8'
);
console.log('Update backend_version.js success!');
} catch (e) {
console.error(e);
process.exit(1);
}
- uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install dependencies
run: poetry install --without dev
- name: Run tests
run: poetry run pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: ./coverage.xml
verbose: true
- name: Manage version
run: |
sed -i "s/^version[ ]*=.*/version = '${NEXT_VERSION}'/" pyproject.toml
- name: Publish to TestPyPi
if: ${{ github.ref_name == 'alpha'}}
env:
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }}
run: |
poetry config pypi-token.testpypi $TEST_PYPI_TOKEN
poetry publish --build --skip-existing -r testpypi
- name: Publish to PyPi
if: ${{ github.ref_name == 'main'}}
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build --skip-existing
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/commit-analyzer
@semantic-release/release-notes-generator
@semantic-release/exec
@semantic-release/github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ====================== post release ======================
- name: Send release notification
env:
CHANGELOG: ${{ github.event.inputs.changelog != '' && format('## Frontend changelog👇🏻 \n\n{0}\n\n\n', github.event.inputs.changelog) || '' }}
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
RELEASE_NOTES: ${{ env.RELEASE_NOTES }}
NEXT_VERSION: ${{ env.NEXT_VERSION }}
PYPI_URL: ${{ env.PYPI_URL }}
run: |
node ./scripts/release-notification.js