-
Notifications
You must be signed in to change notification settings - Fork 3
129 lines (106 loc) · 3.53 KB
/
release.yml
File metadata and controls
129 lines (106 loc) · 3.53 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out develop
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: poetry install --all-extras
- name: Run tests
env:
FLASHPOINT_API_KEY: dummy
IPQS_API_KEY: dummy
SPYCLOUD_API_ATO_KEY: dummy
TWILIO_API_SID: dummy
TWILIO_API_SECRET: dummy
URLSCAN_API_KEY: dummy
PYTHONPATH: .
run: poetry run pytest --ignore=dev_env
- name: Bump version
id: bump
run: |
python3 << 'PYEOF'
import re, os
bump_type = "${{ inputs.bump }}"
with open("pyproject.toml", "r") as f:
content = f.read()
match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE)
major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3))
if bump_type == "major":
major, minor, patch = major + 1, 0, 0
elif bump_type == "minor":
minor, patch = minor + 1, 0
else:
patch += 1
new_version = f"{major}.{minor}.{patch}"
content = re.sub(
r'^(version\s*=\s*")(\d+\.\d+\.\d+)(")',
rf"\g<1>{new_version}\g<3>",
content,
count=1,
flags=re.MULTILINE,
)
with open("pyproject.toml", "w") as f:
f.write(content)
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"new_version={new_version}\n")
print(f"Bumped version to {new_version}")
PYEOF
- name: Commit version bump to develop
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
git remote set-url origin "https://x-access-token:${RELEASE_TOKEN}@github.com/${{ github.repository }}.git"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "ci: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
git push origin develop
- name: Merge develop into main
run: |
git checkout main
git merge --ff-only develop
git push origin main
- name: Create tag
run: |
git tag "v${{ steps.bump.outputs.new_version }}"
git push origin "v${{ steps.bump.outputs.new_version }}"
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: "v${{ steps.bump.outputs.new_version }}"
generate_release_notes: true
- name: Build package
run: poetry build
- name: Publish to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_PUBLISH }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish