Skip to content

Commit 4eb8063

Browse files
puehringerCopilot
andauthored
feat: add release support for pyproject.toml (#231)
* feat: add release support for pyproject.toml * Update .github/workflows/release-source.yml Co-authored-by: Copilot <[email protected]> * Update .github/workflows/release-post-merge.yml Co-authored-by: Copilot <[email protected]> * Add UV_SYSTEM_PYTHON and UV_PROJECT_ENVIRONMENT --------- Co-authored-by: Copilot <[email protected]>
1 parent c877922 commit 4eb8063

File tree

3 files changed

+113
-62
lines changed

3 files changed

+113
-62
lines changed

.github/actions/build-node-python/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ runs:
198198
run: |
199199
# Run node and python in parallel
200200
201+
# In case uv sync is used, sync into the system python environment
202+
# https://github.com/astral-sh/uv/issues/8085#issuecomment-2406665798
203+
export UV_PROJECT_ENVIRONMENT="${pythonLocation}"
204+
201205
# Define the node sequence of commands
202206
node_job() {
203207
set -e
@@ -280,7 +284,9 @@ runs:
280284
RUN_PYTHON_LINT: ${{ inputs.run_python_lint }}
281285
RUN_PYTHON_TEST: ${{ inputs.run_python_test }}
282286
RUN_PYTHON_BUILD: ${{ inputs.run_python_build }}
287+
UV_SYSTEM_PYTHON: 1 # In case uv pip is used, install into the system python environment https://docs.astral.sh/uv/guides/integration/github/#using-uv-pip
283288
UV_HTTP_TIMEOUT: 300 # https://docs.astral.sh/uv/reference/environment/#uv_http_timeout
289+
284290
# Node
285291
- name: Save yarn cache
286292
uses: actions/cache/save@v4

.github/workflows/release-post-merge.yml

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ on:
3030
description: "The name of the repository"
3131
required: true
3232

33-
3433
permissions:
3534
contents: write
3635
pull-requests: write
@@ -53,13 +52,13 @@ jobs:
5352
git config --add --global url."https://$GITHUB_TOKEN@github".insteadOf https://github
5453
git config --add --global url."https://[email protected]/".insteadOf [email protected]:
5554
56-
- name: Checkout Repository
55+
- name: Checkout repository
5756
uses: actions/checkout@v5
5857
with:
5958
token: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }}
6059
fetch-depth: 0
6160

