Skip to content

Commit f97fb15

Browse files
ci: add bump file (#670)
1 parent 4d3adbd commit f97fb15

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

.github/workflows/bump.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Bump
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump_type:
7+
description: 'Type of bump to perform'
8+
required: true
9+
default: 'beta'
10+
type: choice
11+
options:
12+
- beta
13+
- stable
14+
15+
jobs:
16+
check-and-bump:
17+
environment: production
18+
runs-on: ubuntu-24.04
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Check current commit
23+
run: |
24+
COMMIT_MSG=$(git log --format=%B -n 1)
25+
echo "Checking commit message: $COMMIT_MSG"
26+
if [[ $COMMIT_MSG == bump:* ]]; then
27+
echo "Current commit is a bump, skipping"
28+
exit 0
29+
fi
30+
31+
- name: Determine bump type
32+
id: bump-type
33+
run: |
34+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
35+
echo "type=${{ inputs.bump_type }}" >> $GITHUB_OUTPUT
36+
else
37+
echo "type=beta" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Set up Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: "3.12"
44+
45+
- name: Install hatch
46+
run: pip install hatch
47+
48+
- name: Configure Git
49+
run: |
50+
git config --global user.name 'safety-bot'
51+
git config --global user.email '[email protected]'
52+
53+
- name: Import GPG key
54+
uses: crazy-max/ghaction-import-gpg@v6
55+
with:
56+
gpg_private_key: ${{ secrets.SAFETY_BOT_GPG_KEY }}
57+
passphrase: ${{ secrets.SAFETY_BOT_GPG_PASSPHRASE }}
58+
git_config_global: true
59+
git_user_signingkey: true
60+
git_commit_gpgsign: true
61+
git_tag_gpgsign: true
62+
63+
- name: Get current version
64+
id: current-version
65+
run: |
66+
CURRENT_VERSION=$(hatch version)
67+
echo "version -> $CURRENT_VERSION"
68+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
69+
70+
if [[ $CURRENT_VERSION =~ .*b[0-9]+$ ]]; then
71+
echo "is_beta=true" >> $GITHUB_OUTPUT
72+
else
73+
echo "is_beta=false" >> $GITHUB_OUTPUT
74+
fi
75+
76+
- name: Perform version bump
77+
id: version-bump
78+
run: |
79+
if [ "${{ steps.bump-type.outputs.type }}" = "stable" ]; then
80+
COMMAND="hatch run bump"
81+
else
82+
# For beta, only proceed if current version is not beta
83+
if [ "${{ steps.current-version.outputs.is_beta }}" = "true" ]; then
84+
echo "Current version is already beta, skipping bump"
85+
echo "bumped=false" >> $GITHUB_OUTPUT
86+
exit 0
87+
fi
88+
COMMAND="hatch run beta-bump"
89+
fi
90+
91+
# Execute the command
92+
if $COMMAND; then
93+
echo "bumped=true" >> $GITHUB_OUTPUT
94+
else
95+
echo "bumped=false" >> $GITHUB_OUTPUT
96+
fi
97+
98+
- name: Push changes
99+
if: steps.version-bump.outputs.bumped == 'true'
100+
run: |
101+
git push --follow-tags

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ dependencies = [
124124

125125
# Common scripts used across environments
126126
[tool.hatch.envs.default.scripts]
127-
bump = "cz bump --check-consistency --yes && cz changelog --merge-prerelease"
128-
beta-bump = "cz bump -pr beta --check-consistency --yes && cz changelog --merge-prerelease"
127+
bump = "cz bump --check-consistency --yes --changelog --gpg-sign --annotated-tag --annotated-tag-message 'Version $(hatch version)'"
128+
beta-bump = "cz bump -pr beta --check-consistency --yes --changelog --gpg-sign --annotated-tag --annotated-tag-message 'Version $(hatch version)'"
129129
local-bump = "cz bump {args} --files-only --yes"
130130
binary-dist = "python --version && python -m PyInstaller safety.spec {args}"
131131

0 commit comments

Comments
 (0)