@@ -3,34 +3,26 @@ name: "CD"
33on :
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
1015jobs :
1116 release :
1217 name : " Release"
18+ if : ${{ github.ref == 'refs/heads/master' }}
1319 runs-on : ubuntu-latest
1420 steps :
1521 - name : " Checkout code"
1622 uses : actions/checkout@v2
1723 with :
1824 token : ${{ secrets.GH_PAT }}
1925
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-
3426 - name : " Set up Python"
3527 id : setup-python
3628 uses : actions/setup-python@v2
4335 virtualenvs-create : true
4436 virtualenvs-in-project : true
4537
38+ - name : " Bump pyproject.toml to new version"
39+ id : bump
40+ run : |
41+ poetry version ${{ github.event.inputs.release-type }}
42+ echo "::set-output name=version::$(poetry version --short)"
43+
44+ - name : " Bump apilytics.__version__ to new version"
45+ run : sed -i 's/^__version__ *=.*/__version__ = "${{ steps.bump.outputs.version }}"/' apilytics/__init__.py
46+
4647 - name : " Build the wheel"
4748 run : poetry build
4849
@@ -51,17 +52,29 @@ jobs:
5152 env :
5253 POETRY_PYPI_TOKEN_PYPI : ${{ secrets.PYPI_TOKEN }}
5354
55+ - name : " Update the changelog"
56+ # Find the first line that starts with `###` or `## [<number>` from the CHANGELOG and insert the new version header before it.
57+ run : |
58+ current_date="$(date -u '+%Y-%m-%d')"
59+ sed -i "0,/^\(###\|## *\[[0-9]\).*/{s//## [${{ steps.bump.outputs.version }}] - ${current_date}\n\n&/}" CHANGELOG.md
60+
61+ - name : " Extract version's changelog for release notes"
62+ # 1. Find the lines between the first `## [<number>` and the second `## [<number>`.
63+ # 2. Remove all leading and trailing newlines from the output.
64+ run : sed '1,/^## *\[[0-9]/d;/^## *\[[0-9]/Q' CHANGELOG.md | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.txt
65+
5466 - name : " Commit and tag the changes"
5567 uses : EndBug/add-and-commit@8c12ff729a98cfbcd3fe38b49f55eceb98a5ec02 # v7.5.0
5668 with :
57- add : ' ["pyproject.toml", "CHANGELOG.md"]'
58- message : ' Release ${{ github.event.inputs .version }}'
59- tag : ' v${{ github.event.inputs .version }} --annotate --file <(true) '
69+ add : ' ["pyproject.toml", "apilytics/__init__.py", " CHANGELOG.md"]'
70+ message : ' Release ${{ steps.bump.outputs .version }}'
71+ tag : ' v${{ steps.bump.outputs .version }} --annotate --file /dev/null '
6072 default_author : github_actions
73+ pathspec_error_handling : exitImmediately
6174
6275 - name : " Create a GitHub release"
6376 uses : softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1
6477 with :
65- tag_name : v${{ github.event.inputs .version }}
66- name : v${{ github.event.inputs .version }}
78+ tag_name : v${{ steps.bump.outputs .version }}
79+ name : v${{ steps.bump.outputs .version }}
6780 body_path : release_notes.txt
0 commit comments