-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (174 loc) · 7.19 KB
/
release.yml
File metadata and controls
206 lines (174 loc) · 7.19 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: release
concurrency: release
env:
PYTHON_VERSION_BUMP: 3.8
PYTHON_VERSION_RELEASE: 3.8
on:
pull_request_target:
branches: [main, develop]
types: [closed]
jobs:
bump-version:
if:
| # skip if: trying to re-run; PR is closed without merging; '[skip release]' is in the PR title; or if merging any branch other than pre_release_branch into release_branch
(
github.run_attempt == '1'
&& github.event.pull_request.merged
&& ! contains(github.event.pull_request.title, '[skip release]')
&& (
github.event.pull_request.base.ref == 'develop' || (
github.event.pull_request.base.ref == 'main'
&& github.event.pull_request.head.ref == 'develop'
)
)
)
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
new_tag_name: ${{ steps.get_new_tag.outputs.new_tag_name }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # get all history and tags
ref: ${{ github.event.pull_request.base.ref }}
token: ${{ secrets.LIGHTFORM_ACTIONS_TOKEN }}
- run: |
git config user.name lightform-bot
git config user.email lightform-bot@users.noreply.github.com
- uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION_BUMP }}
- name: Get git-chglog executable
run: |
wget https://github.com/git-chglog/git-chglog/releases/download/v0.15.0/git-chglog_0.15.0_linux_amd64.tar.gz
tar --extract --file git-chglog_0.15.0_linux_amd64.tar.gz git-chglog
- name: Install commitizen
run: pip install commitizen
- name: Manipulate tags (stable release)
if: github.event.pull_request.base.ref == 'main'
run:
| # delete all pre-release tags, set current version to the latest stable release
CUR_PRE_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "CUR_PRE_TAG is: $CUR_PRE_TAG"
echo "cur_pre_tag=$CUR_PRE_TAG" >> $GITHUB_ENV
git tag -l | awk '/^(v[0-9]+\.[0-9]+\.[0-9]+(a|b|rc).*)$/ {print $1}' | xargs git tag -d
- name: Get current tag
run: |
CUR_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "CUR_TAG is: $CUR_TAG"
echo "cur_tag=$CUR_TAG" >> $GITHUB_ENV
- name: Commitizen bump (pre-release) # Bump version strings (pre-release) and add a new tag; commit
if: github.event.pull_request.base.ref == 'develop'
run: cz bump --prerelease alpha
- name: Commitizen bump # First update version number to latest stable release, then bump to new stable release, add a new tag and commit
if: github.event.pull_request.base.ref == 'main'
run: |
python3 -c "
from commitizen.bump import update_version_in_files
update_version_in_files(
current_version='${{ env.cur_pre_tag }}'.lstrip('v'),
new_version='${{ env.cur_tag }}'.lstrip('v'),
files=['pyproject.toml', 'cipher_parse/_version.py'],
)"
cz bump
- name: Get new tag
id: get_new_tag
run: |
NEW_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "NEW_TAG is: $NEW_TAG"
echo "new_tag=$NEW_TAG" >> $GITHUB_ENV
echo "::set-output name=new_tag_name::$NEW_TAG"
- name: Write requirements.txt for binder
run: |
new_tag=${{ env.new_tag }}
new_version="${new_tag:1}"
echo "cipher-parse==${new_version}" > .binder/requirements.txt
git add .binder/requirements.txt
- name: Generate CHANGELOG (stable release)
if: github.event.pull_request.base.ref == 'main'
run: |
./git-chglog --output CHANGELOG.md
git add CHANGELOG.md
- name: Generate CHANGELOG-dev (pre-release)
if: github.event.pull_request.base.ref == 'develop'
run: |
./git-chglog --output CHANGELOG-dev.md
git add CHANGELOG-dev.md
- name: Push new CHANGELOG
run: |
git tag -d ${{ env.new_tag }}
git commit --amend --no-edit
git tag ${{ env.new_tag }}
git push && git push origin ${{ env.new_tag }}
- name: Rebase into develop branch if exists (stable release)
if: github.event.pull_request.base.ref == 'main'
run: |
exists_in_remote=$(git ls-remote --heads origin refs/heads/develop)
echo "exists_in_remote: $exists_in_remote"
if [[ -n $exists_in_remote ]]; then
export SKIP=end-of-file-fixer
git checkout develop
git pull
git rebase main
git push -u origin develop
else
echo "No develop branch to merge into."
fi
- name: Generate incremental CHANGELOG for GitHub release body (stable release)
if: github.event.pull_request.base.ref == 'main'
run: |
./git-chglog --template .chglog/RELEASE.tpl.md --output CHANGELOG_increment.md ${{ env.cur_tag }}..
cat CHANGELOG_increment.md
- name: Generate incremental CHANGELOG for GitHub release body (pre-release)
if: github.event.pull_request.base.ref == 'develop'
run: |
./git-chglog --template .chglog/RELEASE.tpl.md --output CHANGELOG_increment.md ${{ env.new_tag }}
cat CHANGELOG_increment.md
- uses: actions/upload-artifact@v6
with:
name: CHANGELOG_increment
path: CHANGELOG_increment.md
release-github-PyPI:
needs: [bump-version]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.ref }} # otherwise we get the ref when the workflow started (missing above commit)
- uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION_RELEASE }}
- name: Cache the virtualenv
uses: actions/cache@v5
with:
path: ./.venv
key: venv-release-${{ hashFiles('**/poetry.lock') }}
- name: Install poetry
run: python -m pip install poetry
- name: Configure poetry
run: |
poetry config virtualenvs.in-project true
poetry config installer.modern-installation false
- name: Install dependencies
run: poetry install
- name: Build (for PyPI)
run: poetry build
- run: mkdir release-artifacts
- uses: actions/download-artifact@v7
with:
path: release-artifacts
- name: Display structure of downloaded files
run: ls -R
- name: Release
id: release
uses: softprops/action-gh-release@v2
with:
body_path: release-artifacts/CHANGELOG_increment/CHANGELOG_increment.md
tag_name: ${{ needs.bump-version.outputs.new_tag_name }}
prerelease: ${{ github.event.pull_request.base.ref == 'develop' }}
- name: Publish (to https://upload.pypi.org/legacy/)
run: |
poetry config repositories.pypi https://upload.pypi.org/legacy/
poetry config pypi-token.pypi ${{ secrets.PYPI_CIPHER_PARSE }}
poetry publish --repository pypi