diff --git a/.github/chainguard/self.bump-versions.create-pr.sts.yaml b/.github/chainguard/self.version_getter_shared.create-pr.yaml similarity index 70% rename from .github/chainguard/self.bump-versions.create-pr.sts.yaml rename to .github/chainguard/self.version_getter_shared.create-pr.yaml index b3cf33153ed5a..ba9ae0f262590 100644 --- a/.github/chainguard/self.bump-versions.create-pr.sts.yaml +++ b/.github/chainguard/self.version_getter_shared.create-pr.yaml @@ -6,7 +6,7 @@ claim_pattern: event_name: schedule ref: refs/heads/master ref_protected: "true" - job_workflow_ref: DataDog/documentation/\.github/workflows/bump_versions\.yml@refs/heads/master + job_workflow_ref: DataDog/documentation/\.github/workflows/version_getter_shared\.yml@refs/heads/master permissions: contents: write diff --git a/.github/workflows/bump_private_action_version.yml b/.github/workflows/bump_private_action_version.yml new file mode 100644 index 0000000000000..70ad1d0adcf0a --- /dev/null +++ b/.github/workflows/bump_private_action_version.yml @@ -0,0 +1,15 @@ +on: + schedule: + # At 08:00 on every day-of-week from Monday through Friday. + - cron: "0 7 * * 1-5" + workflow_dispatch: # allows manual trigger + +jobs: + call-version-getter-shared-workflow: + permissions: + contents: read + pull-requests: write + uses: Datadog/documentation/.github/workflows/version_getter_shared.yml@heston/dynamic-action-version + with: + url: https://api.datadoghq.com/api/v2/on-prem-management-service/runner/latest-image + file-name: private_action_runner_version.json \ No newline at end of file diff --git a/.github/workflows/bump_synthetics_worker_version.yml b/.github/workflows/bump_synthetics_worker_version.yml index fb22eb52b14bd..f3d3e3ea29873 100644 --- a/.github/workflows/bump_synthetics_worker_version.yml +++ b/.github/workflows/bump_synthetics_worker_version.yml @@ -5,71 +5,11 @@ on: workflow_dispatch: # allows manual trigger jobs: - synthetics-worker-version: + call-version-getter-shared-workflow: permissions: - contents: write # for git push - id-token: write # Needed to federate tokens. - runs-on: ubuntu-latest - name: Find latest synthetics-worker version - steps: - - uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 - id: octo-sts - with: - scope: DataDog/documentation - policy: self.bump-synthetics-worker-version.create-pr - - - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - with: - persist-credentials: false - - - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 - with: - python-version: "3.11" - - 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 - - - name: Save modified file - run: | - mkdir -p $RUNNER_TEMP/synthetics - cp ./data/synthetics_worker_versions.json $RUNNER_TEMP/synthetics/ - - - name: echo new version - run: echo ${{ steps.write-synthetics-worker-version.outputs.new_version }} - - - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - with: - persist-credentials: true - - - name: Restore modified file - run: | - cp $RUNNER_TEMP/synthetics/synthetics_worker_versions.json ./data/ - - - name: Write version - if: steps.write-synthetics-worker-version.outputs.new_version == 'true' - run: |- - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add ./data/synthetics_worker_versions.json - git commit -m "(Automated) Bump synthetics-worker version" - git push -f origin HEAD:refs/heads/synthetics-worker/versions - - - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - name: Propose change with latest versions - if: steps.write-synthetics-worker-version.outputs.new_version == 'true' - with: - github-token: ${{ steps.octo-sts.outputs.token }} - result-encoding: string - script: | - await github.rest.pulls.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: "(Automated) Bump synthetics-worker version", - body: "### Merge instructions\n- [x] Please merge after reviewing", - head: "synthetics-worker/versions", - base: "master", - maintainer_can_modify: true - }) + contents: read + pull-requests: write + uses: Datadog/documentation/.github/workflows/version_getter_shared.yml@heston/dynamic-action-version + with: + url: https://ddsynthetics-windows.s3.amazonaws.com/installers.json + file-name: synthetics_worker_versions.json \ No newline at end of file diff --git a/.github/workflows/version_getter_shared.yml b/.github/workflows/version_getter_shared.yml new file mode 100644 index 0000000000000..b00f1ba1c84fa --- /dev/null +++ b/.github/workflows/version_getter_shared.yml @@ -0,0 +1,85 @@ +on: + workflow_call: + inputs: + url: + required: true + type: string + file_name: + required: true + type: string + +jobs: + reusable_workflow_job: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 + + fetch-version: + permissions: + contents: write # for git push + id-token: write # Needed to federate tokens. + runs-on: ubuntu-latest + name: Find latest version + steps: + - uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 + id: octo-sts + with: + scope: DataDog/documentation + policy: self.version_getter_shared.create-pr + + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + with: + persist-credentials: false + + - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + with: + python-version: "3.11" + - run: pip install requests semver defusedxml + + - name: Find and write latest version + id: write-version + run: | + python local/bin/py/version_getter.py --url ${{ inputs.url }} --file-name ${{ inputs.file_name }} + + - name: Save modified file + run: | + mkdir -p $RUNNER_TEMP/temp + cp ./data/{{ inputs.file_name }} $RUNNER_TEMP/temp/ + + - name: echo new version + run: echo ${{ steps.write-version.outputs.new_version }} + + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + with: + persist-credentials: true + + - name: Restore modified file + run: | + cp $RUNNER_TEMP/temp/{{ inputs.file_name }} ./data/ + + - name: Write version + if: steps.write-version.outputs.new_version == 'true' + run: |- + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add ./data/{{ inputs.file_name }} + git commit -m "(Automated) Bump version" + git push -f origin HEAD:refs/heads/automatic-version-update/versions + + - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + name: Propose change with latest versions + if: steps.write-version.outputs.new_version == 'true' + with: + github-token: ${{ steps.octo-sts.outputs.token }} + result-encoding: string + script: | + await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: "(Automated) Bump version", + body: "### Merge instructions\n- [x] Please merge after reviewing", + head: "automatic-version-update/versions", + base: "master", + maintainer_can_modify: true + }) + \ No newline at end of file diff --git a/data/private_action_runner_version.json b/data/private_action_runner_version.json new file mode 100644 index 0000000000000..42f1dc88f0a89 --- /dev/null +++ b/data/private_action_runner_version.json @@ -0,0 +1,6 @@ +[ + { + "client": "private-action-runner", + "version": "1.7.0" + } +] \ No newline at end of file diff --git a/local/bin/py/version_getter.py b/local/bin/py/version_getter.py index 046164d69a44b..ffac510ed6ace 100755 --- a/local/bin/py/version_getter.py +++ b/local/bin/py/version_getter.py @@ -4,15 +4,14 @@ import json import requests -def get_data(): - url = "https://ddsynthetics-windows.s3.amazonaws.com/installers.json" +def get_data(url): response = requests.get(url) if response.status_code != 200: - raise Exception("Failed to list ddsynthetics-windows bucket") + raise Exception("Failed to retrieve version information from URL: " + url) return response -def get_version(data): +def get_synthetics_worker_version(data): '''Get the latest version''' data = data.json() latest_info = data.get("synthetics-private-location", {}).get("latest", {}).get("x86_64", {}).get("url", "") @@ -28,34 +27,77 @@ def get_version(data): return version +def get_private_action_runner_version(data): + '''Get the latest version''' + data = data.json() + latest_info = data.get("data", {}).get("id", "") + if latest_info: + # Extract version from the image tag (e.g., "gcr.io/datadoghq/private-action-runner:v1.7.0" -> "1.7.0") + match = re.search(r":v(\d+\.\d+\.\d+)", latest_info) + if match: + version = match.group(1) + return version + else: + raise Exception("Failed to extract version from image tag: " + latest_info) + else: + raise Exception("Failed to find latest release") + ''' Gets the latest version tag from https://ddsynthetics-windows.s3.amazonaws.com/installers.json ''' if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser(description='Get latest version information') + parser.add_argument('--url', required=True, help='URL to fetch version data from') + parser.add_argument('--file-name', required=True, help='Target file name to update') + + args = parser.parse_args() + url = args.url + file_name = args.file_name + + if not url or not file_name: + raise Exception("Missing required arguments: URL and file name are required") + github_output = os.getenv('GITHUB_OUTPUT') - data = get_data() - latest_version = get_version(data) + data = get_data(url) + client = "" + if file_name == "synthetics_worker_versions.json": + latest_version = get_synthetics_worker_version(data) + client = "synthetics-windows-pl" + elif file_name == "private_action_runner_version.json": + latest_version = get_private_action_runner_version(data) + client = "private-action-runner" + else: + raise Exception("Invalid file name: " + file_name) try: - current_versions = json.load(open('data/synthetics_worker_versions.json')) + with open(f'data/{file_name}', 'r') as f: + current_versions = json.load(f) except: current_versions = {} - current_version = current_versions[0].get('version') + current_version = current_versions[0].get('version') if current_versions else None print("Current version: ", current_version) - if current_version != latest_version: + if current_version != latest_version and client: print("New version detected: ", latest_version) final_versions = [{ - "client": "synthetics-windows-pl", + "client": client, "version": latest_version }] - with open('data/synthetics_worker_versions.json', 'w') as f: + with open(f'data/{file_name}', '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') + if github_output: + with open(github_output, 'a', encoding='utf-8') as f: + f.write('new_version=true') + else: + print("A new version was found!") 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 + if github_output: + with open(github_output, 'a', encoding='utf-8') as f: + print("No new version detected") + f.write('new_version=false') + else: + print("No new version detected") \ No newline at end of file