-
Notifications
You must be signed in to change notification settings - Fork 21
54 lines (48 loc) · 1.72 KB
/
publish_to_pypi.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
name: publish-to-pypi
on:
push:
branches:
- main
jobs:
publish-to-pypi:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Install dependencies
run: npm install @iarna/toml
- name: Check for version changes
id: check_version
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const execSync = require('child_process').execSync;
const toml = require('@iarna/toml');
const current = fs.readFileSync('pyproject.toml', 'utf8');
execSync('git checkout HEAD^1 pyproject.toml');
const previous = fs.readFileSync('pyproject.toml', 'utf8');
execSync('git checkout HEAD pyproject.toml');
const currentVersion = toml.parse(current).tool.poetry.version;
const previousVersion = toml.parse(previous).tool.poetry.version;
const versionChanged = currentVersion !== previousVersion;
if (versionChanged) {
console.log(`version changed from ${previousVersion} to ${currentVersion}`);
return currentVersion;
} else {
console.log(`version did not change from ${previousVersion}`);
}
- name: Install Poetry
if: ${{ steps.check_version.outputs.result }}
uses: snok/install-poetry@v1
with:
version: 1.5.1
- name: Build and publish
if: ${{ steps.check_version.outputs.result }}
run: |
echo "Building version ${{ steps.check_version.outputs.result }} ..."
poetry build
echo "Publishing ..."
poetry publish --username __token__ --password ${{ secrets.PYPI_TOKEN }}