Skip to content

Commit ff73941

Browse files
committed
ci: add release workflow
1 parent f4970ba commit ff73941

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Next Version'
8+
required: true
9+
10+
env:
11+
python_version: '3.x'
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 10
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.release_token }}
24+
25+
- name: Set author in Git
26+
run: |
27+
git config user.name github-actions
28+
git config user.email [email protected]
29+
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: ${{ env.python_version }}
33+
34+
- name: Bump version
35+
run: |
36+
python .scripts/bump.py ${{ github.event.inputs.version }}
37+
git commit --message ${{ github.event.inputs.version }} setup.py
38+
git tag v${{ github.event.inputs.version }}
39+
40+
- name: Push release commit
41+
run: git push --tags origin ${{ github.ref_name }}
42+
43+
- uses: ncipollo/release-action@v1
44+
with:
45+
tag: v${{ github.event.inputs.version }}
46+
draft: true

.scripts/bump.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import re
2+
import sys
3+
from os import path
4+
5+
if len(sys.argv) < 2:
6+
raise Exception("Please provide a new version number:\n\tbump.py <VERSION>")
7+
8+
new_version = sys.argv[1]
9+
setup_file = path.realpath(path.join(path.dirname(__file__), "..", "setup.py"))
10+
11+
with open(setup_file, "r") as file:
12+
lines = file.readlines()
13+
14+
changed = False
15+
for i, line in enumerate(lines):
16+
if "version=" in line:
17+
line = re.sub(r'"[^"]+"', '"' + new_version + '"', line)
18+
if line != lines[i]:
19+
lines[i] = line
20+
changed = True
21+
22+
if changed:
23+
with open(setup_file, "w") as file:
24+
file.writelines(lines)
25+
print("setup.py changed to version: " + new_version)
26+
else:
27+
print("setup.py did not change")
28+
sys.exit(1)

0 commit comments

Comments
 (0)