Skip to content

Commit 14a2709

Browse files
committed
feat: add release support for pyproject.toml
1 parent c877922 commit 14a2709

File tree

2 files changed

+108
-62
lines changed

2 files changed

+108
-62
lines changed

.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 | awk -F'"' '{print $2}')
126+
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print $0".dev0"}')
127+
sed -i "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: 76 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,13 +28,12 @@ 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"
37-
WORKFLOW_BRANCH: "main"
36+
WORKFLOW_BRANCH: "mp/release_pyproject" # TODO: Remove
3837
GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }}
3938
CHARTMUSEUM_USER: ${{ secrets.DV_CHARTMUSEUM_USER }}
4039
CHARTMUSEUM_PASSWORD: ${{ secrets.DV_CHARTMUSEUM_PASSWORD }}
@@ -61,36 +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
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
94100
if: ${{ inputs.skip_branch_check == false }}
95101
id: get-release-version-from-input
96102
run: |
@@ -102,27 +108,26 @@ jobs:
102108
exit 1
103109
fi
104110
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)
113-
114-
echo "Stable release version: $file_major.$file_minor.$file_patch"
111+
# Extract major, minor, and patch versions of the input version
112+
input_major=$(echo "$input_release_version" | cut -d'.' -f1)
113+
input_minor=$(echo "$input_release_version" | cut -d'.' -f2)
114+
input_patch=$(echo "$input_release_version" | cut -d'.' -f3)
115115
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)
116+
# Utility function to validate versioning rules
117+
validate_version() {
118+
input_major=$1
119+
input_minor=$2
120+
input_patch=$3
121+
file_major=$4
122+
file_minor=$5
123+
file_patch=$6
119124
120125
if [ "$input_major" -eq "$file_major" ]; then
121126
if [ "$input_minor" -eq "$file_minor" ]; then
122127
if [ "$input_patch" -eq "$file_patch" ]; then
123128
echo "Valid patch version input"
124129
else
125-
echo "Error: Patch version must match the package.json version without the -SNAPSHOT suffix."
130+
echo "Error: Patch version must match the file version without the -SNAPSHOT or .dev0 suffix."
126131
exit 1
127132
fi
128133
elif [ "$input_minor" -gt "$file_minor" ] && [ "$input_patch" -eq 0 ]; then
@@ -137,21 +142,54 @@ jobs:
137142
echo "Error: Version input is invalid based on semantic versioning rules."
138143
exit 1
139144
fi
145+
}
146+
147+
# Call the function for package.json (if needed)
148+
if [ "${{ steps.check-package-json.outputs.has_package_json }}" == "true" ]; then
149+
file_release_version="$(jq -r '.version' package.json | cut -d '-' -f 1)"
150+
file_release_version=$(echo "$file_release_version" | sed 's/-SNAPSHOT//')
151+
echo "file_release_version=$file_release_version"
152+
file_major=$(echo "$file_release_version" | cut -d'.' -f1)
153+
file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
154+
file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
155+
156+
echo "Validating package.json version: $file_major.$file_minor.$file_patch"
157+
158+
validate_version "$input_major" "$input_minor" "$input_patch" "$file_major" "$file_minor" "$file_patch"
159+
fi
160+
161+
# Call the function for pyproject.toml (if needed)
162+
if [ "${{ steps.check-pyproject-toml.outputs.has_pyproject_toml }}" == "true" ]; then
163+
file_release_version="$(grep -oP '(?<=version = ")[^"]+' pyproject.toml | cut -d '-' -f 1)"
164+
file_release_version=$(echo "$file_release_version" | sed 's/\.dev0//')
165+
echo "file_release_version=$file_release_version"
166+
file_major=$(echo "$file_release_version" | cut -d'.' -f1)
167+
file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
168+
file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
169+
170+
echo "Validating pyproject.toml version: $file_major.$file_minor.$file_patch"
171+
172+
validate_version "$input_major" "$input_minor" "$input_patch" "$file_major" "$file_minor" "$file_patch"
140173
fi
141174
142175
echo "New version is $input_major.$input_minor.$input_patch"
143176
echo "RELEASE_VERSION=$input_release_version" >> "$GITHUB_ENV"
144-
145-
- name: create release branch
177+
178+
- name: Create release branch
146179
run: |
147180
git config user.name "$GITHUB_ACTOR"
148181
git config user.email "<>"
149182
git checkout -b release-"$RELEASE_VERSION"
150183
- name: Update package.json
151-
if: ${{ steps.check-package-json.outputs.is_package_json == 'true' }}
184+
if: ${{ steps.check-package-json.outputs.has_package_json == 'true' }}
152185
run: |
153186
sed -i "s/^\(\s*\)\"version\".*/\1\"version\": \"$RELEASE_VERSION\",/" package.json
154187
git add package.json
188+
- name: Update pyproject.toml
189+
if: ${{ steps.check-pyproject-toml.outputs.has_pyproject_toml == 'true' }}
190+
run: |
191+
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
192+
git add pyproject.toml
155193
- name: Add Helm repository
156194
if: ${{ inputs.is_helm_chart == true }}
157195
run: |
@@ -160,7 +198,7 @@ jobs:
160198
# TODO: make this an input of the workflow.
161199
helm repo add apache-airflow https://airflow.apache.org
162200
helm repo add bitnami https://charts.bitnami.com/bitnami
163-
- name: change charts and subcharts version
201+
- name: Change charts and subcharts version
164202
if: ${{ inputs.is_helm_chart == true }}
165203
run: |
166204
cd deploy/helm
@@ -190,7 +228,7 @@ jobs:
190228
done
191229
192230
git add .
193-
- name: update imageTag and repository_tag in values files
231+
- name: Update imageTag and repository_tag in values files
194232
if: ${{ inputs.is_helm_chart == true }}
195233
run: |
196234
cd deploy/helm
@@ -255,12 +293,12 @@ jobs:
255293
-d "$(jq -n --arg tag_name "$TAG_NAME" \
256294
--arg target_commitish "${{ github.ref_name }}" \
257295
'{tag_name: $tag_name, target_commitish: $target_commitish}')")
258-
296+
259297
RELEASE_NOTES=$(echo "$response" | jq -r '.body')
260298
261-
echo "$RELEASE_NOTES" > release_notes.txt
299+
echo "$RELEASE_NOTES" > release_notes.txt
262300
263-
- name: create pr
301+
- name: Create pr
264302
run: |
265303
PR_NOTES=$(cat release_notes.txt)
266304
curl -L \

0 commit comments

Comments
 (0)