-
Notifications
You must be signed in to change notification settings - Fork 97
149 lines (139 loc) · 5.08 KB
/
cicd_pipeline.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
name: "DEV CI/CD Pipeline"
on:
push:
branches:
- dev
workflow_dispatch:
inputs:
branch:
description: 'Frontend branch'
required: true
default: 'release'
type: choice
options:
- release
- alpha
version:
description: 'Current frontend version'
required: true
type: string
name:
description: 'Frontend app name'
required: false
assets_url:
description: 'Frontend assets url'
required: true
type: string
changelog:
description: 'Frontend changelog'
required: false
type: string
jobs:
test:
strategy:
fail-fast: false
matrix:
python-version: [3.7]
poetry-version: ["1.2.2"]
node-version: [16]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Resolve frontend
run: |
sh ./scripts/resolve_frontend.sh alpha $FRONTEND_VERSION $FRONTEND_ASSET_URL
echo "PROVIDED_VERSION=0.7.${{ github.run_number }}" >> $GITHUB_ENV
env:
FRONTEND_VERSION: ${{ inputs.version }}
FRONTEND_ASSET_URL: ${{ inputs.assets_url }}
CURRENT_BRANCH: ${{ github.head_ref || github.ref_name }}
- name: Inject backend info into frontend
uses: satackey/[email protected]
id: InjectBackend
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.PROVIDED_VERSION || projectInfo.tool.poetry.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 = '${PROVIDED_VERSION}'/" pyproject.toml
- name: Publish
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: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: https://docker.shlab.tech
username: ${{ secrets.ALI_DOCKERHUB_USERNAME }}
password: ${{ secrets.ALI_DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: docker.shlab.tech/public/labelu:0.7.${{ github.run_number }}-dev
- name: Commit .VERSION pyproject.toml files to current branch
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Update .VERSION and pyproject.toml [skip ci]"
file_pattern: '.VERSION pyproject.toml'
- name: Webhook message
uses: joelwmale/webhook-action@master
with:
url: ${{ secrets.WEBHOOK_URL }}
headers: '{"Content-Type": "application/json"}'
body: '{"msgtype":"markdown","markdown":{"content":"# LabelU@${{ env.PROVIDED_VERSION }}(test) is Released 🎉\n \nCheck it out now \ud83d\udc49\ud83c\udffb [v${{ env.PROVIDED_VERSION }}](https://test.pypi.org/project/labelu/#files) \n \n ## Changelog \n \n${{ inputs.changelog || github.event.head_commit.message }}"}}'