Skip to content

Commit

Permalink
Merge pull request #44 from plebhash/trigger-release-lib-automatically
Browse files Browse the repository at this point in the history
Trigger release lib automatically
  • Loading branch information
plebhash committed Apr 2, 2024
2 parents 9ef0f83 + 432ffae commit 6c94d08
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 24 deletions.
39 changes: 15 additions & 24 deletions .github/workflows/release-libs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@
name: Release Libs

on:
push:
pull_request:
branches:
- main

jobs:
libs_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run check-versioning-lib-release.sh
run: |
./check-versioning-lib-release.sh
if [ $? -eq 1 ]; then
echo "Script returned exit code 1, halting the workflow"
exit 1
fi
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
toolchain: stable
override: true
- name: Login
run: cargo login ${{ secrets.CRATES_IO_DEPLOY_KEY }}
- name: Publish crate common
Expand Down Expand Up @@ -135,24 +146,4 @@ jobs:
continue-on-error: true
run: |
cd roles/roles-utils/rpc
cargo publish
- name: Publish crate jd_client
continue-on-error: true
run: |
cargo publish --manifest-path=roles/jd-client/Cargo.toml
- name: Publish crate jd_server
continue-on-error: true
run: |
cargo publish --manifest-path=roles/jd-server/Cargo.toml
- name: Publish crate mining_proxy_sv2
continue-on-error: true
run: |
cargo publish --manifest-path=roles/mining-proxy/Cargo.toml
- name: Publish crate pool_sv2
continue-on-error: true
run: |
cargo publish --manifest-path=roles/pool/Cargo.toml
- name: Publish crate translator_sv2
continue-on-error: true
run: |
cargo publish --manifest-path=roles/translator/Cargo.toml
cargo publish
49 changes: 49 additions & 0 deletions check-versioning-lib-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

git fetch origin main
git fetch origin dev

# Get the list of paths to `Cargo.toml` files
crates=$(find . -name Cargo.toml -exec dirname {} \; | sort)

# Filter out crates that are not published to crates.io
filter=("benches" "examples" "test" "roles")
for crate in $crates; do
filtered=false
for f in "${filter[@]}"; do
if [ "$crate" = "./$f" ]; then
filtered=true
break
fi
done
if [ "$filtered" = false ]; then
filtered_crates+=("$crate")
fi
done

crates="${filtered_crates[@]}"

# Loop through each crate, while avoiding root workspace Cargo.toml and files under `target` directory
for crate in $crates; do
if [ "$crate" != "./protocols" ] && \
[ "$crate" != "./common" ] && \
! echo "$crate" | grep -q "target"; then

cd "$crate"

# Check if there were any changes between dev and main
git diff --quiet "origin/dev" "origin/main" -- .
if [ $? -ne 0 ]; then

# Check if crate versions on dev and main are identical
version_dev=$(git show origin/dev:./Cargo.toml | awk -F' = ' '$1 == "version" {gsub(/[ "]+/, "", $2); print $2}')
version_main=$(git show origin/main:./Cargo.toml | awk -F' = ' '$1 == "version" {gsub(/[ "]+/, "", $2); print $2}')
if [ "$version_dev" = "$version_main" ]; then
echo "Changes detected in crate $crate between dev and main branches! Versions on dev and main branches are identical ($version_dev), so you should bump the crate version on dev before merging into main."
exit 1
fi
fi

cd - >/dev/null
fi
done

0 comments on commit 6c94d08

Please sign in to comment.