Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 4f848b4

Browse files
committed
Allow choosing just the type of release in CD workflow
Makes it more convenient and avoids typos in the inputted version number.
1 parent 6856fa9 commit 4f848b4

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

.github/workflows/cd.yml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ name: "CD"
33
on:
44
workflow_dispatch:
55
inputs:
6-
version:
7-
description: "Version of the release, e.g. 1.0.0"
6+
release-type:
7+
description: "Type of release?"
88
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
914

1015
jobs:
1116
release:
@@ -17,20 +22,6 @@ jobs:
1722
with:
1823
token: ${{ secrets.GH_PAT }}
1924

20-
- name: "Update the changelog"
21-
# Find the first line that starts with `###` or `## [<number>` from the CHANGELOG and insert the new version header before it.
22-
run: >
23-
current_date="$(date '+%Y-%m-%d')"
24-
&& sed -i "0,/^\(###\|## *\[[0-9]\).*/{s//## [${{ github.event.inputs.version }}] - ${current_date}\n\n&/}" CHANGELOG.md
25-
26-
- name: "Bump pyproject.toml to new version"
27-
run: sed -i 's/^version *=.*/version = "${{ github.event.inputs.version }}"/' pyproject.toml
28-
29-
- name: "Extract version's changelog for release notes and tag message"
30-
# 1. Find the lines between the first `## [<number>` and the second `## [<number>`.
31-
# 2. Remove all leading and trailing newlines from the output.
32-
run: sed '1,/^## *\[[0-9]/d;/^## *\[[0-9]/Q' CHANGELOG.md | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.txt
33-
3425
- name: "Set up Python"
3526
id: setup-python
3627
uses: actions/setup-python@v2
@@ -43,6 +34,12 @@ jobs:
4334
virtualenvs-create: true
4435
virtualenvs-in-project: true
4536

37+
- name: "Bump pyproject.toml to new version"
38+
id: bump
39+
run: |
40+
poetry version ${{ github.event.inputs.release-type }}
41+
echo "::set-output name=version::$(poetry version --short)"
42+
4643
- name: "Build the wheel"
4744
run: poetry build
4845

@@ -51,17 +48,28 @@ jobs:
5148
env:
5249
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
5350

51+
- name: "Update the changelog"
52+
# Find the first line that starts with `###` or `## [<number>` from the CHANGELOG and insert the new version header before it.
53+
run: |
54+
current_date="$(date '+%Y-%m-%d')"
55+
sed -i "0,/^\(###\|## *\[[0-9]\).*/{s//## [${{ steps.bump.outputs.version }}] - ${current_date}\n\n&/}" CHANGELOG.md
56+
57+
- name: "Extract version's changelog for release notes and tag message"
58+
# 1. Find the lines between the first `## [<number>` and the second `## [<number>`.
59+
# 2. Remove all leading and trailing newlines from the output.
60+
run: sed '1,/^## *\[[0-9]/d;/^## *\[[0-9]/Q' CHANGELOG.md | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.txt
61+
5462
- name: "Commit and tag the changes"
5563
uses: EndBug/add-and-commit@8c12ff729a98cfbcd3fe38b49f55eceb98a5ec02 # v7.5.0
5664
with:
5765
add: '["pyproject.toml", "CHANGELOG.md"]'
58-
message: 'Release ${{ github.event.inputs.version }}'
59-
tag: 'v${{ github.event.inputs.version }} --annotate --file /dev/null'
66+
message: 'Release ${{ steps.bump.outputs.version }}'
67+
tag: 'v${{ steps.bump.outputs.version }} --annotate --file /dev/null'
6068
default_author: github_actions
6169

6270
- name: "Create a GitHub release"
6371
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1
6472
with:
65-
tag_name: v${{ github.event.inputs.version }}
66-
name: v${{ github.event.inputs.version }}
73+
tag_name: v${{ steps.bump.outputs.version }}
74+
name: v${{ steps.bump.outputs.version }}
6775
body_path: release_notes.txt

0 commit comments

Comments
 (0)