Release crates #23
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
name: Release crates | |
on: | |
workflow_dispatch: | |
inputs: | |
release_pac: | |
description: 'Release PAC (yes/no)' | |
required: true | |
default: 'yes' | |
release_hal: | |
description: 'Release HAL (yes/no)' | |
required: true | |
default: 'yes' | |
release_bsp: | |
description: 'Release BSPs (yes/no)' | |
required: true | |
default: 'yes' | |
jobs: | |
release-crates: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Rust | |
run: | | |
rustup set profile minimal | |
rustup override set stable | |
rustup target add thumbv6m-none-eabi | |
rustup target add thumbv7em-none-eabihf | |
- name: Login | |
run: cargo login ${CRATES_IO_TOKEN} | |
env: | |
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} | |
- name: Release PAC crates | |
if: github.event.inputs.release_pac == 'yes' | |
shell: bash | |
run: | | |
set -ex | |
# Run `cargo publish` on each PAC. | |
# Unfortunately, cargo publish errors if the crate is already uploaded, | |
# and there is no way to turn that off. As a result, we need to do some | |
# janky hacks to detect that condition and ignore it. | |
# | |
# Specifically, we ignore the exit code but capture the stderr. If | |
# the standard error contains ' is already uploaded', then it must | |
# be the error we dont care about, so we exit the subshell with a | |
# success status. | |
# | |
# All errors start with the form 'error: ', so we detect that and | |
# bail the subshell to crash out on other publish errors. | |
for d in pac/*/ | |
do | |
( | |
cd "${d}" | |
set +e | |
PUBLISH_ERR=$(cargo publish 2>&1 >/dev/null) | |
set -e | |
if [[ "$PUBLISH_ERR" == *" is already uploaded"* ]]; then | |
exit 0 | |
fi | |
if [[ "$PUBLISH_ERR" == *"error: "* ]]; then | |
echo "$PUBLISH_ERR" | |
exit 1 | |
fi | |
) | |
done | |
- name: Release HAL crate | |
if: github.event.inputs.release_hal == 'yes' | |
shell: bash | |
run: | | |
set -ex | |
# Force update of the registry | |
cargo update || true | |
cd "hal" && cargo publish --no-verify | |
- name: Release BSP crates | |
if: github.event.inputs.release_bsp == 'yes' | |
shell: bash | |
run: | | |
set -ex | |
# Force update of the registry | |
cargo update || true | |
sudo apt-get install -y jq | |
# Unfortunately, cargo publish errors if the crate is already uploaded, | |
# and there is no way to turn that off. As a result, we need to do some | |
# janky hacks to detect that condition and ignore it. | |
# | |
# Specifically, we ignore the exit code but capture the stderr. If | |
# the standard error contains ' is already uploaded', then it must | |
# be the error we dont care about, so we exit the subshell with a | |
# success status. | |
# | |
# All errors start with the form 'error: ', so we detect that and | |
# bail the subshell to crash out on other publish errors. | |
for bsp in $(cat crates.json | jq -Mr -c '.boards | keys[]'); | |
do | |
( | |
cd "boards/${bsp}" | |
set +e | |
PUBLISH_ERR=$(cargo publish 2>&1 >/dev/null) | |
set -e | |
if [[ "$PUBLISH_ERR" == *" is already uploaded"* ]]; then | |
exit 0 | |
fi | |
if [[ "$PUBLISH_ERR" == *"error: "* ]]; then | |
echo "$PUBLISH_ERR" | |
exit 1 | |
fi | |
) | |
done |