-
Notifications
You must be signed in to change notification settings - Fork 4
170 lines (143 loc) · 4.49 KB
/
cd.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
---
name: CD
env:
PYTHON_VERSION: 3.8
POETRY_VERSION: 1.2.2
NODE_VERSION: 16
DOCKER_IMAGE: metaphordata/connectors
permissions:
contents: read
# Run this build workflow after a new PR is merged
on:
push:
branches: [main]
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
version:
name: Get version
runs-on: ubuntu-latest
outputs:
full: ${{ steps.get-version.outputs.full }}
major: ${{ steps.get-version.outputs.major }}
minor: ${{ steps.get-version.outputs.minor }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm install toml
- id: get-version
name: Get version
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const toml = require('toml');
const pyproject = toml.parse(fs.readFileSync('pyproject.toml'));
const version = pyproject.tool.poetry.version;
core.setOutput('full', version);
core.setOutput('major', version.split('.').slice(0, 1).join('.'));
core.setOutput('minor', version.split('.').slice(0, 2).join('.'));
publish-coverage:
name: Publish coverage stats
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup Poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Setup dev libs
run: |
sudo apt-get install libsasl2-dev
- name: Test
run: |
poetry install -E all
poetry run coverage run --source=metaphor -m pytest
poetry run coverage xml
- name: Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: version
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup Poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Publish to PyPI
run: >
poetry publish --build --skip-existing
-u ${{ secrets.PYPI_USERNAME }}
-p ${{ secrets.PYPI_PASSWORD }}
- name: Create tag
uses: actions/github-script@v5
with:
github-token: ${{ github.token }}
script: |
const version = '${{ needs.version.outputs.full }}';
core.notice(`Tagging ${{ github.sha }} as ${version}`);
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${ version }`
});
} catch (err) {}
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${ version }`,
sha: "${{ github.sha }}"
})
docker:
name: Publish to Docker
runs-on: ubuntu-latest
needs: version
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Check existing version
id: check
continue-on-error: true
run: docker manifest inspect ${{ env.DOCKER_IMAGE }}:${{ needs.version.outputs.full }} > /dev/null
- name: Build Docker image
if: steps.check.outcome == 'failure'
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ needs.version.outputs.full }}
${{ env.DOCKER_IMAGE }}:${{ needs.version.outputs.major }}
${{ env.DOCKER_IMAGE }}:${{ needs.version.outputs.minor }}