diff --git a/.github/scripts/cargo-toml-match-readme-version.sh b/.github/scripts/cargo-toml-match-readme-version.sh new file mode 100755 index 00000000..773c7edc --- /dev/null +++ b/.github/scripts/cargo-toml-match-readme-version.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +function get_major_version() { + echo "$1" | cut -d '.' -f 1 +} + +function get_minor_version() { + echo "$1" | cut -d '.' -f 2 +} + +function trim_version() { + grep -e "$1" "$2" | cut -d "=" -f 2 | tr -d "\"^ " +} + +function check_versions() { + if [ "$1" != "$2" ]; then + echo "aleph-bft Cargo's toml $3 version $1 different than README.md's $3 version $2!" + exit 1 + fi +} + +cargo_toml_version=$(trim_version '^version =' "Cargo.toml") +cargo_toml_major_version=$(get_major_version "${cargo_toml_version}") +cargo_toml_minor_version=$(get_minor_version "${cargo_toml_version}") + +readme_version=$(trim_version '\s*aleph-bft =' "README.md") +readme_major_version=$(get_major_version "${readme_version}") +readme_minor_version=$(get_minor_version "${readme_version}") + +check_versions "${cargo_toml_major_version}" "${readme_major_version}" "major" +check_versions "${cargo_toml_minor_version}" "${readme_minor_version}" "minor" +echo "Versions from README and Cargo.toml match." diff --git a/.github/scripts/check-cargo-toml-version-bumped.sh b/.github/scripts/check-cargo-toml-version-bumped.sh new file mode 100755 index 00000000..ba0fdf07 --- /dev/null +++ b/.github/scripts/check-cargo-toml-version-bumped.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +if [ -z "$(git diff HEAD origin/main -- src/)" ]; then + echo "No changes in the code." + exit 0 +fi + +if [ -z "$(git diff HEAD origin/main -- Cargo.toml | grep '^+version =')" ]; then + echo "This PR does not change version in Cargo.toml!" + exit 1 +fi diff --git a/.github/workflows/check-version-bumped.yml b/.github/workflows/check-version-bumped.yml new file mode 100644 index 00000000..a06f214f --- /dev/null +++ b/.github/workflows/check-version-bumped.yml @@ -0,0 +1,21 @@ +name: Check if PR has bumbed versions in Cargo.toml for code changes and if README is synchronized + +on: + pull_request: + branches: + - main + +jobs: + check-versions: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: check-cargo-toml-version-bumped + run: ./.github/scripts/check-cargo-toml-version-bumped.sh + shell: bash + - name: cargo-toml-match-readme-version + run: ./.github/scripts/cargo-toml-match-readme-version.sh + shell: bash diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml new file mode 100644 index 00000000..53e56cef --- /dev/null +++ b/.github/workflows/publish-package.yml @@ -0,0 +1,37 @@ +name: Publish to crates.io + +on: + push: + branches: + main + +jobs: + publish: + # need to rename environment name after this is merged + environment: Autobump version + runs-on: ubuntu-latest + if: ${{ github.repository == 'Cardinal-Cryptography/AlephBFT'}} + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 2 + - name: force publish if version bumped + run: | + if [ -n "$(git diff HEAD~ -- Cargo.toml | grep '^+version =')" ]; then + echo "Version in Cargo.toml was bumped in this PR, publishing to crates.io." + touch publishMe + fi + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: credentials + uses: actions-rs/cargo@v1 + with: + command: login + args: ${{ secrets.CRATES_IO_TOKEN }} + - name: publish + run: | + if [ -f publishMe ]; then + echo "cargo publish" + fi diff --git a/.github/workflows/push-foundation-repo.yml b/.github/workflows/push-foundation-repo.yml index 698e8fd0..312b7d90 100644 --- a/.github/workflows/push-foundation-repo.yml +++ b/.github/workflows/push-foundation-repo.yml @@ -1,11 +1,9 @@ name: Sync Cardinal-Cryptography repo with Aleph-Zero-Foundation repo on: - workflow_run: - workflows: ["Autobump version"] - branches: [main] - types: - - completed + push: + branches: + main jobs: sync: diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml deleted file mode 100644 index e7fe56c3..00000000 --- a/.github/workflows/version-bump.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Autobump version - -on: - push: - branches: - - main - -jobs: - autobump: - environment: Autobump version - runs-on: ubuntu-latest - if: ${{ github.repository == 'Cardinal-Cryptography/AlephBFT'}} - steps: - - name: checkout - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - name: bump - run: | - version=`grep -e '^version =' Cargo.toml | sed 's/version = //' | sed 's/"//g'` - major_version=`echo $version|grep -o -e '^[0-9]*'` - minor_version=`echo $version|grep -o -e '^[0-9]*.[0-9]*'|grep -o -e '[0-9]*$'` - patch_version=`echo $version|grep -o -e '[0-9]*$'` - git config user.email "<>" - git config user.name "Version autobump" - if git diff HEAD~ -- Cargo.toml | grep -q '^+version ='; then - echo 'Version has been bumped manually, bumping readme version and uploading to crates.io' - new_version=$major_version.$minor_version - sed -i "s/aleph-bft = \"\^[0-9]*.[0-9]*\"$/aleph-bft = \"^$new_version\"/" README.md - git add README.md - git commit --amend --no-edit - git push -f origin main - touch publishMe - exit 0 - fi - if [ -e `git diff HEAD~ -- src/` ]; then - echo 'No changes in code.' - exit 0 - fi - new_version=$major_version.$minor_version.$((patch_version + 1)) - sed -i "s/^version = \"$version\"$/version = \"$new_version\"/" Cargo.toml - git add Cargo.toml - git commit --amend --no-edit - git push -f origin main - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - name: credentials - uses: actions-rs/cargo@v1 - with: - command: login - args: ${{ secrets.CRATES_IO_TOKEN }} - - name: publish - run: | - if [ -f publishMe ]; then - cargo publish - fi diff --git a/Cargo.lock b/Cargo.lock index 773a361b..a7f6e711 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,7 +65,7 @@ dependencies = [ [[package]] name = "aleph-bft" -version = "0.8.0" +version = "0.8.2" dependencies = [ "async-trait", "bit-vec", diff --git a/README.md b/README.md index 6f2c3eb8..00910ab4 100644 --- a/README.md +++ b/README.md @@ -204,3 +204,4 @@ The implementation in this repository is funded by [Aleph Zero Foundation][webpa [old-paper-link]: https://arxiv.org/abs/1810.05256 [aleph-node-link]: https://github.com/Cardinal-Cryptography/aleph-node [webpage-link]: https://alephzero.org + diff --git a/src/nodes.rs b/src/nodes.rs index 0f4fddd0..d4ad7a74 100644 --- a/src/nodes.rs +++ b/src/nodes.rs @@ -1,3 +1,4 @@ + use codec::{Decode, Encode, Error, Input, Output}; use derive_more::{Add, AddAssign, From, Into, Sub, SubAssign, Sum}; use std::{