-
-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (125 loc) · 4.92 KB
/
semanticVersionBump.yml
File metadata and controls
139 lines (125 loc) · 4.92 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
---
###############################################################################
# Workflow: Semantic Version Bump (next)
#
# Purpose:
# - Calculates the next semantic version for the Python package (openai_utils)
# based on semantic-release rules, comparing the current __version__.py value
# to the calculated value.
# - If a version bump is needed, updates __version__.py and pushes the change
# to the main branch.
#
# Triggers:
# - On push to the main branch
# - Manual dispatch
#
# Key Steps:
# 1. Checkout repository code
# 2. Set up Python and Node.js environments
# 3. Get current and next semantic version values
# 4. Compare versions and update __version__.py if needed
# 5. Commit and push the updated version file to the repository
#
# Notes:
# - Uses semantic-release (dry-run) to determine the next version
# - Requires PAT (Personal Access Token) secret for authentication
# - Only updates __version__.py if a version bump is detected
###############################################################################
name: Semantic Version Bump (next)
on:
workflow_dispatch:
push:
branches:
- main
jobs:
bump-version-next:
runs-on: ubuntu-latest
env:
VERSION_FILE: __version__.py
PACKAGE_PATH: ${{ github.workspace }}/app/
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Cache NPM dependencies
uses: actions/cache@v5
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Setup Node.js environment
uses: actions/setup-node@v6
with:
node-version: "20.9.0"
- name: Install npm dev dependencies
run: npm install
- name: Get current version
# step 1
# the current version persisted to __version__.py
id: current_version
run: |
cd ${{ env.PACKAGE_PATH }}
echo "CURRENT_VERSION=$(python -c 'from __version__ import __version__; print(__version__)')" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: null step
id: null_step1
run: echo "i ensure that CURRENT_VERSION is set."
- name: Get next version
# step 2
# calculate the next version based on semantic-release rules
# this will return a null string is there in fact is no version bump.
# so set NEXT_VERSION to CURRENT_VERSION if there is no version bump.
id: next_version
run: |
NEXT_VERSION=$(npx semantic-release --dry-run --no-ci | awk '/The next release version is/{print $NF}')
echo "NEXT_VERSION=${NEXT_VERSION:-${{ env.CURRENT_VERSION }}}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
- name: null step
id: null_step2
run: echo "i ensure that NEXT_VERSION is set."
- name: Check versions
# step 3
# compare the current version to the next version.
# if they are different, set VERSION_CHANGED to true
id: check_versions
run: |
if [ "$CURRENT_VERSION" != "$NEXT_VERSION" ]; then
echo "VERSION_CHANGED=true" >> $GITHUB_ENV
else
echo "VERSION_CHANGED=false" >> $GITHUB_ENV
fi
env:
CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
NEXT_VERSION: ${{ env.NEXT_VERSION }}
- name: another null step
id: null_step3
run: echo "i ensure that CURRENT_VERSION, NEXT_VERSION and VERSION_CHANGED are set."
- name: Update __version__.py
# step 4
# if VERSION_CHANGED is true, update __version__.py and push the changes to the
# branch that triggered this workflow.
if: env.VERSION_CHANGED == 'true'
id: update_version
run: |
echo "# -*- coding: utf-8 -*-" > ${{ env.VERSION_FILE }}
echo "# DO NOT EDIT." >> ${{ env.VERSION_FILE }}
echo "# Managed via automated CI/CD in .github/workflows/semanticVersionBump.yml." >> ${{ env.VERSION_FILE }}
echo "__version__ = \"${{ env.NEXT_VERSION }}\"" >> ${{ env.VERSION_FILE }}
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ${{ env.VERSION_FILE }}
git commit -m "chore: [gh] Update __version__.py to ${{ env.NEXT_VERSION }} [skip ci]"
git push https://${{ secrets.PAT }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}
env:
VERSION_FILE: ${{ env.PACKAGE_PATH }}${{ env.VERSION_FILE }}
GITHUB_TOKEN: ${{ secrets.PAT }}
NEXT_VERSION: ${{ env.NEXT_VERSION }}
VERSION_CHANGED: ${{ env.VERSION_CHANGED }}