-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (105 loc) · 3.63 KB
/
release.yml
File metadata and controls
119 lines (105 loc) · 3.63 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
name: Release
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
runner:
description: 'Choose runner'
default: 'self-hosted'
type: choice
options:
- self-hosted
- ubuntu-latest
jobs:
setup:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.set-runner.outputs.runner }}
steps:
- name: Determine runner
id: set-runner
run: |
SELECTED_RUNNER="${{ github.event.inputs.runner }}"
if [ -z "$SELECTED_RUNNER" ]; then
SELECTED_RUNNER="self-hosted"
fi
echo "runner=$SELECTED_RUNNER" >> $GITHUB_OUTPUT
release:
needs: setup
runs-on: ${{ needs.setup.outputs.runner }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get current version
id: current_version
run: |
# Get latest tag or default to 0.0.0
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "current_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Current version: $LATEST_TAG"
- name: Bump version
id: bump_version
run: |
CURRENT="${{ steps.current_version.outputs.current_tag }}"
CURRENT=${CURRENT#v} # Remove 'v' prefix
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT"
MAJOR="${VERSION_PARTS[0]:-0}"
MINOR="${VERSION_PARTS[1]:-0}"
PATCH="${VERSION_PARTS[2]:-0}"
case "${{ inputs.version_bump }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update version in pyproject.toml
run: |
NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
NEW_VERSION=${NEW_VERSION#v} # Remove 'v' prefix for pyproject.toml
sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" pyproject.toml
- name: Commit version bump
run: |
NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
git add pyproject.toml
git commit -m "chore: bump version to $NEW_VERSION"
git push
- name: Create and push tag
run: |
NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION"
git push origin "$NEW_VERSION"
- name: Summary
run: |
echo "### Release Created! 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Type**: ${{ inputs.version_bump }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The build and deployment workflow will trigger automatically." >> $GITHUB_STEP_SUMMARY