Publish Crates #1
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 workflow is used for publish crate to crates.io. The workflow will use | |
# environment "Publish to crates.io" which needs approval to access the `CARGO_REGISTRY_TOKEN` | |
name: Publish Crates | |
on: | |
# The workflow can be triggered or by creating new release: please ensure the tag name used for the | |
# release follow this format: '${crate name}_v{version number}', although in this workflow | |
# only ${crate name} is used, but {version number} is still needed for a good tag name. | |
release: | |
types: [created] | |
# The workflow can be also manually triggered by `workflow_dispatch`, see more | |
# from: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch | |
workflow_dispatch: | |
inputs: | |
crate_name: | |
description: 'Name of crate to be published' | |
required: true | |
type: string | |
permissions: | |
contents: read | |
jobs: | |
crate_publish: | |
environment: "Publish to crates.io" | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
- name: Install build dependencies | |
run: | | |
cat llvm-snapshot.gpg.key | sudo apt-key add - | |
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main" | sudo tee -a /etc/apt/sources.list | |
cat intel-sgx-deb.key | sudo apt-key add - | |
echo "deb https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main" | sudo tee -a /etc/apt/sources.list | |
sudo apt-get update | |
sudo apt-get install -y clang-11 libsgx-dcap-ql-dev protobuf-compiler | |
# Create a symbolic link to ensure correct usage of libclang | |
sudo ln -s /lib/x86_64-linux-gnu/libclang-11.so.1 /lib/x86_64-linux-gnu/libclang.so | |
- name: Get name of crate to be published | |
run: | | |
# If this workflow is manually triggered through `workflow_dispatch` | |
if [[ -z "${{ inputs.crate_name }}" ]]; then | |
# Extract the crate name from the GITHUB_REF environment variable | |
# GITHUB_REF contains the GitHub reference (e.g., refs/tags/rs-lic_v0.2.4) associated with the event | |
export CRATE_NAME=$(python3 -c "print('$GITHUB_REF'.split('/')[2].rsplit('_v', 1)[0])") | |
else | |
export CRATE_NAME="${{ inputs.crate_name }}" | |
fi | |
echo "CRATE_NAME=$CRATE_NAME" >> $GITHUB_ENV | |
- name: Publish crate to crates.io | |
run: | | |
echo "Publishing crate: $CRATE_NAME" | |
cargo publish --locked --token ${CARGO_REGISTRY_TOKEN} --package "$CRATE_NAME" | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
RUST_BACKTRACE: "1" | |
PYTHONDONTWRITEBYTECODE: "1" |