-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract inline publish step to separate action
* Create seprate action for publish to crates.io making it simplier to maintain. * Now released crates are not based on lastest change but all will be released.
- Loading branch information
Showing
3 changed files
with
65 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Publish crate | ||
description: Publishes crate to crates.io | ||
inputs: | ||
token: | ||
description: Cargo login token to use the publish the crate | ||
required: true | ||
runs: | ||
using: composite | ||
steps: | ||
- shell: bash | ||
id: publish_crate | ||
run: | | ||
${{ github.action_path }}/publish.sh --token ${{ inputs.token }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Publishes crate to crates.io | ||
|
||
token="" | ||
while true; do | ||
case $1 in | ||
"--token") | ||
shift | ||
token="$1" | ||
shift | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
if [[ "$token" == "" ]]; then | ||
echo "Missing --token <token> option argument, cannot publish crates without it!" && exit 1 | ||
fi | ||
|
||
function publish { | ||
module="$1" | ||
if [[ "$module" == "utoipa" ]]; then | ||
cargo publish | ||
else | ||
cargo publish -p "$module" | ||
fi | ||
} | ||
|
||
echo "$token" | cargo login | ||
while read -r manifest; do | ||
echo "Publishing module $manifest..." | ||
module=$(cargo read-manifest --manifest-path "$manifest" | jq -r .name) | ||
|
||
max_retries=5 | ||
retry=0 | ||
while ! publish "$module" && [[ $retry -lt $max_retries ]]; do | ||
await_time=$((retry*2)) | ||
echo "Failed to publish, Retrying $retry... after $await_time sec." | ||
sleep $await_time | ||
retry=$((retry+1)) | ||
done | ||
if [[ $retry -eq $max_retries ]]; then | ||
echo "Failed to publish crate $module, try to increase await time? Or retries?" && exit 1 | ||
fi | ||
done < <(find . ! -path "*target*" -name "Cargo.toml" | sort -r) |
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