-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (124 loc) · 5.45 KB
/
release.yml
File metadata and controls
149 lines (124 loc) · 5.45 KB
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: Release
on:
workflow_dispatch:
inputs:
deployment-env:
type: choice
description: 'Deployment environment'
required: true
options:
- test.pypi.org
- pypi.org
default: 'test.pypi.org'
jobs:
release:
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing to pypi.org and test.pypi.org
contents: write # needed for the softprops/action-gh-release GitHub release step
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DISY_RELEASE_APP_ID }}
private-key: ${{ secrets.DISY_RELEASE_APP_SECRET }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ vars.PYTHON_VERSION }}
# poetry is needed for building and for poetry-bumpversion for version management
- name: Install poetry
run: |
pipx install poetry
poetry self add poetry-bumpversion
# install dependencies early in case there are problems, do not build yet, or we will have a dist with wrong version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
# Needed for creating the tag
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# either bump release or pre-release version, depending on user input
- name: Prepare package version (e.g. 1.2.3a0.dev0 => 1.2.3a0) FOR TEST (!) pre-release
if: "${{ github.event.inputs.deployment-env == 'test.pypi.org' }}"
run: |
poetry version "$(poetry version -s | head -n 1 | sed 's/\.dev[0-9]*$//')"
RELEASE_VERSION=$(poetry version -s) && echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- name: Prepare package version (e.g. 1.2.3.dev0 => 1.2.3, 1.2.3a0.dev0 => 1.2.3) for release
if: "${{ github.event.inputs.deployment-env == 'pypi.org' }}"
run: |
echo "RELEASE_VERSION=$(poetry version patch -s | head -n 1)" >> $GITHUB_ENV
# Create a dist/wheel for the bumped version now after "poetry version" has run
- name: Build
run: |
poetry build
# either push to test.pypi.org or pypi.org, depending on user input
- name: Publish package distributions TO TEST (!) PyPI
if: "${{ github.event.inputs.deployment-env == 'test.pypi.org' }}"
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Publish package distributions to PyPI
if: "${{ github.event.inputs.deployment-env == 'pypi.org' }}"
uses: pypa/gh-action-pypi-publish@release/v1
- name: Update changelog, only for proper release
if: "${{ github.event.inputs.deployment-env == 'pypi.org' }}"
uses: superfaceai/release-changelog-action@v2
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.RELEASE_VERSION }}
operation: release
- name: Commit and tag changes without changelog FOR TEST (!) prerelease
if: "${{ github.event.inputs.deployment-env == 'test.pypi.org' }}"
run: |
git add "pyproject.toml"
git commit -m "Chore: pre-release ${{ env.RELEASE_VERSION }}"
git tag ${{ env.RELEASE_VERSION }}
- name: Commit and tag changes
if: "${{ github.event.inputs.deployment-env == 'pypi.org' }}"
run: |
git add "pyproject.toml"
git add "CHANGELOG.md"
git commit -m "Chore: release ${{ env.RELEASE_VERSION }}"
git tag ${{ env.RELEASE_VERSION }}
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push origin && git push --tags
- id: get-changelog
if: "${{ github.event.inputs.deployment-env == 'pypi.org' }}"
name: Get version changelog
uses: superfaceai/release-changelog-action@v2
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.RELEASE_VERSION }}
operation: read
- name: Update GitHub release documentation
if: "${{ github.event.inputs.deployment-env == 'pypi.org' }}"
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.RELEASE_VERSION }}
body: ${{ steps.get-changelog.outputs.changelog }}
env:
# Use app token to ensure the release event triggers other workflows (e.g., docs.yml)
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Bump package version to new prerelease dev version (e.g. 1.2.3 => 1.2.4a0.dev0, 1.2.3a0 => 1.2.3a1.dev0)
run: |
poetry version "$(poetry version prerelease --dry-run -s | head -n 1).dev0"
DEV_VERSION=$(poetry version -s) && echo "DEV_VERSION=$DEV_VERSION" >> $GITHUB_ENV # Determine DEV_VERSION
- name: Commit version bump (push happens later)
run: |
git add "pyproject.toml"
git commit -m "Chore: bump up version to ${{ env.DEV_VERSION }}"
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push origin