Skip to content

Commit

Permalink
Merge branch 'develop' into refactor-create-chains-orchestrator-zetac…
Browse files Browse the repository at this point in the history
…ore-package
  • Loading branch information
ws4charlie authored May 16, 2024
2 parents 1def779 + 9394bbb commit 169d3ee
Show file tree
Hide file tree
Showing 90 changed files with 3,217 additions and 472 deletions.
8 changes: 7 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ package.json
yarn.lock
.github/
.gitignore
dist/**
dist/**

# dockerfiles are not needed inside the docker build
Dockerfile
Dockerfile-localnet
Dockerfile-upgrade
docker-compose*.yml
135 changes: 135 additions & 0 deletions .github/actions/release-status-checker/check_and_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import requests
import time
import logging
import os
from github import Github
from datetime import datetime, timezone, timedelta
import sys

# Setup logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

STATUS_ENDPOINT = os.environ["STATUS_ENDPOINT"]
PROPOSALS_ENDPOINT = os.environ["PROPOSAL_ENDPOINT"]


def get_current_block_height():
response = requests.get(STATUS_ENDPOINT)
response.raise_for_status()
data = response.json()
return int(data['result']['sync_info']['latest_block_height'])


def get_proposals():
response = requests.get(PROPOSALS_ENDPOINT)
response.raise_for_status()
data = response.json()
return [proposal['id'] for proposal in data['proposals']]


def get_proposal_details(proposal_id):
url = f"{PROPOSALS_ENDPOINT}/{proposal_id}"
response = requests.get(url)
response.raise_for_status()
data = response.json()
return data


def is_older_than_one_week(submit_time_str):
submit_time_str = submit_time_str.split('.')[0] + 'Z'
submit_time = datetime.strptime(submit_time_str, '%Y-%m-%dT%H:%M:%S%z')
current_time = datetime.now(timezone.utc)
return current_time - submit_time > timedelta(weeks=1)


def monitor_block_height(proposal_height):
max_checks = int(os.environ["MAX_WAIT_FOR_PROCESSING_BLOCKS_CHECK"])
checks = 0
while checks < max_checks:
current_height = get_current_block_height()
if current_height >= proposal_height:
for _ in range(50):
prev_height = current_height
time.sleep(3)
current_height = get_current_block_height()
if current_height > prev_height:
logger.info("Block height is moving. Network is processing blocks.")
return True
logger.warning("Network is not processing blocks.")
return False
checks += 1
time.sleep(3)
logger.warning("Max wait time reached. Proposal height not reached.")
return False


def update_github_release(proposal_title):
github_token = os.environ["GITHUB_TOKEN"]
g = Github(github_token)
repo = g.get_repo("zeta-chain/node")
releases = repo.get_releases()
for release in releases:
if release.title == proposal_title and release.prerelease:
release.update_release(release.title, release.body, draft=False, prerelease=False)
logger.info(f"Updated GitHub release '{proposal_title}' from pre-release to release.")
return
logger.warning(f"No matching GitHub pre-release found for title '{proposal_title}'.")


def main():
current_block_height = get_current_block_height()
logger.info(f"Current Block Height: {current_block_height}")
proposals_retrieved = get_proposals()
proposals = {}

for proposal_id in proposals_retrieved:
proposal_details = get_proposal_details(proposal_id)

submit_time_str = proposal_details["proposal"]["submit_time"]
if is_older_than_one_week(submit_time_str):
logger.info(f"Proposal {proposal_id} is older than one week. Skipping.")
continue

for message in proposal_details["proposal"]["messages"]:
if "content" not in message:
continue
proposal_type = message["content"]["@type"]
logger.info(f"id: {proposal_id}, proposal type: {proposal_type}")
if "plan" not in message["content"]:
continue
if proposal_details["proposal"]["status"] != "PROPOSAL_STATUS_PASSED":
logger.info(f'Proposal did not pass: {proposal_details["proposal"]["status"]}')
continue
if 'SoftwareUpgradeProposal' in str(proposal_type) or 'MsgSoftwareUpgrade' in str(proposal_type):
proposals[proposal_id] = {
"proposal_height": int(message["content"]["plan"]["height"]),
"proposal_title": message["content"]["title"]
}
break
if len(proposals) <= 0:
logger.info("No proposals found within the timeframe.")
sys.exit(0)
for proposal_id, proposal_data in proposals.items():
if current_block_height >= proposal_data["proposal_height"]:
logger.info(f"Proposal {proposal_id} height {proposal_data['proposal_height']} has been reached.")
update_github_release(proposal_data["proposal_title"])
else:
logger.info(
f"Waiting for proposal {proposal_id} height {proposal_data['proposal_height']} to be reached. Current height: {current_block_height}")
if monitor_block_height(proposal_data['proposal_height']):
logger.info(
f"Proposal {proposal_id} height {proposal_data['proposal_height']} has been reached and network is processing blocks.")
update_github_release(proposal_data["proposal_title"])
else:
logger.warning(
f"Failed to reach proposal {proposal_id} height {proposal_data['proposal_height']} or network is not processing blocks.")


if __name__ == "__main__":
main()
26 changes: 12 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:

jobs:
build-and-test:
runs-on: buildjet-4vcpu-ubuntu-2004
runs-on: ubuntu-22.04
timeout-minutes: 15
concurrency:
group: "build-and-test"
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
run: rm -rf *

e2e-test:
runs-on: buildjet-4vcpu-ubuntu-2204
runs-on: ubuntu-22.04
timeout-minutes: 25
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -125,23 +125,21 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_READ_ONLY }}

- name: Build zetanode
run: |
make zetanode
- name: Start Test
run: make start-e2e-test

- name: Start Private Network
# use docker logs -f rather than docker attach to make sure we get the initial logs
- name: Watch Test
run: |
cd contrib/localnet/
docker compose up -d zetacore0 zetacore1 zetaclient0 zetaclient1 eth bitcoin
container_id=$(docker ps --filter "ancestor=orchestrator:latest" --format "{{.ID}}")
docker logs -f "${container_id}" &
exit $(docker wait "${container_id}")
- name: Run E2E Test
- name: Full Log Dump On Failure
if: failure()
run: |
cd contrib/localnet
docker-compose up orchestrator --exit-code-from orchestrator
if [ $? -ne 0 ]; then
echo "E2E Test Failed"
exit 1
fi
docker compose logs
- name: Notify Slack on Failure
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/develop'
Expand Down
70 changes: 6 additions & 64 deletions .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ jobs:
with:
fetch-depth: 0

- name: Set Version from the PR title.
- name: Set Version from the release title.
if: github.event_name != 'workflow_dispatch'
run: |
LATEST_RELEASE=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/latest)
RELEASE_TITLE=$(echo $LATEST_RELEASE | jq -r .name)
echo "Latest release title: $RELEASE_TITLE"
echo "GITHUB_TAG_MAJOR_VERSION=$RELEASE_TITLE" >> $GITHUB_ENV
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.release.name }}" >> $GITHUB_ENV
- name: Set Version for Hotfix Release from Input.
if: github.event_name != 'pull_request'
if: github.event_name == 'workflow_dispatch'
run: |
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.inputs.version }}" >> ${GITHUB_ENV}
Expand All @@ -58,54 +53,6 @@ jobs:
DOCKER_BUILD_KIT: "0"
TAG_LATEST: "true"

docker_build_mac:
runs-on: macos-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set Version from the PR title.
if: github.event_name != 'workflow_dispatch'
run: |
LATEST_RELEASE=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/latest)
RELEASE_TITLE=$(echo $LATEST_RELEASE | jq -r .name)
echo "Latest release title: $RELEASE_TITLE"
echo "GITHUB_TAG_MAJOR_VERSION=$RELEASE_TITLE" >> $GITHUB_ENV
- name: Set Version for Hotfix Release from Input.
if: github.event_name != 'pull_request'
run: |
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.inputs.version }}" >> ${GITHUB_ENV}
- name: Setup docker and docker-compose (missing on MacOS)
if: runner.os == 'macos'
run: |
brew install docker docker-compose
# Link the Docker Compose v2 plugin so it's understood by the docker CLI
mkdir -p ~/.docker/cli-plugins
ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
colima start
- name: "BUILD:PUSH:MONITORING:DOCKER:IMAGE"
uses: ./.github/actions/build-docker-images-generic
with:
DOCKER_FILENAME: "Dockerfile"
REPOSITORY_NAME: "${{ env.DOCKER_REPO }}"
IMAGE_TAG: "mac-${{ env.GITHUB_TAG_MAJOR_VERSION }}"
REGISTRY: "${{ env.DOCKER_REGISTRY }}"
DOCKER_ORG: "${{ env.DOCKER_ORG }}"
USERNAME: "${{ secrets.DOCKER_HUB_USERNAME }}"
TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}"
DOCKER_FILE_DIRECTORY: "./"
DOCKER_BUILD_KIT: "0"
TAG_LATEST: "false"

docker_build_arm:
runs-on: buildjet-4vcpu-ubuntu-2204-arm
timeout-minutes: 30
Expand All @@ -114,18 +61,13 @@ jobs:
with:
fetch-depth: 0

- name: Set Version from the PR title.
- name: Set Version from the release title.
if: github.event_name != 'workflow_dispatch'
run: |
LATEST_RELEASE=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/latest)
RELEASE_TITLE=$(echo $LATEST_RELEASE | jq -r .name)
echo "Latest release title: $RELEASE_TITLE"
echo "GITHUB_TAG_MAJOR_VERSION=$RELEASE_TITLE" >> $GITHUB_ENV
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.release.name }}" >> $GITHUB_ENV
- name: Set Version for Hotfix Release from Input.
if: github.event_name != 'pull_request'
if: github.event_name == 'workflow_dispatch'
run: |
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.inputs.version }}" >> ${GITHUB_ENV}
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/execute_advanced_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jobs:
container_id=$(docker ps --filter "ancestor=orchestrator:latest" --format "{{.ID}}")
docker logs -f "${container_id}" &
exit $(docker wait "${container_id}")
- name: Full Log Dump On Failure
if: failure()
run: |
cd contrib/localnet
docker compose logs
- name: Notify Slack on Failure
if: failure() && github.event_name == 'schedule'
Expand Down Expand Up @@ -73,6 +79,12 @@ jobs:
docker logs -f "${container_id}" &
exit $(docker wait "${container_id}")
- name: Full Log Dump On Failure
if: failure()
run: |
cd contrib/localnet
docker compose logs
- name: Notify Slack on Failure
if: failure() && github.event_name == 'schedule'
uses: 8398a7/action-slack@v3
Expand All @@ -99,6 +111,12 @@ jobs:
docker logs -f "${container_id}" &
exit $(docker wait "${container_id}")
- name: Full Log Dump On Failure
if: failure()
run: |
cd contrib/localnet
docker compose logs
e2e-performance-test:
if: ${{ github.event.inputs.e2e-performance-test == 'true' }}
runs-on: buildjet-4vcpu-ubuntu-2204
Expand All @@ -114,4 +132,10 @@ jobs:
run: |
container_id=$(docker ps --filter "ancestor=orchestrator:latest" --format "{{.ID}}")
docker logs -f "${container_id}" &
exit $(docker wait "${container_id}")
exit $(docker wait "${container_id}")
- name: Full Log Dump On Failure
if: failure()
run: |
cd contrib/localnet
docker compose logs
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- name: Run Gosec Security Scanner
if: ${{ github.event.inputs.skip_checks != 'true' }}
uses: securego/gosec@master
uses: securego/gosec@v2.19.0
with:
args: ./...

Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/release-status-changer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "RELEASE:STATUS:UPDATER"

on:
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:

jobs:
run-script:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install requests PyGithub
- name: Execute Status Check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STATUS_ENDPOINT: "https://zetachain-mainnet.g.allthatnode.com/archive/tendermint/status"
PROPOSAL_ENDPOINT: "https://zetachain-mainnet.g.allthatnode.com/archive/rest/cosmos/gov/v1/proposals"
MAX_WAIT_FOR_PROCESSING_BLOCKS_CHECK: "500"
run: |
python .github/actions/release-status-checker/check_and_update.py
Loading

0 comments on commit 169d3ee

Please sign in to comment.