Skip to content

Commit f0b47b1

Browse files
authored
chore: update workflows to create release (#198)
1 parent 93ba24d commit f0b47b1

File tree

6 files changed

+229
-212
lines changed

6 files changed

+229
-212
lines changed

.github/release-drafter.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name-template: '$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
categories:
4+
- title: 'Bug Fixes'
5+
labels:
6+
- 'P: bug'
7+
- 'V: patch'
8+
- title: '🚀Features'
9+
labels:
10+
- 'P: enhancement'
11+
- 'V: minor'
12+
- title: 'Maintenance'
13+
labels:
14+
- 'chore'
15+
change-template: '- [#$NUMBER] $TITLE (@$AUTHOR)'
16+
change-title-escapes: '\<*_&'
17+
version-resolver:
18+
major:
19+
labels:
20+
- 'V: major'
21+
minor:
22+
labels:
23+
- 'V: minor'
24+
patch:
25+
labels:
26+
- 'V: patch'
27+
default: patch
28+
exclude-labels:
29+
- 'dependencies'
30+
- 'fresh'
31+
- 'help wanted'
32+
- 'question'
33+
- 'release'
34+
- 'C: convention'
35+
- 'C: stakeholder'
36+
- 'C: style'
37+
- 'S: duplicate'
38+
- 'S: feedback'
39+
- 'S: invalid'
40+
- 'S: merged'
41+
- 'S: wontfix'
42+
template: |
43+
## What Changed
44+
45+
$CHANGES

.github/workflows/do-release.yml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# This workflow runs when a pull request is closed.
2+
#
3+
# - Gets list of PR labels.
4+
# - If 'release' label:
5+
# - Get release version using Poetry.
6+
# - Generate new CHANGELOG.
7+
# - Tag repository with new version tag.
8+
# - Build the release.
9+
# - Draft a new GitHub release.
10+
# - Upload the wheel to the new GitHub release.
11+
# - Upload wheel to Test PyPi if build succeeds. (Future)
12+
# - Test install from Test PyPi. (Future)
13+
# - Upload wheel to PyPi if test install succeeds. (Future)
14+
name: Do Release Workflow
15+
16+
on:
17+
pull_request:
18+
branches:
19+
- master
20+
types:
21+
- closed
22+
23+
jobs:
24+
create_new_release:
25+
name: Create New Release
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Get PR labels
33+
id: prlabels
34+
uses: joerick/pr-labels-action@v1.0.8
35+
36+
- name: Get release version
37+
id: relversion
38+
if: contains(steps.prlabels.outputs.labels, ' release ')
39+
run: |
40+
pip install poetry
41+
echo "version=$(echo $(poetry version | cut -d' ' -f2))" >> $GITHUB_OUTPUT
42+
echo "do_release=1" >> $GITHUB_ENV
43+
44+
- name: Generate release changelog
45+
uses: heinrichreimer/github-changelog-generator-action@master
46+
if: ${{ env.do_release == 1 }}
47+
with:
48+
token: ${{ secrets.GITHUB_TOKEN }}
49+
sinceTag: "v1.3.1"
50+
excludeTags: "latest"
51+
breakingLabel: "Breaking Changes"
52+
breakingLabels: "V: major"
53+
enhancementLabel: "New Features"
54+
enhancementLabels: "P: enhancement"
55+
bugsLabel: "Bug Fixes"
56+
bugLabels: "P: bug"
57+
excludeLabels: "release"
58+
issues: false
59+
issuesWoLabels: false
60+
maxIssues: 100
61+
pullRequests: true
62+
prWoLabels: false
63+
author: true
64+
unreleased: true
65+
compareLink: true
66+
stripGeneratorNotice: true
67+
verbose: true
68+
69+
- name: Check if diff
70+
continue-on-error: true
71+
run: >
72+
git diff --exit-code CHANGELOG.md &&
73+
(echo "### No update" && exit 1) || (echo "### Commit update")
74+
75+
- uses: EndBug/add-and-commit@v9
76+
name: Commit and push if diff
77+
if: success()
78+
with:
79+
add: CHANGELOG.md
80+
message: 'chore: update CHANGELOG.md for new release'
81+
author_name: GitHub Actions
82+
author_email: action@github.com
83+
committer_name: GitHub Actions
84+
committer_email: actions@github.com
85+
push: true
86+
87+
- name: Build release
88+
id: build
89+
if: ${{ env.do_release == 1 }}
90+
run: |
91+
pip install -U pip poetry twine
92+
poetry build && twine check dist/* && echo "build_ok=1" >> $GITHUB_ENV
93+
94+
- name: Cut the release
95+
id: cutrelease
96+
if: ${{ env.build_ok == 1 }}
97+
uses: release-drafter/release-drafter@v5
98+
with:
99+
name: "${{ steps.newversion.outputs.new_tag }}"
100+
tag: "${{ steps.newversion.outputs.new_tag }}"
101+
version: "${{ steps.newversion.outputs.new_tag }}"
102+
prerelease: false
103+
publish: true
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
107+
- name: Print release info
108+
run: |
109+
echo ${{ steps.cutrelease.outputs.id }}
110+
echo ${{ steps.cutrelease.outputs.name }}
111+
echo ${{ steps.cutrelease.outputs.tag_name }}
112+
echo ${{ steps.cutrelease.outputs.html_url }}
113+
echo ${{ steps.cutrelease.outputs.upload_url }}
114+
115+
- name: Upload wheel to GitHub release
116+
id: upload-wheel
117+
if: ${{ env.build_ok == 1 }}
118+
uses: shogo82148/actions-upload-release-asset@v1
119+
with:
120+
upload_url: ${{ steps.cutrelease.outputs.upload_url }}
121+
122+
# - name: Publish to Test PyPi
123+
# if: ${{ env.build_ok == 1 }}
124+
# uses: pypa/gh-action-pypi-publish@release/v1
125+
# with:
126+
# user: __token__
127+
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
128+
# repository_url: https://test.pypi.org/legacy/
129+
130+
# - name: Test install from Test PyPI
131+
# if: ${{ env.build_ok == 1 }}
132+
# run: |
133+
# sudo apt-get update
134+
# pip install \
135+
# --index-url https://test.pypi.org/simple/ \
136+
# --extra-index-url https://pypi.org/simple \
137+
# docformatter==${{ steps.newversion.outputs.new_version }} && echo "install_ok=1" >> $GITHUB_ENV
138+
139+
# - name: Publish to PyPi
140+
# if: ${{ env.install_ok == 1 }}
141+
# uses: pypa/gh-action-pypi-publish@release/v1
142+
# with:
143+
# user: __token__
144+
# password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/do-update-authors.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ jobs:
5050
5151
file_head = (
5252
".. This file is automatically generated/updated by a github actions workflow.\n"
53-
".. Every manual change will be overwritten on push to main.\n"
54-
".. You can find it here: ``.github/workflows/do-update-authors.yaml``\n\n"
53+
".. Every manual change will be overwritten on push to master.\n"
54+
".. You can find it here: ``.github/workflows/do-update-authors.yml``\n\n"
5555
"Author\n"
5656
"------\n"
5757
"Steven Myint <git@stevenmyint.com>\n\n"

.github/workflows/on-push-tag.yml

Lines changed: 38 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
# This workflow runs when a version tag is pushed.
22
#
33
# - Get new tag.
4-
# - Build new release.
54
# - If release tag:
6-
# - Build release.
7-
# - Generate GitHub release if build succeeds.
8-
# - Upload wheel to GitHub release if build succeeds.
9-
# - Upload wheel to Test PyPi if build succeeds. (Future)
10-
# - Test install from Test PyPi. (Future)
11-
# - Upload wheel to PyPi if test install succeeds. (Future)
12-
name: Push Version Tag Workflow
5+
# - Get next semantic version.
6+
# - Close old milestones.
7+
# - Create new minor version milestone.
8+
# - Create new major version milestone.
9+
name: Version Tag Workflow
1310

1411
on:
1512
push:
1613
tags:
1714
- 'v*'
1815

1916
jobs:
20-
request-release:
21-
name: Request Release PR
17+
manage_milestones:
18+
name: Manage Milestones
2219
runs-on: ubuntu-latest
2320
steps:
2421
- name: Checkout repository
@@ -30,68 +27,42 @@ jobs:
3027
- name: Get new tag
3128
id: newversion
3229
run: |
33-
new_tag=${GITHUB_REF/refs\/tags\//}
34-
new_version=$(echo $new_tag | sed 's/.rc[0-9]*//')
35-
echo "new_tag=$(echo $new_tag)" >> $GITHUB_OUTPUT
36-
echo "new_version=$(echo $new_version)" >> $GITHUB_OUTPUT
37-
echo "New tag is: $new_tag"
38-
echo "New version is: $new_version"
30+
tag=${GITHUB_REF/refs\/tags\//}
31+
version=$(echo $new_tag | sed 's/.rc[0-9]*//')
32+
if [[ $tag != *"-rc"* ]]; then
33+
echo "do_milestones=1" >> $GITHUB_ENV
34+
echo "tag=$(echo $tag)" >> $GITHUB_OUTPUT
35+
echo "version=$(echo $version)" >> $GITHUB_OUTPUT
36+
fi
37+
echo "New tag is: $tag"
38+
echo "New version is: $version"
3939
echo "GitHub ref: ${{ github.ref }}"
4040
41-
- name: Build release
42-
id: build
43-
run: |
44-
pip install -U pip poetry twine
45-
poetry build && twine check dist/* && echo "build_ok=1" >> $GITHUB_ENV
41+
- name: Get next semantic version
42+
id: nextversion
43+
if: ${{ env.do_milestones == 1 }}
44+
uses: WyriHaximus/github-action-next-semvers@v1.2.1
45+
with:
46+
version: ${{ steps.newversion.outputs.version }}
47+
48+
- name: Close old milestone
49+
if: ${{ env.do_milestones == 1 }}
50+
uses: WyriHaximus/github-action-close-milestone@master
51+
with:
52+
number: ${{ steps.relversion.outputs.version }}
4653

47-
- name: Cut the release
48-
id: cutrelease
49-
if: ${{ !contains( steps.newversion.output.new_tag, 'rc' ) && env.build_ok == 1 }}
50-
uses: release-drafter/release-drafter@v5
54+
- name: Create new minor release milestone
55+
if: ${{ env.do_milestones == 1 }}
56+
uses: WyriHaximus/github-action-create-milestone@v1.2.0
5157
with:
52-
name: "v${{ steps.newversion.outputs.new_tag }}"
53-
tag: "v${{ steps.newversion.outputs.new_tag }}"
54-
version: "${{ steps.newversion.outputs.new_tag }}"
55-
prerelease: false
56-
publish: true
58+
title: "${{ steps.nextversion.outputs.v_minor }}"
5759
env:
5860
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5961

60-
- name: Print release info
61-
run: |
62-
echo ${{ steps.cutrelease.outputs.id }}
63-
echo ${{ steps.cutrelease.outputs.name }}
64-
echo ${{ steps.cutrelease.outputs.tag_name }}
65-
echo ${{ steps.cutrelease.outputs.html_url }}
66-
echo ${{ steps.cutrelease.outputs.upload_url }}
67-
68-
- name: Upload wheel to GitHub release
69-
id: upload-wheel
70-
if: ${{ env.build_ok == 1 }}
71-
uses: shogo82148/actions-upload-release-asset@v1
62+
- name: Create new major release milestone
63+
if: ${{ env.do_milestones == 1 }}
64+
uses: WyriHaximus/github-action-create-milestone@v1.2.0
7265
with:
73-
upload_url: ${{ steps.cutrelease.outputs.upload_url }}
74-
75-
# - name: Publish to Test PyPi
76-
# if: ${{ !contains( steps.newversion.output.new_tag, 'rc' ) && env.build_ok == 1 }}
77-
# uses: pypa/gh-action-pypi-publish@release/v1
78-
# with:
79-
# user: __token__
80-
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
81-
# repository_url: https://test.pypi.org/legacy/
82-
83-
# - name: Test install from Test PyPI
84-
# if: ${{ !contains( steps.newversion.output.new_tag, 'rc' ) && env.build_ok == 1 }}
85-
# run: |
86-
# sudo apt-get update
87-
# pip install \
88-
# --index-url https://test.pypi.org/simple/ \
89-
# --extra-index-url https://pypi.org/simple \
90-
# docformatter==${{ steps.newversion.outputs.new_version }} && echo "install_ok=1" >> $GITHUB_ENV
91-
92-
# - name: Publish to PyPi
93-
# if: ${{ !contains( steps.newversion.output.new_tag, 'rc' ) && env.install_ok == 1 }}
94-
# uses: pypa/gh-action-pypi-publish@release/v1
95-
# with:
96-
# user: __token__
97-
# password: ${{ secrets.PYPI_API_TOKEN }}
66+
title: "${{ steps.nextversion.outputs.v_major }}"
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)