Skip to content

Commit

Permalink
Automatically bump rust crate version on release
Browse files Browse the repository at this point in the history
This way we don't forget to do it in future releases.
  • Loading branch information
JasonGross committed May 13, 2020
1 parent be9371b commit aed3c7d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,22 @@ jobs:
run: cargo publish --manifest-path fiat-rust/Cargo.toml
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.crates_io_token }}
- name: Bump Rust crate version
run: |
etc/bump-fiat-rust-crate-version.sh
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git config http.sslVerify false
git config user.name "Automated Publisher"
git config user.email "[email protected]"
git remote add publisher "${remote_repo}"
git show-ref # useful for debugging
git branch --verbose
git checkout master
git add fiat-rust/Cargo.toml
timestamp=$(date -u)
git commit -m "Automated Rust Crate Version Bump: ${timestamp} ${GITHUB_SHA}"
git pull --rebase publisher master
git push publisher master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions etc/bump-fiat-rust-crate-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

CARGO_TOML_PATH="fiat-rust/Cargo.toml"

VERSION_LINE="$(grep 'version\s*=\s*' "${CARGO_TOML_PATH}")"
VERSION_NUMBER="$(echo "${VERSION_LINE}" | sed 's/version\s*=\s*//g; s/"//g; s/\s//g')"
# https://stackoverflow.com/a/4486087/377022
NEW_VERSION_NUMBER="$(awk -F. '/[0-9]+\./{$NF++;print}' OFS=. <<< "${VERSION_NUMBER}")"
NEW_VERSION_LINE="$(echo "${VERSION_LINE}" | sed "s/${VERSION_NUMBER}/${NEW_VERSION_NUMBER}/g")"
echo "Updating ${CARGO_TOML_PATH} from version ${VERSION_NUMBER} to ${NEW_VERSION_NUMBER}"
sed "s/${VERSION_LINE}/${NEW_VERSION_LINE}/g" -i "${CARGO_TOML_PATH}"

# sanity check
AGAIN_VERSION_LINE="$(grep 'version\s*=\s*' "${CARGO_TOML_PATH}")"
AGAIN_VERSION_NUMBER="$(echo "${AGAIN_VERSION_LINE}" | sed 's/version\s*=\s*//g; s/"//g; s/\s//g')"
if [ "${NEW_VERSION_NUMBER}" != "${AGAIN_VERSION_NUMBER}" ]; then
echo "ERROR: Tried to change '${VERSION_NUMBER}' to '${NEW_VERSION_NUMBER}' in ${CARGO_TOML_PATH},"
echo " but somehow ended up with '${AGAIN_VERSION_NUMBER}'."
exit 1
fi
2 changes: 1 addition & 1 deletion fiat-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fiat-crypto"
version = "0.1.1"
version = "0.1.2"
authors = ["Fiat Crypto library authors <[email protected]>"]
edition = "2018"
description = "Fiat-crypto generated Rust"
Expand Down

0 comments on commit aed3c7d

Please sign in to comment.