-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move setup-environment workflow into a separate file
- Loading branch information
1 parent
2015b2a
commit 24bab1f
Showing
2 changed files
with
80 additions
and
50 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Setup Environment | ||
on: | ||
workflow_call: | ||
outputs: | ||
git_tag_name: | ||
description: "Git release tag name" | ||
value: ${{ jobs.setup-environment.outputs.git_tag_name }} | ||
cargo_cache_key: | ||
description: "Cargo cache key for the build" | ||
value: ${{ jobs.setup-environment.outputs.cargo_cache_key }} | ||
workflow_dispatch: | ||
inputs: | ||
git_tag_name: | ||
description: Git version tag (eg. v0.9.0) | ||
required: true | ||
|
||
jobs: | ||
setup-environment: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
git_tag_name: ${{ steps.git_tag_name.outputs.value }} | ||
cargo_cache_key: ${{ steps.cargo_cache_key.outputs.value }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
ref: ${{ inputs.git_tag_name || github.ref }} | ||
- uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
|
||
- name: Set cargo cache key | ||
id: cargo_cache_key | ||
run: | | ||
CARGO_CACHE_KEY="${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}" | ||
echo "value=$CARGO_CACHE_KEY" >> $GITHUB_OUTPUT | ||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
target | ||
~/.cargo/bin | ||
key: ${{ steps.cargo_cache_key.outputs.value }} | ||
id: cache-cargo-release | ||
|
||
- name: Set git_tag_name from latest Cargo.toml version | ||
id: git_tag_name | ||
run: | | ||
VERSION=$(cargo read-manifest --manifest-path ./tinted-builder-rust/Cargo.toml | jq -r ".version") | ||
echo "value=v$VERSION" >> $GITHUB_OUTPUT | ||
- name: Ensure the release tag does not exist | ||
run: | | ||
version="${{ steps.git_tag_name.outputs.value }}" | ||
if git rev-parse "$version" >/dev/null 2>&1; then | ||
echo "This git tag already exists: $version" | ||
exit 1 | ||
fi | ||
- name: Ensure crate version doesn't already exist | ||
run: | | ||
crate_name="tinted-builder-rust" | ||
version="${{ steps.git_tag_name.outputs.value }}" | ||
response=$(curl -s "https://crates.io/api/v1/crates/$crate_name") | ||
if echo "$response" | grep -q "\"num\":\"$version\""; then | ||
echo "Version $version of $crate_name already exists." | ||
exit 1 | ||
fi | ||
- name: Ensure changelog entry for version exists | ||
run: | | ||
version=$(cargo read-manifest --manifest-path ./tinted-builder-rust/Cargo.toml | jq -r ".version") | ||
if ! grep -q "\[$version\]" ./CHANGELOG.md; then | ||
echo "Changelog doesn't contain an entry for this version: $version" | ||
exit 1 | ||
fi |