Skip to content

Commit c286715

Browse files
Copilotadriangb
andcommitted
Add version detection to conditionally run release jobs
- Add check-version job to python.yaml workflow - Add check-version job to python-json.yaml workflow - Add check-version job to rust.yaml workflow - Each release job now only runs if version has changed Co-authored-by: adriangb <1755071+adriangb@users.noreply.github.com>
1 parent 295d7ab commit c286715

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
lines changed

.github/workflows/python-json.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,43 @@ jobs:
231231
# If they fail in main, we want to fail the alls-green check
232232
allowed-skips: macos,windows, musllinux
233233

234+
check-version:
235+
name: Check if version changed
236+
runs-on: ubuntu-latest
237+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
238+
outputs:
239+
version-changed: ${{ steps.check.outputs.changed }}
240+
steps:
241+
- uses: actions/checkout@v4
242+
with:
243+
fetch-depth: 2
244+
- name: Check if version changed
245+
id: check
246+
run: |
247+
# Get the version from the current commit
248+
CURRENT_VERSION=$(grep '^version = ' ${{ env.PACKAGE_DIR }}/pyproject.toml | head -n 1 | cut -d '"' -f 2)
249+
echo "Current version: $CURRENT_VERSION"
250+
251+
# Get the version from the previous commit
252+
git checkout HEAD~1 -- ${{ env.PACKAGE_DIR }}/pyproject.toml 2>/dev/null || true
253+
PREVIOUS_VERSION=$(grep '^version = ' ${{ env.PACKAGE_DIR }}/pyproject.toml | head -n 1 | cut -d '"' -f 2)
254+
echo "Previous version: $PREVIOUS_VERSION"
255+
256+
# Restore current version
257+
git checkout HEAD -- ${{ env.PACKAGE_DIR }}/pyproject.toml
258+
259+
# Compare versions
260+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
261+
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
262+
echo "changed=true" >> $GITHUB_OUTPUT
263+
else
264+
echo "Version unchanged: $CURRENT_VERSION"
265+
echo "changed=false" >> $GITHUB_OUTPUT
266+
fi
267+
234268
release:
235269
name: Release
236-
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
270+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && needs.check-version.outputs.version-changed == 'true'
237271
runs-on: ubuntu-latest
238272
timeout-minutes: 15
239273
needs:
@@ -242,6 +276,7 @@ jobs:
242276
- windows
243277
- linux
244278
- musllinux
279+
- check-version
245280
steps:
246281
- uses: actions/download-artifact@v4
247282
with:

.github/workflows/python.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,52 @@ jobs:
230230
# If they fail in main, we want to fail the alls-green check
231231
allowed-skips: macos,windows, musllinux
232232

233+
check-version:
234+
name: Check if version changed
235+
runs-on: ubuntu-latest
236+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
237+
outputs:
238+
version-changed: ${{ steps.check.outputs.changed }}
239+
steps:
240+
- uses: actions/checkout@v4
241+
with:
242+
fetch-depth: 2
243+
- name: Check if version changed
244+
id: check
245+
run: |
246+
# Get the version from the current commit
247+
CURRENT_VERSION=$(grep '^version = ' ${{ env.PACKAGE_DIR }}/pyproject.toml | head -n 1 | cut -d '"' -f 2)
248+
echo "Current version: $CURRENT_VERSION"
249+
250+
# Get the version from the previous commit
251+
git checkout HEAD~1 -- ${{ env.PACKAGE_DIR }}/pyproject.toml 2>/dev/null || true
252+
PREVIOUS_VERSION=$(grep '^version = ' ${{ env.PACKAGE_DIR }}/pyproject.toml | head -n 1 | cut -d '"' -f 2)
253+
echo "Previous version: $PREVIOUS_VERSION"
254+
255+
# Restore current version
256+
git checkout HEAD -- ${{ env.PACKAGE_DIR }}/pyproject.toml
257+
258+
# Compare versions
259+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
260+
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
261+
echo "changed=true" >> $GITHUB_OUTPUT
262+
else
263+
echo "Version unchanged: $CURRENT_VERSION"
264+
echo "changed=false" >> $GITHUB_OUTPUT
265+
fi
266+
233267
release:
234268
name: Release
235269
runs-on: ubuntu-latest
236270
timeout-minutes: 15
237-
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
271+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && needs.check-version.outputs.version-changed == 'true'
238272
needs:
239273
- lint
240274
- linux
241275
- macos
242276
- windows
243277
- musllinux
278+
- check-version
244279
steps:
245280
- uses: actions/download-artifact@v4
246281
with:

.github/workflows/rust.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,47 @@ jobs:
8585
with:
8686
jobs: ${{ toJSON(needs) }}
8787

88+
check-version:
89+
name: Check if version changed
90+
runs-on: ubuntu-latest
91+
if: ${{ github.ref == 'refs/heads/main' }}
92+
outputs:
93+
version-changed: ${{ steps.check.outputs.changed }}
94+
steps:
95+
- uses: actions/checkout@v4
96+
with:
97+
fetch-depth: 2
98+
- name: Check if version changed
99+
id: check
100+
run: |
101+
# Get the version from the current commit
102+
CURRENT_VERSION=$(grep '^version = ' core/Cargo.toml | head -n 1 | cut -d '"' -f 2)
103+
echo "Current version: $CURRENT_VERSION"
104+
105+
# Get the version from the previous commit
106+
git checkout HEAD~1 -- core/Cargo.toml 2>/dev/null || true
107+
PREVIOUS_VERSION=$(grep '^version = ' core/Cargo.toml | head -n 1 | cut -d '"' -f 2)
108+
echo "Previous version: $PREVIOUS_VERSION"
109+
110+
# Restore current version
111+
git checkout HEAD -- core/Cargo.toml
112+
113+
# Compare versions
114+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
115+
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
116+
echo "changed=true" >> $GITHUB_OUTPUT
117+
else
118+
echo "Version unchanged: $CURRENT_VERSION"
119+
echo "changed=false" >> $GITHUB_OUTPUT
120+
fi
121+
88122
release:
89123
name: Release
90124
runs-on: ubuntu-latest
91125
needs:
92126
- check
93-
if: ${{ github.ref == 'refs/heads/main' }}
127+
- check-version
128+
if: ${{ github.ref == 'refs/heads/main' && needs.check-version.outputs.version-changed == 'true' }}
94129
steps:
95130
- uses: actions/checkout@v4
96131
- uses: actions-rs/toolchain@v1

0 commit comments

Comments
 (0)