Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add release-libs.sh #69

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 48 additions & 74 deletions .github/workflows/release-libs.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# This workflow is used to publish SV2 crates to crates.io
# The workflow tries to update all the library crates, so if a crate is not to updated, the step will fail
# for that each step have continue-on-error set to true.
# Since each step can fail, the output ot the action must be manually checked to make sure that all
# the library intended to be published are published.
# Running cargo release in the various workspace help to prepare the version number and everything.
# ATTENTION
# Is very important to check the output manually cause when too many crates are updated crates.io could fail
# and ask to rerun the action later
# the workflow tries to publish all the library crates by running scripts/release-libs.sh
# in case the `cargo publish` command fails, the script returns 1 and the entire workflow fails
# the only exception is when the `cargo publish` command fails due to the crate already
# being published, in which case the workflow continues

name: Release Libs

Expand All @@ -32,113 +28,91 @@ jobs:
override: true
- name: Login
run: cargo login ${{ secrets.CRATES_IO_DEPLOY_KEY }}

- name: Publish crate common
continue-on-error: true
run: |
cd common
cargo publish
./scripts/release-libs.sh common --dry-run

- name: Publish crate buffer_sv2
continue-on-error: true
run: |
cd utils/buffer
cargo publish
./scripts/release-libs.sh utils/buffer --dry-run

- name: Publish crate no_serde_sv2_derive_codec
continue-on-error: true
run: |
cd protocols/v2/binary-sv2/no-serde-sv2/derive_codec
cargo publish
./scripts/release-libs.sh protocols/v2/binary-sv2/no-serde-sv2/derive_codec --dry-run

- name: Publish crate no_serde_sv2_codec
continue-on-error: true
run: |
cd protocols/v2/binary-sv2/no-serde-sv2/codec
cargo publish
./scripts/release-libs.sh protocols/v2/binary-sv2/no-serde-sv2/codec --dry-run

- name: Publish crate serde_sv2
continue-on-error: true
run: |
cd protocols/v2/binary-sv2/serde-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/binary-sv2/serde-sv2 --dry-run

- name: Publish crate binary_sv2
continue-on-error: true
run: |
cd protocols/v2/binary-sv2/binary-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/binary-sv2/binary-sv2 --dry-run

- name: Publish crate const_sv2
continue-on-error: true
run: |
cd protocols/v2/const-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/const-sv2 --dry-run

- name: Publish crate framing_sv2
continue-on-error: true
run: |
cd protocols/v2/framing-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/framing-sv2 --dry-run

- name: Publish crate noise_sv2
continue-on-error: true
run: |
cd protocols/v2/noise-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/noise-sv2 --dry-run

- name: Publish crate codec_sv2
continue-on-error: true
run: |
cd protocols/v2/codec-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/codec-sv2 --dry-run

- name: Publish crate common_messages
continue-on-error: true
run: |
cd protocols/v2/subprotocols/common-messages
cargo publish
./scripts/release-libs.sh protocols/v2/subprotocols/common-messages --dry-run

- name: Publish crate job_declaration
continue-on-error: true
run: |
cd protocols/v2/subprotocols/job-declaration
cargo publish
./scripts/release-libs.sh protocols/v2/subprotocols/job-declaration --dry-run

- name: Publish crate mining
continue-on-error: true
run: |
cd protocols/v2/subprotocols/mining
cargo publish
./scripts/release-libs.sh protocols/v2/subprotocols/mining --dry-run

- name: Publish crate template_distribution
continue-on-error: true
run: |
cd protocols/v2/subprotocols/template-distribution
cargo publish
./scripts/release-libs.sh protocols/v2/subprotocols/template-distribution --dry-run

- name: Publish crate sv2_ffi
continue-on-error: true
run: |
cd protocols/v2/sv2-ffi
cargo publish --all-features
./scripts/release-libs.sh protocols/v2/sv2-ffi --dry-run

- name: Publish crate roles_logic_sv2
continue-on-error: true
run: |
cd protocols/v2/roles-logic-sv2
cargo publish
./scripts/release-libs.sh protocols/v2/roles-logic-sv2 --dry-run

- name: Publish crate v1
continue-on-error: true
run: |
cd protocols/v1
cargo publish
./scripts/release-libs.sh protocols/v1 --dry-run

- name: Publish crate bip32-key-derivation
continue-on-error: true
run: |
cd utils/bip32-key-derivation
cargo publish
./scripts/release-libs.sh utils/bip32-key-derivation --dry-run

- name: Publish crate error-handling
continue-on-error: true
run: |
cd utils/error-handling
cargo publish
./scripts/release-libs.sh utils/error-handling --dry-run

- name: Publish crate key-utils
continue-on-error: true
run: |
cd utils/key-utils
cargo publish
./scripts/release-libs.sh utils/key-utils --dry-run

- name: Publish crate network_helpers_sv2
continue-on-error: true
run: |
cd roles/roles-utils/network-helpers
cargo publish
./scripts/release-libs.sh roles/roles-utils/network-helpers --dry-run

- name: Publish crate rpc_sv2
continue-on-error: true
run: |
cd roles/roles-utils/rpc
cargo publish
./scripts/release-libs.sh roles/roles-utils/rpc --dry-run
51 changes: 51 additions & 0 deletions scripts/release-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

# USAGE:
# ./scripts/cargo-publish.sh <crate-dir> [--dry-run]
#
# If --dry-run is provided, the script runs cargo publish --dry-run,
# otherwise it performs a real publish.

CRATE_DIR="$1"
DRY_FLAG="${2:-}"

echo "Publishing crate in directory: $CRATE_DIR"

cd "$CRATE_DIR"

if [ "$DRY_FLAG" = "--dry-run" ]; then
echo "Dry run enabled. Will not actually publish to crates.io."
CARGO_COMMAND="cargo publish --dry-run"
else
CARGO_COMMAND="cargo publish"
fi

OUTPUT="$($CARGO_COMMAND 2>&1)"
EXIT_CODE=$?
echo "Ran cargo command, exit code was $EXIT_CODE"

if [ "$DRY_FLAG" = "--dry-run" ]; then
if [ "$EXIT_CODE" -eq 0 ]; then
echo "Dry-run succeeded; nothing was actually published."
exit 0
fi
# If it failed under --dry-run, handle error or log accordingly:
echo "Dry-run failed for $CRATE_DIR."
echo "$OUTPUT"
exit 1
fi

if [ "$EXIT_CODE" -eq 0 ] ; then
echo "Publish command succeeded: $CRATE_DIR"
exit 0
fi

# If cargo failed, check whether it was 'already uploaded'
if echo "$OUTPUT" | grep -q "already uploaded"; then
echo "Crate is already published: $CRATE_DIR"
exit 0
fi

echo "Publish command failed for $CRATE_DIR"
echo "$OUTPUT"
exit 1
Loading