Skip to content
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
50 changes: 50 additions & 0 deletions .github/workflows/prepare-version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Autobump version on PR

on:
pull_request:
branches:
- main

jobs:
prepare-new-version:
environment: Autobump version
runs-on: ubuntu-latest
if: ${{ github.repository == 'Cardinal-Cryptography/AlephBFT'}}
steps:
- name: cargo-next-install
run: |
cargo install cargo-next --locked
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
ref: ${{ github.head_ref }}
token: ${{ secrets.SYNCAZF || secrets.MY_TOKEN || github.token }}
- name: check-and-bump
run: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this block can be made into sh script (and put somewhere in the scripts/... folder). This way it will be more readable here and easier to review the script without the noise from the workflow file.

old_version=`cargo next --get`
# If version on PR branch and main branch have no differences in version -> bump it.
# Set version in README.md, commit, tag and push to PR branch.
# Assuming nominal version for us is the one in the top level Cargo.toml.
if ! git diff ${{ github.head_ref }} ${{ github.base_ref }} -- Cargo.toml | grep -q '^+version ='; then
echo "Version $old_version has NOT been changed manually between ${{ github.head_ref }} and ${{ github.base_ref }}, patching it now."
cargo next --patch
new_version=`cargo next --get`
echo "New version is $new_version."
git add Cargo.toml
fi
new_version=`cargo next --get`
# Make sure README has the same version as Cargo.toml.
sed -i "s/^version = \"$version\"$/version = \"$new_version\"/" Cargo.toml
git add README.md
# Publishing changes to PR branch
git config user.email "<>"
git config user.name "Version autobump"
git commit -m "Setting version to $new_version"
# Create tag with version if it not exist.
if ! git rev-parse "$new_version" >/dev/null 2>&1; then
git tag -a $new_version -m "Version $new_version created at PR ${{ github.head_ref }} -> ${{ github.base_ref }}"
fi
- name: push-to-PR
run: |
git push --follow-tags
28 changes: 22 additions & 6 deletions .github/workflows/push-foundation-repo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Sync Cardinal-Cryptography repo with Aleph-Zero-Foundation repo
name: Sync Cardinal-Cryptography repo with Aleph-Zero-Foundation repo and publishes AlephBFT main to crates.io.

on:
workflow_run:
workflows: ["Autobump version"]
branches: [main]
types:
- completed
# NOTE: changed to "manual workflow dispatch" for now.
# TODO: To be automated again, when workflows stabilize
# and pushes to main origin will be forbidden.
workflow_dispatch:

# workflow_run:
# workflows: ["Autobump version"]
# branches: [main]
# types:
# - completed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By purpose - see note above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why we have git though – if someone wants to see what once was here they can use history. Commented code is just confusing too often.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not about history - commented code is left there, because it is the right code to be enabled in the future, when workflows stabilize.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but keeping commented code is always confusing. I would rather trust the person who will enable the automation here to do this correctly. If they need help one of the options is to look in the history, that's what I meant by it staying there.


jobs:
sync:
Expand All @@ -19,3 +24,14 @@ jobs:
token: ${{ secrets.SYNCAZF }}
- name: Push to Aleph-Zero-Foundation
run: git push https://x-access-token:${{ secrets.SYNCAZF }}@github.com/aleph-zero-foundation/AlephBFT.git
- 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: |
cargo publish
37 changes: 3 additions & 34 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,6 @@ jobs:
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
Expand All @@ -52,6 +21,6 @@ jobs:
args: ${{ secrets.CRATES_IO_TOKEN }}
- name: publish
run: |
if [ -f publishMe ]; then
cargo publish
fi
echo 'Uploading to crates.io'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I'm confused now, this always pushes to crates.io?

Anyway, you probably want to rename this file? It seems there was some naming confusion here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow is invoked right now only manually, so yes, if you invoke it manually, it will publish every time it will be called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, although maybe it's just my lack of understanding of workflows – this file seems to imply it will always run on push to main, the other file states it only runs manually. And the other one also publishes. Shouldn't this file just be deleted then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I did some clean up. See 4339e93. Workflow should be like this:

  1. On PR creation to main -> prepare-version-bump.yml
  2. Manually (for now) -> version-bump.yml
  3. On (2) -> push-foundation-repo.yml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that seems good now. I still have some gripes with naming – maybe call this one something like "Publish to crates.io" rather than "Autobump version"? Similar for file names, what is now called "prepare-..." should just be "version-bump" and this one "publish" or something.

cargo publish

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-bft"
version = "0.8.2"
version = "0.8.3"
edition = "2018"
authors = ["Cardinal Cryptography"]
categories = ["algorithms", "data-structures", "cryptography", "database"]
Expand Down