-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b734f8f
commit 1142ba1
Showing
2 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,24 +13,26 @@ jobs: | |
pull-requests: write # to create pull request | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Generate a token | ||
id: generate-token | ||
uses: actions/create-github-app-token@v1 | ||
with: | ||
app-id: ${{ vars.DOCS_GH_APP_ID }} | ||
private-key: ${{ secrets.DOCS_GH_APP_PRIVATE_KEY }} | ||
- id: set-worker-version | ||
name: Load latest worker version | ||
uses: actions/github-script@v7 | ||
|
||
- uses: actions/[email protected] | ||
with: | ||
github-token: ${{ steps.generate-token.outputs.token }} | ||
result-encoding: string | ||
script: | | ||
const tags = await github.rest.repos.listTags({ | ||
owner: 'hestonhoffman', | ||
repo: 'changed-lines' | ||
}) | ||
const regex = /^(?:(?:[0-9]*)[.](?:[0-9]*)[.](?:[0-9]*))$/; | ||
latestTag = tags.data.find(value => regex.test(value)) | ||
console.log(latestTag) | ||
return latestTag | ||
python-version: '3.11' | ||
|
||
- name: Find latest synthetic-worker version | ||
id: set-worker-version | ||
env: | ||
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
run: | | ||
python local/bin/py/synthetics_worker_version.py | ||
- name: echo worker version | ||
run: echo ${{ steps.set-worker-version.outputs.worker_version }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import requests | ||
import re | ||
from os import environ | ||
|
||
class InvalidTokenError(Exception): | ||
''' | ||
Represents an error when no token is provided | ||
''' | ||
|
||
def get_data(): | ||
url = 'https://api.github.com/repos/DataDog/synthetics-worker/git/refs/tags' | ||
headers = { | ||
'Authorization': f'Bearer {token}', | ||
'Accept': 'application/vnd.github+json', | ||
'X-GitHub-Api-Version': '2022-11-28' | ||
} | ||
response = requests.get(url, headers=headers) | ||
if response.status_code != 200: | ||
raise Exception('Failed to get tags') | ||
return response.json() | ||
|
||
def get_tags(data): | ||
versions = [] | ||
for tag in data: | ||
version = tag.get('ref', '').split('/')[-1] | ||
if version: | ||
versions.append(version) | ||
return versions | ||
|
||
def return_latest_version(tags): | ||
valid_versions = [] | ||
pattern = r"^(?:(?:[0-9]*)[.](?:[0-9]*)[.](?:[0-9]*))$" | ||
valid_versions = [version for version in tags if re.match(pattern, version)] | ||
return sorted(valid_versions)[-1] | ||
|
||
''' | ||
Gets the latest version tag from the synthetics-worker repo | ||
''' | ||
if __name__ == "__main__": | ||
token = environ.get('GH_TOKEN') | ||
github_output = environ.get('GITHUB_OUTPUT') | ||
if token is None: | ||
raise InvalidTokenError('No token provided') | ||
data = get_data() | ||
tags = get_tags(data) | ||
latest_version = return_latest_version(tags) | ||
print(f'Latest version: {latest_version}') | ||
|
||
# Write the latest version to the output file | ||
with open(github_output, 'w', encoding='utf-8') as f: | ||
f.write(f'worker_version={latest_version}\n') |