Skip to content

Commit

Permalink
[CORE-632] Add workflow to check sample_pregenesis is uptodate; sort …
Browse files Browse the repository at this point in the history
…pregenesis file so ordering is deterministic (#652) (#656)

* add workflow to check sample_pregenesis is uptodate

* reuse protocol Dockerfile

* nit

* nit

* update workflow trigger path

(cherry picked from commit c17e215)

Co-authored-by: Teddy Ding <[email protected]>
  • Loading branch information
mergify[bot] and teddyding authored Oct 18, 2023
1 parent a07e50c commit 3643e0b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/protocol-pregenesis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Protocol Pregenesis

on: # yamllint disable-line rule:truthy
pull_request:
paths:
- protocol/**
push:
branches:
- main
- 'release/protocol/v0.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
paths:
- protocol/**

# Ensure only a single instance of this workflow is running, and cancel any that are in-progress
# before this workflow instance starts
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
check-sample-pregenesis-up-to-date:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- uses: actions/checkout@v3
- name: Check Sample Pregenesis Up-to-date
run: >
make check-sample-pregenesis-up-to-date
9 changes: 7 additions & 2 deletions protocol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ update-swagger-docs: statik
update-sample-pregenesis:
make build
./scripts/genesis/prod_pregenesis.sh build/dydxprotocold
cp /tmp/prod-chain/.dydxprotocol/config/genesis.json ./scripts/genesis/sample_pregenesis.json
cp /tmp/prod-chain/.dydxprotocol/config/sorted_genesis.json ./scripts/genesis/sample_pregenesis.json
@echo "Updated ./scripts/genesis/sample_pregenesis.json"

.PHONY: update-sample-pregenesis
check-sample-pregenesis-up-to-date:
$(MAKE) localnet-build
@docker build . -t check-sample-pregenesis -f scripts/genesis/Dockerfile --no-cache
@docker run -v $(CURDIR):/workspace check-sample-pregenesis

.PHONY: update-sample-pregenesis check-sample-pregenesis-up-to-date
7 changes: 7 additions & 0 deletions protocol/scripts/genesis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM dydxprotocol-base

RUN apk add --no-cache bash dasel jq

WORKDIR /workspace

ENTRYPOINT ["sh", "/workspace/scripts/genesis/check_sample_pregenesis_uptodate.sh"]
16 changes: 7 additions & 9 deletions protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/bin/bash
# This script checks `sample_pregenesis.json` is up to date with the result of running `prod_pregenesis.sh`.
# Usage: % ./scripts/genesis/check_sample_pregenesis_uptodate.sh
# Currently can only be run locally on macOS.
# TODO(CORE-632): Make this script work on CI.
echo "Building binary..."
make build
# Usage: make check-sample-pregenesis-up-to-date

echo "Running prod_pregenesis.sh..."
./scripts/genesis/prod_pregenesis.sh build/dydxprotocold
./scripts/genesis/prod_pregenesis.sh dydxprotocold

diff_output=$(diff "/tmp/prod-chain/.dydxprotocol/config/genesis.json" "./scripts/genesis/sample_pregenesis.json")
echo "Diffing output against current sample_pregenesis.json..."
diff_output=$(diff "/tmp/prod-chain/.dydxprotocol/config/sorted_genesis.json" "./scripts/genesis/sample_pregenesis.json")

if [ -z "$diff_output" ]; then
echo "./scripts/genesis/sample_pregenesis.json is up-to-date"
else
echo "./scripts/genesis/sample_pregenesis.json is not up-to-date"
echo "./scripts/genesis/sample_pregenesis.json is not up-to-date. Run `make update-sample-pregenesis` to update."
echo "$diff_output"
exit 1
fi
fi
7 changes: 6 additions & 1 deletion protocol/scripts/genesis/prod_pregenesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ create_pregenesis_file() {
overwrite_genesis_production
}

sort_genesis_file(){
jq -S . $VAL_CONFIG_DIR/genesis.json > $VAL_CONFIG_DIR/sorted_genesis.json
}

cleanup_tmp_dir
create_pregenesis_file
echo "Wrote pregenesis file to $VAL_CONFIG_DIR/genesis.json"
sort_genesis_file
echo "Wrote pregenesis file to $VAL_CONFIG_DIR/sorted_genesis.json"

0 comments on commit 3643e0b

Please sign in to comment.