CD #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
workflow_run: | |
workflows: ["CI"] | |
types: | |
- completed | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
# Run this only on tag push after success of CI | |
if: | | |
github.event_name == 'workflow_run' && | |
github.event.workflow_run.conclusion == 'success' && | |
startsWith(github.event.workflow_run.head_branch, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Extract version from Cargo.toml | |
id: extract_version | |
run: | | |
cargo_version=$(grep '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/') | |
echo "cargo_version=$cargo_version" >> $GITHUB_ENV | |
- name: Verify tag version matches Cargo.toml version | |
run: | | |
tag_version=${GITHUB_REF#refs/tags/v} | |
if [ "$tag_version" != "$cargo_version" ]; then | |
echo "Tag version (v$tag_version) does not match Cargo.toml version ($cargo_version)" | |
exit 1 | |
fi | |
- name: Cache Cargo registry and build | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo- | |
- name: Build | |
run: cargo build --verbose | |
- name: Publish crates | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
run: | | |
for crate in $(ls -d */ | grep -v 'target' | sed 's#/##'); do | |
echo "Publishing crate $crate" | |
cd $crate | |
cargo publish --token $CARGO_REGISTRY_TOKEN | |
cd .. | |
done |