Skip to content

Commit

Permalink
add publih workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass committed Mar 25, 2024
1 parent 985e617 commit 4d9425c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
33 changes: 33 additions & 0 deletions .github/actions/publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'publish'
description: 'Publishes Rust library to crates.io'
inputs:
crates-token:
description: 'used for authenticating towards crates.io'
required: true
version:
description: 'the version to release under (e.g. `1.2.3-dev.1`)'
required: true
dry-run:
description: "'true' = only log potential result; 'false' = publish'"
required: true
runs:
using: "composite"
steps:
- name: Setup Rust
uses: './.github/actions/setup'
with:
os: ${{ runner.os }}

- name: Install cargo-release
shell: bash
run: cargo install --version =0.25 cargo-release

- name: Publish library to crates.io
shell: bash
run: |
echo "dry-run: '${{ inputs.dry-run }}'"
echo "version: '${{ inputs.version }}'"
cargo login ${{ inputs.crates-token }}
cargo release config
cargo release version --verbose --execute --no-confirm ${{ inputs.version }}
cargo release publish --verbose $(if [ "${{ inputs.dry-run }}" = "false" ]; then echo --execute --no-confirm; fi)
49 changes: 49 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'rust-setup'
description: 'Prepares a rust environment and relevant caches.'
inputs:
target:
description: 'Additionally install specified target for this toolchain, ex. x86_64-apple-darwin'
required: false
toolchain:
description: 'Toolchain to install. Default: stable.'
required: false
default: stable
components:
description: 'Comma-separated string of additional components to install e.g. `clippy`, `rustfmt`'
required: false
os:
description: 'OS of the runner, used for cache key construction.'
required: true
runs:
using: "composite"
steps:

- name: Setup rust toolchain
shell: bash
run: |
if ! rustup self update; then
echo "rustup self update failed"
fi
TARGET=${{ inputs.target }}
if [[ $TARGET != '' ]]; then
rustup target add $TARGET
fi
rustup update
TOOLCHAIN=${{ inputs.toolchain }}
if [[ $TOOLCHAIN != 'stable' ]]; then
rustup toolchain install $TOOLCHAIN
fi
COMPONENTS=${{ inputs.components }}
if [[ $COMPONENTS != '' ]]; then
for i in ${COMPONENTS//,/ }
do
rustup component add $i $(if [ $TOOLCHAIN != '' ]; then echo --toolchain $TOOLCHAIN; fi)
done
fi
rustup show
Empty file.
9 changes: 4 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install rust toolchain
uses: actions-rs/toolchain@v1
- name: Setup Rust
uses: './.github/actions/setup'
with:
os: ${{ runner.os }}
toolchain: nightly
components: clippy,rustfmt
override: true
profile: minimal

- name: Run cargo test
uses: actions-rs/cargo@v1
Expand Down

0 comments on commit 4d9425c

Please sign in to comment.