Merge pull request #851 from axone-protocol/dependabot/github_actions… #1053
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
workflow_call: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
concurrency: | |
group: test-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
name: Create build context | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix-genesis: ${{ steps.matrix-genesis.outputs.config }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Find changed genesis files | |
id: changed-genesis | |
uses: tj-actions/[email protected] | |
with: | |
safe_output: false | |
separator: "," | |
files: | | |
chains/*/genesis.json | |
- name: Setup matrix (for changed genesis) | |
id: matrix-genesis | |
run: | | |
CONFIG="" | |
ALL_MODIFIED_FILES="${{ steps.changed-genesis.outputs.all_modified_files }}" | |
IFS=',' read -r -a GENESISFILES <<< "$ALL_MODIFIED_FILES" | |
for GENESISFILE in "${GENESISFILES[@]}"; do | |
APATH=$(dirname ${GENESISFILE}) | |
NETWORK=$(basename ${APATH}) | |
NAME=$(basename ${GENESISFILE}) | |
CONFIG="${CONFIG:+${CONFIG}, }{\"path\": \"${APATH}\", \"network\": \"${NETWORK}\", \"name\": \"${NAME}\"}" | |
done | |
echo "config=[${CONFIG}]" >> $GITHUB_OUTPUT | |
test-blockchain: | |
if: needs.prepare.outputs.matrix-genesis != '[]' | |
runs-on: ubuntu-22.04 | |
needs: prepare | |
strategy: | |
matrix: | |
context: ${{ fromJson(needs.prepare.outputs.matrix-genesis) }} | |
fail-fast: false | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Initialize blockchain | |
run: | | |
docker run --rm -v ${GITHUB_WORKSPACE}/${{ matrix.context.path }}:/.axoned axoneprotocol/axoned:`cat ./chains/${{ matrix.context.network }}/version.txt` \ | |
keys add validator \ | |
--home /.axoned \ | |
--keyring-backend test | |
jq --arg date "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" '.genesis_time = $date' ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/${{ matrix.context.name }} > ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/${{ matrix.context.name }}-tmp | |
sudo cp ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/${{ matrix.context.name }}-tmp ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/config/genesis.json | |
sudo mkdir -p ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/config/gentx | |
sudo cp ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/gentx/* ${GITHUB_WORKSPACE}/${{ matrix.context.path }}/config/gentx | |
docker run --rm -v ${GITHUB_WORKSPACE}/${{ matrix.context.path }}:/.axoned axoneprotocol/axoned:`cat ./chains/${{ matrix.context.network }}/version.txt` \ | |
genesis add-genesis-account validator 1000000000uaxone \ | |
--home /.axoned \ | |
--keyring-backend test | |
docker run --rm -v ${GITHUB_WORKSPACE}/${{ matrix.context.path }}:/.axoned axoneprotocol/axoned:`cat ./chains/${{ matrix.context.network }}/version.txt` \ | |
genesis gentx validator 1000000uaxone \ | |
--home /.axoned \ | |
--chain-id=axone-${{ matrix.context.network }} \ | |
--keyring-backend test | |
docker run --rm -v ${GITHUB_WORKSPACE}/${{ matrix.context.path }}:/.axoned axoneprotocol/axoned:`cat ./chains/${{ matrix.context.network }}/version.txt` \ | |
genesis collect-gentxs \ | |
--home /.axoned | |
- name: Start the blockchain | |
run: | | |
docker run --network host --rm --name axone-node -v ${GITHUB_WORKSPACE}/${{ matrix.context.path }}:/.axoned axoneprotocol/axoned:`cat ./chains/${{ matrix.context.network }}/version.txt` \ | |
start \ | |
--home /.axoned \ | |
--moniker axone-node & | |
- name: Wait for blockchain to start | |
uses: ifaxity/wait-on-action@v1 | |
with: | |
resource: http://0.0.0.0:26657/status | |
timeout: 20000 # ms | |
- name: Verify blockchain startup | |
run: | | |
STATUS=$(curl http://0.0.0.0:26657/status) | |
CHECK=$(echo $STATUS | jq '.result.validator_info | has("address")') | |
if [ $CHECK != "true" ]; then | |
echo "❌ Blockchain test failed" | |
echo "$STATUS" | |
exit -1 | |
fi | |
- name: Stop the blockchain | |
run: | | |
docker stop axone-node |