Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/bump_private_action_version.yml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we need a SHA here, but I might have to update this in a follow-up PR

with:
url: https://api.datadoghq.com/api/v2/on-prem-management-service/runner/latest-image
file-name: private_action_runner_version.json
74 changes: 7 additions & 67 deletions .github/workflows/bump_synthetics_worker_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here

with:
url: https://ddsynthetics-windows.s3.amazonaws.com/installers.json
file-name: synthetics_worker_versions.json
85 changes: 85 additions & 0 deletions .github/workflows/version_getter_shared.yml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/DataDog/documentation/blob/master/.github/chainguard/self.bump-versions.create-pr.sts.yaml#L9

This will need to be updated to match the workflow otherwise it will not be able to auth


- 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
})

6 changes: 6 additions & 0 deletions data/private_action_runner_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"client": "private-action-runner",
"version": "1.7.0"
}
]
74 changes: 58 additions & 16 deletions local/bin/py/version_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand All @@ -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')
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")
Loading