Skip to content

Commit

Permalink
Move setup-environment workflow into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden committed Jun 25, 2024
1 parent 2015b2a commit 24bab1f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 50 deletions.
54 changes: 4 additions & 50 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,10 @@ permissions:

jobs:
setup-environment:
runs-on: ubuntu-latest
uses: ./.github/workflows/setup-environment.yml
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: ${{ 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
git_tag: ${{ steps.setup-environment.outputs.git_tag_name }}
cargo_key: ${{ steps.setup-environment.outputs.cargo_cache_key }}

lint:
needs: setup-environment
Expand Down Expand Up @@ -129,7 +83,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
checksum: sha256

build-docker-image:
build-and-push-docker-image:
needs:
- setup-environment
- release
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/setup-environment.yml
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

0 comments on commit 24bab1f

Please sign in to comment.