-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
2 changed files
with
76 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: PR Views to PrefectHQ/prefect | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- pr-worker-view | ||
paths: | ||
- 'views/aggregate-worker-metadata.json' | ||
|
||
jobs: | ||
update-views: | ||
name: Send updated views to PrefectHQ/prefect | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
cache: pip | ||
cache-dependency-path: requirements*.txt | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install --upgrade --upgrade-strategy eager -e ".[dev]" | ||
- name: Open PRs to PrefectHQ/prefect | ||
run: src/pr_views_to_core.py | ||
|
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,44 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import asyncio | ||
import httpx | ||
from datetime import datetime | ||
|
||
GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] | ||
SOURCE_REPO_URL = 'https://raw.githubusercontent.com/PrefectHQ/prefect-collection-registry/main/views/aggregate-worker-metadata.json' | ||
TARGET_FILE_PATH = 'src/prefect/server/api/collections_data/views/aggregate-worker-metadata.json' # noqa E501 | ||
TARGET_ORG = 'PrefectHQ' | ||
TARGET_REPO = 'prefect' | ||
NEW_BRANCH = f'update-worker-metadata-{datetime.now().strftime("%Y%m%d%H%M%S")}' | ||
|
||
commands = f""" | ||
mkdir -p {os.path.dirname(TARGET_FILE_PATH)} && | ||
curl -o {TARGET_FILE_PATH} {SOURCE_REPO_URL} && | ||
git checkout -b {NEW_BRANCH} && | ||
git add {TARGET_FILE_PATH} && | ||
git commit -m "Update aggregate-worker-metadata.json" && | ||
git push -u origin {NEW_BRANCH} | ||
""" | ||
subprocess.check_call(commands, shell=True) | ||
|
||
async def create_pull_request(new_branch: str): | ||
async with httpx.AsyncClient() as client: | ||
response = await client.post( | ||
f'https://api.github.com/repos/{TARGET_ORG}/{TARGET_REPO}/pulls', | ||
headers={'Authorization': f'token {GITHUB_TOKEN}'}, | ||
json={ | ||
'title': 'Automated PR for Worker Metadata Update', | ||
'head': new_branch, | ||
'base': 'main' | ||
} | ||
) | ||
|
||
if response.status_code == 201: | ||
print('Pull request created successfully.') | ||
else: | ||
print('Failed to create pull request:', response.json()) | ||
|
||
if __name__ == '__main__': | ||
new_branch = sys.argv[1] if len(sys.argv) > 1 else NEW_BRANCH | ||
asyncio.run(create_pull_request(new_branch)) |