Skip to content

Commit

Permalink
Chore: release sqlglotrs only when Cargo.toml is updated (#3408)
Browse files Browse the repository at this point in the history
* Chore: release sqlglotrs only when Cargo.toml is updated

* typo

* fixup
  • Loading branch information
georgesittas committed May 4, 2024
1 parent 1b5b77d commit fcb51af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ permissions:
contents: read

jobs:
should-deploy-rs:
runs-on: ubuntu-latest
outputs:
deploy: ${{ steps.check_deploy.outputs.deploy }}
steps:
- uses: actions/checkout@v3
- id: check_deploy
name: Check if sqlglotrs should be deployed
run: |
bash ./.github/workflows/should_deploy_sqlglotrs.sh
if [ $? -eq 0]; then echo "deploy=true"; else echo "deploy=false"; fi >> "$GITHUB_OUTPUT"
build-rs:
needs: should-deploy-rs
if: ${{ needs.should-deploy-rs.outputs.deploy == 'true' }}
strategy:
matrix:
os: [linux, macos, windows]
Expand Down Expand Up @@ -51,6 +65,8 @@ jobs:
path: sqlglotrs/dist

sdist-rs:
needs: should-deploy-rs
if: ${{ needs.should-deploy-rs.outputs.deploy == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -67,8 +83,9 @@ jobs:
path: sqlglotrs/dist

deploy-rs:
needs: [should-deploy-rs, build-rs, sdist-rs]
if: ${{ needs.should-deploy-rs.outputs.deploy == 'true' }}
runs-on: ubuntu-latest
needs: [build-rs, sdist-rs]
steps:
- uses: actions/download-artifact@v3
with:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/should_deploy_sqlglotrs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -ex

CARGO_TOML_PATH="./sqlglotrs/Cargo.toml"
CARGO_TOML_MOST_RECENT_COMMIT=$(git log -1 --pretty="%H" -- $CARGO_TOML_PATH | head -1)

PREVIOUS_TAG=$(git tag --sort=-creatordate | head -n 2 | tail -n 1)
PREVIOUS_TAG_COMMIT=$(git rev-list -n 1 $PREVIOUS_TAG)

# We should only deploy sqlglotrs if Cargo.toml was modified between this tag and the previous one
exit $(git merge-base --is-ancestor $PREVIOUS_TAG_COMMIT $CARGO_TOML_MOST_RECENT_COMMIT)

0 comments on commit fcb51af

Please sign in to comment.