From 1bb29c6441ac46727f671af983cc534143d18b7e Mon Sep 17 00:00:00 2001 From: hestonhoffman Date: Wed, 2 Oct 2024 08:55:55 -0700 Subject: [PATCH 1/3] (maint) Prevent workflow from failing on no change --- .../bump_synthetics_worker_version.yml | 5 ++++- local/bin/py/version_getter.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bump_synthetics_worker_version.yml b/.github/workflows/bump_synthetics_worker_version.yml index a244d25132eac..da5a2f2688b4a 100644 --- a/.github/workflows/bump_synthetics_worker_version.yml +++ b/.github/workflows/bump_synthetics_worker_version.yml @@ -22,13 +22,15 @@ jobs: - run: pip install requests semver defusedxml - name: Find latest synthetic-worker version + id: write-synthetics-worker-version run: | - python local/bin/py/version_getter.py + python local/bin/py/version_getter.py - uses: actions/checkout@v4 with: persist-credentials: false - name: Write version + if: steps.write-synthetics-worker-version.outputs.new_version == 'true' run: |- git config user.name documentation-ci git config user.email documentation-ci@datadoghq.com @@ -38,6 +40,7 @@ jobs: - uses: actions/github-script@v7 name: Propose change with latest versions + if: steps.write-synthetics-worker-version.outputs.new_version == 'true' with: github-token: ${{secrets.GITHUB_TOKEN}} result-encoding: string diff --git a/local/bin/py/version_getter.py b/local/bin/py/version_getter.py index cb87f0fd8a1c4..4ee4aed593573 100755 --- a/local/bin/py/version_getter.py +++ b/local/bin/py/version_getter.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import re +import os import json from io import StringIO import requests @@ -60,11 +61,24 @@ def get_versions(keys): Currently only supports synthetics-windows-pl ''' if __name__ == "__main__": + github_output = os.getenv('GITHUB_OUTPUT') PRODUCTS = ["synthetics-windows-pl"] data = get_data() keys = get_keys(data) + try: + current_versions = json.load(open('data/synthetics_worker_versions.json')) + except: + current_versions = {} + print(current_versions) final_versions = get_versions(keys) + print(final_versions) - with open('data/synthetics_worker_versions.json', 'w') as f: - f.write(json.dumps(final_versions, indent=4, sort_keys=True)) + if current_versions != final_versions: + with open('data/synthetics_worker_versions.json', 'w') as f: + f.write(json.dumps(final_versions, indent=4, sort_keys=True)) + with open(github_output, 'a', encoding='utf-8') as f: + f.write('new_version=true') + else: + with open(github_output, 'a', encoding='utf-8') as f: + f.write('new_version=false') \ No newline at end of file From d7c7ebd3fe6330ce787a2d0340e8e656339cd262 Mon Sep 17 00:00:00 2001 From: hestonhoffman Date: Wed, 2 Oct 2024 09:07:05 -0700 Subject: [PATCH 2/3] Update print statements --- local/bin/py/version_getter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/local/bin/py/version_getter.py b/local/bin/py/version_getter.py index 4ee4aed593573..160e2887dcdd3 100755 --- a/local/bin/py/version_getter.py +++ b/local/bin/py/version_getter.py @@ -69,16 +69,16 @@ def get_versions(keys): current_versions = json.load(open('data/synthetics_worker_versions.json')) except: current_versions = {} - print(current_versions) final_versions = get_versions(keys) - print(final_versions) - if current_versions != final_versions: + print("New version detected!") + print(final_versions) with open('data/synthetics_worker_versions.json', 'w') as f: f.write(json.dumps(final_versions, indent=4, sort_keys=True)) with open(github_output, 'a', encoding='utf-8') as f: f.write('new_version=true') else: with open(github_output, 'a', encoding='utf-8') as f: + print("No new version detected") f.write('new_version=false') \ No newline at end of file From 3eb7901b1941fafbaf6fb1ec00fec6ce2e3bd0e3 Mon Sep 17 00:00:00 2001 From: hestonhoffman Date: Wed, 2 Oct 2024 09:10:17 -0700 Subject: [PATCH 3/3] echo new version to test --- .github/workflows/bump_synthetics_worker_version.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bump_synthetics_worker_version.yml b/.github/workflows/bump_synthetics_worker_version.yml index da5a2f2688b4a..40671ef321aec 100644 --- a/.github/workflows/bump_synthetics_worker_version.yml +++ b/.github/workflows/bump_synthetics_worker_version.yml @@ -24,7 +24,10 @@ jobs: - name: Find latest synthetic-worker version id: write-synthetics-worker-version run: | - python local/bin/py/version_getter.py + python local/bin/py/version_getter.py + + - name: echo new version + run: echo ${{ steps.write-synthetics-worker-version.outputs.new_version }} - uses: actions/checkout@v4 with: