Skip to content

Commit

Permalink
Merge pull request #170 from sacherjj/ci_changes_and_crates_publish
Browse files Browse the repository at this point in the history
Setup crates.io and cleaning up other CI
  • Loading branch information
sacherjj authored Aug 17, 2023
2 parents cb744f6 + 30715c3 commit d33c756
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/publish-casper-event-sidecar-crates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: publish-casper-event-sidecar-crates

on:
push:
tags:
- "v*"

jobs:
publish-crates:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2
- uses: actions-rs/toolchain@v1

- name: update toolchain
run: rustup update nightly

- name: Publish Crates
env:
CARGO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: ./ci/publish_to_crates_io.sh
4 changes: 1 addition & 3 deletions .github/workflows/publish-casper-event-sidecar-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-18.04
code_name: bionic
- os: ubuntu-20.04
code_name: focal
- os: ubuntu-22.04
Expand Down Expand Up @@ -78,4 +76,4 @@ jobs:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/debian/casper-event-sidecar/*
tag: ${{ github.ref }}
file_glob: true
file_glob: true
Empty file modified ci/publish_deb_to_repo.sh
100644 → 100755
Empty file.
65 changes: 65 additions & 0 deletions ci/publish_to_crates_io.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -eu -o pipefail

CRATES_URL=https://crates.io/api/v1/crates
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd)"

run_curl() {
set +e
CURL_OUTPUT=$(curl -s $1)
set -e
local EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]; then
printf "curl -s %s failed with exit code %d\n\n" $1 $EXIT_CODE
exit 1
fi
}

max_version_in_crates_io() {
local CRATE=$1
printf "Max published version: "
run_curl "$CRATES_URL/$CRATE"
if [[ "$CURL_OUTPUT" == "{\"errors\":[{\"detail\":\"Not Found\"}]}" ]]; then
CRATES_IO_VERSION="N/A (not found in crates.io)"
else
CRATES_IO_VERSION=$(echo "$CURL_OUTPUT" | jq -r .crate.max_version)
fi
printf "%s\n" "$CRATES_IO_VERSION"
}

publish() {
CRATE_DIR="$1"
local CRATE_DIR
pushd "$ROOT_DIR/$CRATE_DIR" >/dev/null

CRATE_NAME=$(cargo read-manifest | jq -r '.name' | tr -d '\n')
local CRATE_NAME
printf "%s\n" "$CRATE_NAME"

max_version_in_crates_io "$CRATE_NAME"

printf "Local version: "
LOCAL_VERSION=$(cargo read-manifest | jq -r '.version' | tr -d '\n')
printf "%s\n$LOCAL_VERSION"

if [[ "$LOCAL_VERSION" == "$CRATES_IO_VERSION" ]]; then
printf "Skipping\n"
else
printf "Publishing...\n"
set +u
cargo publish "${@:2}" --token "${CARGO_TOKEN}"
set -u
printf "Published version %s\n$LOCAL_VERSION"
printf "Sleeping for 60 seconds...\n"
sleep 60
fi
printf "================================================================================\n\n"
popd >/dev/null
}

# These are the subdirs of casper-node which contain packages for publishing. They should remain ordered from
# least-dependent to most.
publish types
publish listener
publish sidecar

0 comments on commit d33c756

Please sign in to comment.