Skip to content

Fuzion Utilities

Fuzion Utilities #2

Workflow file for this run

name: "crates-publish-release"
on:
push:
branches:
- "main"
jobs:
crates-publish:
name: "Publish release"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --tags
### Prepare cargo & toolchains
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rust toolchain with wasm32-unknown-unknown
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: actions-rs/cargo@v1
with:
toolchain: stable
command: update
args: --aggressive
### Calculate FINAL_VERSION
- name: Install jq & sponge
run: sudo apt-get update && sudo apt-get --yes --force-yes install jq moreutils
- name: Install cargo-show cargo-workspaces toml-cli
run: cargo install cargo-show cargo-workspaces toml-cli || true
- name: What's changed?
run: |
git tag -l
cargo ws changed 2>&1
- name: Set crate versions to match crates.io
run: |
# install semver and add it to PATH
yarn global add semver
PATH="$(yarn global bin):$PATH"
set -x
RELEASE_DESCRIPTION=""
for CRATE_NAME in $(cargo ws changed)
do
CRATE_VERSION="$((cargo show --json "$CRATE_NAME" | jq -r .crate.max_version) 2>/dev/null || true)"
NEXT_CRATE_VERSION="$(semver --increment patch "${CRATE_VERSION}" || true)"
CARGO_TOML="$(cargo ws changed --json | jq -er ".[] | select(.name == \"$CRATE_NAME\") | .location")""/Cargo.toml"
LOCAL_VERSION="$(toml get "$CARGO_TOML" package.version | tr -d \")"
MAX_VERSION="$(semver "$NEXT_CRATE_VERSION" "$LOCAL_VERSION" | tail -n1)"
toml set "$CARGO_TOML" package.version "$MAX_VERSION" | sponge "$CARGO_TOML"
# Generate description
LINK="https://crates.io/crates/$CRATE_NAME/$MAX_VERSION"
TEXT="$CRATE_NAME $MAX_VERSION"
ITEM="<li><a href=\"$LINK\">$TEXT</a></li>"
RELEASE_DESCRIPTION="${RELEASE_DESCRIPTION}${ITEM}"
done
RELEASE_DESCRIPTION="<h2>crates.io:</h2><ul>$RELEASE_DESCRIPTION</ul>"
echo "RELEASE_DESCRIPTION=$RELEASE_DESCRIPTION" | tee -a $GITHUB_ENV
### === Rust package release ===
- name: Login to crates.io
run: cargo login ${{ secrets.CRATES_REGISTRY_TOKEN }}
# Increment patch octet for changed crates and publish
- name: Publish to crates.io
run: cargo ws publish --no-git-commit --allow-dirty --yes --skip-published patch
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.run_number }}
release_name: fuzion-rs ${{ github.run_number }}
body: |
${{ env.RELEASE_DESCRIPTION }}
draft: true
prerelease: false