diff --git a/.github/workflows/protocol-pregenesis.yml b/.github/workflows/protocol-pregenesis.yml new file mode 100644 index 0000000000..44bbcd1430 --- /dev/null +++ b/.github/workflows/protocol-pregenesis.yml @@ -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 diff --git a/protocol/Makefile b/protocol/Makefile index 68d755a851..0ceef16a91 100644 --- a/protocol/Makefile +++ b/protocol/Makefile @@ -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 diff --git a/protocol/scripts/genesis/Dockerfile b/protocol/scripts/genesis/Dockerfile new file mode 100644 index 0000000000..221b58e4dc --- /dev/null +++ b/protocol/scripts/genesis/Dockerfile @@ -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"] diff --git a/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh b/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh index f2a79f5edc..1eb888b7e8 100755 --- a/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh +++ b/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh @@ -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 \ No newline at end of file +fi diff --git a/protocol/scripts/genesis/prod_pregenesis.sh b/protocol/scripts/genesis/prod_pregenesis.sh index dbc7dc6649..af0da31421 100755 --- a/protocol/scripts/genesis/prod_pregenesis.sh +++ b/protocol/scripts/genesis/prod_pregenesis.sh @@ -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"