Skip to content

Commit

Permalink
ci: cancel publish workflow if kanata is already latest
Browse files Browse the repository at this point in the history
  • Loading branch information
rszyma committed Nov 30, 2023
1 parent 06174df commit 78e9796
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:

env:
CARGO_TERM_COLOR: always
VSCE_PAT: ${{ secrets.VSCE_ACCESS_TOKEN }}

jobs:
publish-prerelease:
Expand All @@ -30,8 +29,19 @@ jobs:

- name: Try bump kanata
run: |
just bump_kanata
git push
status=$(just bump_kanata; echo $?)
if [ $status -eq 0 ]; then
git push
elif [ $status -eq 123 ]; then
# Status 123 means that the version of kanata is already most recent.
# Ideally, we'd like to the workflow to appear as canceled.
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
else
echo "Failed with $status"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup - cargo cache
uses: actions/cache@v3
Expand Down Expand Up @@ -73,3 +83,5 @@ jobs:

- name: Build and publish
run: just pre_release ${{ steps.new-version.outputs.value }}
env:
VSCE_PAT: ${{ secrets.VSCE_ACCESS_TOKEN }}
6 changes: 4 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ bump_kanata:
cd kanata
HASH=$(git rev-parse --short HEAD)
cd ..
# Exit early without updating changelog if a bump notice was already added in "Unreleased" section.
$(! grep -q "$HASH" CHANGELOG.md)
# Exit early without updating changelog if a bump notice has already been added in "Unreleased" section.
# This works because of a some weird behavior of bash. More about it here:
# http://redsymbol.net/articles/unofficial-bash-strict-mode/#short-circuiting
grep -q "$HASH" CHANGELOG.md && (exit 123)
awk '/^### [0-9]/ && found==0 {found=1} found==0 && /Updated kanata to/ {next} 1' CHANGELOG.md > temp && mv temp CHANGELOG.md
just _add_to_changelog "Updated kanata to \[$HASH\]\(https\:\/\/github\.com\/jtroo\/kanata\/tree\/$HASH\)"
just _ensure_no_staged_changes
Expand Down

0 comments on commit 78e9796

Please sign in to comment.