62-
- name: Create and Push Tag
61+
- name: Create and push tag
6362
run: |
6463
TAG_NAME="v$(echo "${{ inputs.pr_title }}" | awk '{print $2}')"
6564
git tag "$TAG_NAME"
@@ -72,11 +71,11 @@ jobs:
7271
PR_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
7372
-H "Accept: application/vnd.github.v3+json" \
7473
https://api.github.com/repos/${{ inputs.repository_owner }}/${{ inputs.repository_name }}/pulls/${{ inputs.pr_number }})
75-
74+
7675
PR_BODY=$(echo "$PR_RESPONSE" | jq -r '.body')
7776
echo "$PR_BODY" > pr_release_notes.txt
78-
79-
- name: Create GitHub Release
77+
78+
- name: Create release
8079
run: |
8180
TAG_NAME="v$(echo "${{ inputs.pr_title }}" | awk '{print $2}')"
8281
RELEASE_NOTES=$(cat pr_release_notes.txt)
@@ -100,34 +99,43 @@ jobs:
10099
else
101100
echo "GitHub release '$TAG_NAME' created successfully."
102101
fi
103-
104-
- name: Merge Main into Develop
102+
103+
- name: Merge main into develop
105104
run: |
106105
git config user.name "$GITHUB_USER"
107106
git config user.email "<>"
108107
git checkout ${{ inputs.develop_branch }}
109108
git fetch origin ${{ inputs.base_branch }}
110109
git merge origin/${{ inputs.base_branch }}
111110
git push origin ${{ inputs.develop_branch }}
112-
113-
- name: check for package.json
114-
id: check-package-json
111+
112+
- name: Update package.json
115113
run: |
116114
if [ -f "package.json" ]; then
117-
echo "is_package_json=true" >> "$GITHUB_OUTPUT"
118-
else
119-
echo "is_package_json=false" >> "$GITHUB_OUTPUT"
115+
CURRENT_VERSION=$(jq -r '.version' package.json)
116+
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print $0"-SNAPSHOT"}')
117+
jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json
118+
119+
git add package.json
120120
fi
121121
122-
- name: Update Package Version for Next Development Cycle
123-
if: ${{ steps.check-package-json.outputs.is_package_json == 'true' }}
122+
- name: Update pyproject.toml
124123
run: |
125-
git config user.name "$GITHUB_USER"
126-
git config user.email "<>"
127-
CURRENT_VERSION=$(jq -r '.version' package.json)
128-
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print $0"-SNAPSHOT"}')
129-
jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json
124+
if [ -f "pyproject.toml" ]; then
125+
CURRENT_VERSION=$(grep -m 1 '^version =' pyproject.toml | sed -E "s/^version = ['\"]([^'\"]+)['\"].*/\1/")
126+
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print $0".dev0"}')
127+
sed -i -E "s/^version = ['\"][^'\"]+['\"]/version = \"${NEW_VERSION}\"/" pyproject.toml
130128
131-
git add package.json
132-
git commit -m "chore: prepare next dev release"
133-
git push origin ${{ inputs.develop_branch }}
129+
git add pyproject.toml
130+
fi
131+
132+
- name: Push remaining changes
133+
run: |
134+
# Only push if there are changes to commit
135+
if [[ $(git status --porcelain --untracked-files=no) ]]; then
136+
git config user.name "$GITHUB_USER"
137+
git config user.email "<>"
138+
139+
git commit -m "chore: prepare next dev release"
140+
git push origin ${{ inputs.develop_branch }}
141+
fi

.github/workflows/release-source.yml

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ on:
44
workflow_call:
55
inputs:
66
is_helm_chart:
7-
description: 'Specify if this is a Helm Chart repository'
7+
description: "Specify if this is a Helm Chart repository"
88
required: false
99
type: boolean
1010
default: false
1111
release_version:
1212
type: string
13-
description: 'The version to release'
13+
description: "The version to release"
1414
required: true
1515
skip_branch_check:
16-
description: 'Skip the branch check'
16+
description: "Skip the branch check"
1717
required: false
1818
type: boolean
1919
default: false
2020
base_branch:
21-
description: 'The base branch to use'
21+
description: "The base branch to use"
2222
required: false
2323
type: string
2424
default: main
@@ -28,11 +28,10 @@ permissions:
2828
pull-requests: write
2929

3030
concurrency:
31-
group: '${{ github.workflow }}-${{ github.ref || github.head_ref }}'
31+
group: "${{ github.workflow }}-${{ github.ref || github.head_ref }}"
3232
cancel-in-progress: true
3333

3434
env:
35-
GA_VERSION: "main"
3635
GITHUB_USER: "datavisyn-bot"
3736
WORKFLOW_BRANCH: "main"
3837
GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }}
@@ -61,37 +60,43 @@ jobs:
6160
echo "Error: base_branch must be 'main' when skip_branch_check is false."
6261
exit 1
6362
fi
64-
# checkout specific repository
65-
- name: checkout repository
63+
- name: Checkout repository
6664
uses: actions/checkout@v5
6765
with:
6866
token: ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
69-
# checkout this workflow repository to get actions
70-
- name: checkout github-workflows repository
67+
- name: Checkout github-workflows repository
7168
uses: actions/checkout@v5
7269
with:
7370
repository: datavisyn/github-workflows
7471
ref: ${{ env.WORKFLOW_BRANCH }}
7572
path: ./tmp/github-workflows
76-
- name: check actor
73+
- name: Check actor
7774
uses: ./tmp/github-workflows/.github/actions/check-actor
7875
with:
7976
dv_devops: ${{ vars.DV_DEVOPS }}
8077
allowed_users: ${{ vars.DV_CAN_RELEASE }}
8178
actor: ${{ github.actor }}
8279
qms_are_allowed: "false"
8380

