Skip to content

Commit

Permalink
ci: Automate release process (#1268)
Browse files Browse the repository at this point in the history
* Update release script to optionally accept CRATES_TOKEN

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Add release workflow using release script

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Fix release tag matching

Signed-off-by: Thane Thomson <connect@thanethomson.com>

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson committed Feb 17, 2023
1 parent 89c8add commit 8ba8550
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Attempts to perform a release when a particular tag is pushed. This uses the
# release.sh script in the root of the repository, and assumes that the
# CRATES_TOKEN secret has been set and contains an API token with which we can
# publish our crates to crates.io.
#
# If release operation fails partway through due to a temporary error (e.g. the
# crate being published depends on the crate published just prior, but the
# prior crate isn't yet available via crates.io), one can simply rerun this
# workflow. The release.sh script aims to be an idempotent operation, skipping
# the publishing of crates that have already been published.
name: Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v0.26.0, v1.0.0
- "v[0-9]+.[0-9]+.[0-9]+-pre.[0-9]+" # e.g. v0.26.0-pre.1

jobs:
release:
runs-on: ubuntu
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Publish crates
run: ./release.sh
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}

12 changes: 11 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ DEFAULT_CRATES="tendermint-proto tendermint-std-ext tendermint tendermint-config
# Allows us to override the crates we want to publish.
CRATES=${*:-${DEFAULT_CRATES}}

# Additional flags to pass to the "cargo publish" operation for every crate we
# publish.
CARGO_PUBLISH_FLAGS=""

# Allow us to specify a crates.io API token via environment variables. Mostly
# for CI use.
if [ -n "${CRATES_TOKEN}" ]; then
CARGO_PUBLISH_FLAGS="${CARGO_PUBLISH_FLAGS} --token ${CRATES_TOKEN}"
fi

get_manifest_path() {
cargo metadata --format-version 1 | jq -r '.packages[]|select(.name == "'"${1}"'")|.manifest_path'
}
Expand All @@ -37,7 +47,7 @@ check_version_online() {

publish() {
echo "Publishing crate $1..."
cargo publish --manifest-path "$(get_manifest_path "${1}")"
cargo publish --manifest-path "$(get_manifest_path "${1}")" ${CARGO_PUBLISH_FLAGS}
echo ""
}

Expand Down

0 comments on commit 8ba8550

Please sign in to comment.