From 9fc4736f7388a18baad4e49d35b0d09e22416e3e Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Sun, 4 Feb 2024 16:41:00 -0300 Subject: [PATCH] Add cron job to check for new Octez versions --- .github/workflows/dockerhub.yml | 2 +- .github/workflows/ghcr.yml | 4 +-- .github/workflows/octez_version.yml | 19 ++++++++++++++ .github/workflows/tag.yml | 15 +++++++++++ Makefile | 5 +++- octez_version | 0 octez_version.py | 40 +++++++++++++++++++++++++++++ 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/octez_version.yml create mode 100644 .github/workflows/tag.yml create mode 100644 octez_version create mode 100644 octez_version.py diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index b968f49..c6567e5 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -1,4 +1,4 @@ -name: Build +name: Publish on Docker Hub on: push: diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml index 638a4b7..fead63c 100644 --- a/.github/workflows/ghcr.yml +++ b/.github/workflows/ghcr.yml @@ -1,9 +1,9 @@ -name: Build +name: Publish on GHCR on: push: tags: - - '*' + - 'v*' jobs: build: diff --git a/.github/workflows/octez_version.yml b/.github/workflows/octez_version.yml new file mode 100644 index 0000000..dadb818 --- /dev/null +++ b/.github/workflows/octez_version.yml @@ -0,0 +1,19 @@ +name: Check Octez version + +on: + schedule: + - cron: '0 0 * * *' + # REMOVE + push: + branches: + - aux/octez-version-checker + +jobs: + octez_version: + name: Check the latest Octez release + runs-on: ubuntu-latest + steps: + - name: Install python-requests + run: sudo apt-get install python3-requests + - name: make octez_version + run: make octez_version \ No newline at end of file diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..f69a4ed --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,15 @@ +name: Tag the current Octez release + + +on: + push: + branches: + - 'master' + +jobs: + build: + name: Force push tag of the current Octez release + runs-on: ubuntu-latest + steps: + - name: make release + run: make release \ No newline at end of file diff --git a/Makefile b/Makefile index ad47e91..147c5f3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TAG=v19.0-1 +TAG=`cat octez_version` build: @@ -9,3 +9,6 @@ run: release: git tag $(TAG) -f && git push origin $(TAG) --force + +octez_version: + python3 octez_version.py diff --git a/octez_version b/octez_version new file mode 100644 index 0000000..e69de29 diff --git a/octez_version.py b/octez_version.py new file mode 100644 index 0000000..fa31eee --- /dev/null +++ b/octez_version.py @@ -0,0 +1,40 @@ +from pathlib import Path +import requests +from os import environ as env +import subprocess + +def run(*args, **kwargs): + print(f"$ {' '.join(args)}") + subprocess.run(args, check=True, **kwargs) + + +OCTEZ_REPO_URL = 'https://github.com/serokell/tezos-packaging/releases/latest' + + +def main(): + + version_file = Path('octez_version') + current_version = version_file.read_text().strip() if version_file.exists() else '' + print(f'Current version: {current_version}') + latest_version = requests.get(OCTEZ_REPO_URL).url.split("/")[-1] + print(f'Latest version: {latest_version}') + + if current_version == latest_version: + return + + if not env.get("GITHUB_ACTIONS"): + print("This script is intended to be run in a GitHub Action.") + exit(1) + + print('Octez version has changed. Updating...') + Path('octez_version').write_text(latest_version) + + run('make', 'build') + run('git', 'checkout', '-b', f'octez-{latest_version}') + run('git', 'add', 'octez_version') + run('git', 'commit', '-m', f'Update Octez binaries to {latest_version}') + + + +if __name__ == "__main__": + main() \ No newline at end of file