-
Notifications
You must be signed in to change notification settings - Fork 61
174 lines (157 loc) · 5.62 KB
/
do-release.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
171
172
173
174
# This workflow runs when a pull request is closed.
#
# - Gets list of PR labels.
# - If 'release' label:
# - Get release version using Poetry.
# - Build the release.
# - Draft a new GitHub release.
# - Upload the wheel to the new GitHub release.
# - Upload wheel to Test PyPi if build succeeds. (Future)
# - Test install from Test PyPi. (Future)
# - Upload wheel to PyPi if install test succeeds. (Future)
# - Generate new CHANGELOG.
# - Get next semantic version.
# - Close old milestones.
# - Create new minor version milestone.
# - Create new major version milestone.
name: Do Release Workflow
on:
pull_request:
branches:
- master
types:
- closed
jobs:
create_new_release:
name: Create New Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get PR labels
id: prlabels
uses: joerick/pr-labels-action@v1.0.8
- name: Get release version
id: relversion
if: contains(steps.prlabels.outputs.labels, ' release ')
run: |
pip install poetry
echo "version=$(echo $(poetry version | cut -d' ' -f2))" >> $GITHUB_OUTPUT
if [[ $version != *"-rc"* ]]; then
echo "do_release=1" >> $GITHUB_ENV
echo "do_changelog=1" >> $GITHUB_ENV
echo "do_milestones=1" >> $GITHUB_ENV
fi
- name: Build release
id: build
if: ${{ env.do_release == 1 }}
run: |
pip install -U pip poetry twine
poetry build && twine check dist/* && echo "build_ok=1" >> $GITHUB_ENV
- name: Cut the release
id: cutrelease
if: ${{ env.build_ok == 1 }}
uses: release-drafter/release-drafter@v5
with:
name: "${{ steps.relversion.outputs.new_tag }}"
tag: "${{ steps.relversion.outputs.new_tag }}"
version: "${{ steps.relversion.outputs.new_tag }}"
prerelease: false
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload wheel to GitHub release
id: upload-wheel
if: ${{ env.build_ok == 1 }}
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.cutrelease.outputs.upload_url }}
asset_path: ./dist/*.whl
# - name: Publish to Test PyPi
# if: ${{ env.build_ok == 1 }}
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# user: __token__
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
# - name: Test install from Test PyPI
# if: ${{ env.build_ok == 1 }}
# run: |
# sudo apt-get update
# pip install \
# --index-url https://test.pypi.org/simple/ \
# --extra-index-url https://pypi.org/simple \
# docformatter==${{ steps.newversion.outputs.new_version }} && echo "install_ok=1" >> $GITHUB_ENV
# - name: Publish to PyPi
# if: ${{ env.install_ok == 1 }}
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
- name: Generate release changelog
uses: heinrichreimer/github-changelog-generator-action@master
if: ${{ env.do_changelog == 1 }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
sinceTag: "v1.3.1"
excludeTagsRegex: "-rc[0-9]"
breakingLabel: "Breaking Changes"
breakingLabels: "V: major"
enhancementLabel: "Features"
enhancementLabels: "P: enhancement"
bugsLabel: "Bug Fixes"
bugLabels: "P: bug"
excludeLabels: "release"
issues: false
issuesWoLabels: false
maxIssues: 100
pullRequests: true
prWoLabels: false
author: true
unreleased: true
compareLink: true
stripGeneratorNotice: true
verbose: true
- name: Check if diff
if: ${{ env.do_changelog == 1 }}
continue-on-error: true
run: >
git diff --exit-code CHANGELOG.md &&
(echo "### No update" && exit 1) || (echo "### Commit update")
- uses: EndBug/add-and-commit@v9
name: Commit and push if diff
if: ${{ env.do_changelog == 1 }}
with:
add: CHANGELOG.md
message: 'chore: update CHANGELOG.md for new release'
author_name: GitHub Actions
author_email: action@github.com
committer_name: GitHub Actions
committer_email: actions@github.com
push: true
- name: Get next semantic version
id: nextversion
if: ${{ env.do_milestones == 1 }}
uses: WyriHaximus/github-action-next-semvers@v1.2.1
with:
version: ${{ steps.relversion.outputs.version }}
- name: Close old milestone
if: ${{ env.do_milestones == 1 }}
uses: WyriHaximus/github-action-close-milestone@master
with:
number: ${{ steps.relversion.outputs.version }}
- name: Create new minor release milestone
if: ${{ env.do_milestones == 1 }}
uses: WyriHaximus/github-action-create-milestone@v1.2.0
with:
title: "${{ steps.nextversion.outputs.v_minor }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create new major release milestone
if: ${{ env.do_milestones == 1 }}
uses: WyriHaximus/github-action-create-milestone@v1.2.0
with:
title: "${{ steps.nextversion.outputs.v_major }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}