-
Notifications
You must be signed in to change notification settings - Fork 9
104 lines (88 loc) · 3.15 KB
/
release.yaml
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
name: Publish to PyPI
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
default: 'patch'
type: choice
options:
- 'major'
- 'minor'
- 'patch'
repository:
description: 'Repository to publish to'
required: true
default: 'testpypi'
type: choice
options:
- 'pypi'
- 'testpypi'
permissions:
contents: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: '1.8.3'
- name: Install dependencies
run: poetry install
- name: Bump version
run: |
poetry run python handle_versioning.py ${{ github.event.inputs.version }}
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add pyproject.toml
git commit -m "Bump version to ${{ github.event.inputs.version }}"
git push
- name: Get merged PRs
id: pr_notes
run: |
last_tag = $(git describe --tags --abbrev=0 HEAD^)
if [ -z "$last_tag" ]; then
last_tag=$(git rev-list --max-parents=0 HEAD)
merged_prs=$(git log --oneline --merges --pretty=format:"* %s" $last_tag..HEAD | grep -i 'Merge pull request')
else
merged_prs="No previous tag found, this is the first release"
fi
echo "::set-output name=merged_prs::$merged_prs"
- name: Create tag
run: |
current_version=$( poetry run python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
git tag $current_version
git push origin $current_version
echo "::set-output name=version::$current_version"
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.outputs.version }}
release_name: Release ${{ github.event.outputs.version }}
body: |
Added Features:
${{github.events.outputs.merged_prs}}
draft: false
prerelease: false
- name: Build package
run: |
poetry build
- name: Publish to TestPyPI or PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ github.event.inputs.repository == 'pypi' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }}
username: __token__
password: ${{ github.event.inputs.repository == 'pypi' && secrets.PYPI_API_TOKEN || secrets.TEST_PYPI_API_TOKEN }}
env:
POETRY_PYPI_TOKEN: ${{ github.event.inputs.repository == 'pypi' && secrets.PYPI_POETRY_TOKEN || secrets.TEST_PYPI_POETRY_TOKEN }}