84-
- name: check for package.json
81+
- name: Check for package.json
8582
id: check-package-json
8683
run: |
8784
if [ -f "package.json" ]; then
88-
echo "is_package_json=true" >> "$GITHUB_OUTPUT"
85+
echo "has_package_json=true" >> "$GITHUB_OUTPUT"
8986
else
90-
echo "is_package_json=false" >> "$GITHUB_OUTPUT"
87+
echo "has_package_json=false" >> "$GITHUB_OUTPUT"
9188
fi
9289
93-
- name: get release version from input
94-
if: ${{ inputs.skip_branch_check == false }}
90+
- name: Check for pyproject.toml
91+
id: check-pyproject-toml
92+
run: |
93+
if [ -f "pyproject.toml" ]; then
94+
echo "has_pyproject_toml=true" >> "$GITHUB_OUTPUT"
95+
else
96+
echo "has_pyproject_toml=false" >> "$GITHUB_OUTPUT"
97+
fi
98+
99+
- name: Get release version from input
95100
id: get-release-version-from-input
96101
run: |
97102
input_release_version="${{ inputs.release_version }}"
@@ -102,27 +107,26 @@ jobs:
102107
exit 1
103108
fi
104109
105-
# Check if package.json exists and validate the version against it
106-
if [ "${{ steps.check-package-json.outputs.is_package_json }}" == "true" ]; then
107-
file_release_version="$(jq -r '.version' package.json | cut -d '-' -f 1)"
108-
file_release_version="${file_release_version//[^0-9.]}"
109-
echo "file_release_version=$file_release_version"
110-
file_major=$(echo "$file_release_version" | cut -d'.' -f1)
111-
file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
112-
file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
110+
# Extract major, minor, and patch versions of the input version
111+
input_major=$(echo "$input_release_version" | cut -d'.' -f1)
112+
input_minor=$(echo "$input_release_version" | cut -d'.' -f2)
113+
input_patch=$(echo "$input_release_version" | cut -d'.' -f3)
113114
114-
echo "Stable release version: $file_major.$file_minor.$file_patch"
115-
116-
input_major=$(echo "$input_release_version" | cut -d'.' -f1)
117-
input_minor=$(echo "$input_release_version" | cut -d'.' -f2)
118-
input_patch=$(echo "$input_release_version" | cut -d'.' -f3)
115+
# Utility function to validate versioning rules
116+
validate_version() {
117+
input_major=$1
118+
input_minor=$2
119+
input_patch=$3
120+
file_major=$4
121+
file_minor=$5
122+
file_patch=$6
119123
120124
if [ "$input_major" -eq "$file_major" ]; then
121125
if [ "$input_minor" -eq "$file_minor" ]; then
122126
if [ "$input_patch" -eq "$file_patch" ]; then
123127
echo "Valid patch version input"
124128
else
125-
echo "Error: Patch version must match the package.json version without the -SNAPSHOT suffix."
129+
echo "Error: Patch version must match the file version without the -SNAPSHOT or .dev0 suffix."
126130
exit 1
127131
fi
128132
elif [ "$input_minor" -gt "$file_minor" ] && [ "$input_patch" -eq 0 ]; then
@@ -137,21 +141,54 @@ jobs:
137141
echo "Error: Version input is invalid based on semantic versioning rules."
138142
exit 1
139143
fi
144+
}
145+
146+
# Call the function for package.json (if needed)
147+
if [ "${{ steps.check-package-json.outputs.has_package_json }}" == "true" ]; then
148+
file_release_version="$(jq -r '.version' package.json | cut -d '-' -f 1)"
149+
file_release_version=${file_release_version//-SNAPSHOT/}
150+
echo "file_release_version=$file_release_version"
151+
file_major=$(echo "$file_release_version" | cut -d'.' -f1)
152+
file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
153+
file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
154+
155+
echo "Validating package.json version: $file_major.$file_minor.$file_patch"
156+
157+
validate_version "$input_major" "$input_minor" "$input_patch" "$file_major" "$file_minor" "$file_patch"
158+
fi
159+
160+
# Call the function for pyproject.toml (if needed)
161+
if [ "${{ steps.check-pyproject-toml.outputs.has_pyproject_toml }}" == "true" ]; then
162+
file_release_version="$(grep -oP 'version\s*=\s*[\"\x27]\K[^\"\x27]+' pyproject.toml | cut -d '-' -f 1)"
163+
file_release_version=${file_release_version//.dev0/}
164+
echo "file_release_version=$file_release_version"
165+
file_major=$(echo "$file_release_version" | cut -d'.' -f1)
166+
file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
167+
file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
168+
169+
echo "Validating pyproject.toml version: $file_major.$file_minor.$file_patch"
170+
171+
validate_version "$input_major" "$input_minor" "$input_patch" "$file_major" "$file_minor" "$file_patch"
140172
fi
141173
142174
echo "New version is $input_major.$input_minor.$input_patch"
143175
echo "RELEASE_VERSION=$input_release_version" >> "$GITHUB_ENV"
144-
145-
- name: create release branch
176+
177+
- name: Create release branch
146178
run: |
147179
git config user.name "$GITHUB_ACTOR"
148180
git config user.email "<>"
149181
git checkout -b release-"$RELEASE_VERSION"
150182
- name: Update package.json
151-
if: ${{ steps.check-package-json.outputs.is_package_json == 'true' }}
183+
if: ${{ steps.check-package-json.outputs.has_package_json == 'true' }}
152184
run: |
153185
sed -i "s/^\(\s*\)\"version\".*/\1\"version\": \"$RELEASE_VERSION\",/" package.json
154186
git add package.json
187+
- name: Update pyproject.toml
188+
if: ${{ steps.check-pyproject-toml.outputs.has_pyproject_toml == 'true' }}
189+
run: |
190+
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
191+
git add pyproject.toml
155192
- name: Add Helm repository
156193
if: ${{ inputs.is_helm_chart == true }}
157194
run: |
@@ -160,7 +197,7 @@ jobs:
160197
# TODO: make this an input of the workflow.
161198
helm repo add apache-airflow https://airflow.apache.org
162199
helm repo add bitnami https://charts.bitnami.com/bitnami
163-
- name: change charts and subcharts version
200+
- name: Change charts and subcharts version
164201
if: ${{ inputs.is_helm_chart == true }}
165202
run: |
166203
cd deploy/helm
@@ -190,7 +227,7 @@ jobs:
190227
done
191228
192229
git add .
193-
- name: update imageTag and repository_tag in values files
230+
- name: Update imageTag and repository_tag in values files
194231
if: ${{ inputs.is_helm_chart == true }}
195232
run: |
196233
cd deploy/helm
@@ -255,12 +292,12 @@ jobs:
255292
-d "$(jq -n --arg tag_name "$TAG_NAME" \
256293
--arg target_commitish "${{ github.ref_name }}" \
257294
'{tag_name: $tag_name, target_commitish: $target_commitish}')")
258-
295+
259296
RELEASE_NOTES=$(echo "$response" | jq -r '.body')
260297
261-
echo "$RELEASE_NOTES" > release_notes.txt
298+
echo "$RELEASE_NOTES" > release_notes.txt
262299
263-
- name: create pr
300+
- name: Create pr
264301
run: |
265302
PR_NOTES=$(cat release_notes.txt)
266303
curl -L \

0 commit comments

Comments
 (0)