-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pr-post-lab-link
- Loading branch information
Showing
56 changed files
with
980,354 additions
and
942,080 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,78 @@ | ||
"""Build URLs for each Lab page for Labs that have been changed in this PR. | ||
Test each URL to see if it returns a 200 status code, and post the results | ||
in a PR comment. | ||
""" | ||
|
||
import os | ||
import sys | ||
from github import Github | ||
from pathlib import Path | ||
|
||
COMMENT_TITLE_TEMPLATE = "Preview changes to {lab_name} Lab <!--=-->" | ||
URL_TEMPLATE = ( | ||
"https://labs.usegalaxy.org.au" | ||
"/?content_root=https://github.com/{repo}" | ||
"/blob/{branch_name}/{lab_content_path}" | ||
"&cache=false" | ||
) | ||
TRY_FILES = [ | ||
'base.yml', | ||
'usegalaxy.eu.yml', | ||
'usegalaxy.org.yml', | ||
'usegalaxy.org.au.yml', | ||
] | ||
|
||
# Environment variables from GitHub Actions | ||
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") | ||
PR_NUMBER = int(os.environ["PR_NUMBER"]) | ||
BASE_REPO = os.getenv("BASE_REPO") | ||
|
||
|
||
def get_comment(pull_request, id_string): | ||
"""Fetches PR comments and scans for the COMMENT_TITLE_TEMPLATE.""" | ||
for comment in pull_request.get_issue_comments(): | ||
if id_string in comment.body: | ||
return comment | ||
return None | ||
|
||
|
||
def create_or_update_comment(lab_name, body_md): | ||
"""Creates or updates a comment for the given lab name. | ||
Checks for an existing comment by looking for the COMMENT_TITLE_TEMPLATE | ||
in existing comments. | ||
""" | ||
divider = "\n\n" + '-' * 80 + '\n\n' | ||
print("Posting comment:", divider, body_md.strip(' \n'), divider) | ||
title_string = COMMENT_TITLE_TEMPLATE.format(lab_name=lab_name) | ||
gh = Github(GITHUB_TOKEN) | ||
print("Getting base repo:", BASE_REPO) | ||
repo = gh.get_repo(BASE_REPO) | ||
pull_request = repo.get_pull(PR_NUMBER) | ||
comment = get_comment(pull_request, title_string) | ||
if comment: | ||
comment.edit(body_md) | ||
else: | ||
pull_request.create_issue_comment(body_md) | ||
|
||
|
||
def main(): | ||
comments_dir = Path(sys.argv[1] if len(sys.argv) else "comments") | ||
if ( | ||
comments_dir.exists() | ||
and comments_dir.is_dir() | ||
and list(comments_dir.glob('*.md')) | ||
): | ||
for path in comments_dir.glob('*.md'): | ||
with open(path) as f: | ||
comment_md = f.read() | ||
lab_name = path.stem | ||
print(f"Posting PR comment for {lab_name}...") | ||
create_or_update_comment(lab_name, comment_md) | ||
else: | ||
print("No comments to post - exiting") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
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
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,52 @@ | ||
name: Galaxy Labs PR - post comment(s) | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Test changed Lab pages"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
test-labs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout base branch | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ${{ github.repository }} | ||
ref: main | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install pygithub | ||
run: pip install pygithub | ||
|
||
- name: Install GitHub CLI | ||
run: sudo apt-get install gh | ||
|
||
- name: Download "Test changed Lab pages" artifact | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh repo set-default galaxyproject/galaxy_codex | ||
RUN_ID=$(gh run list --workflow "Test changed Lab pages" --limit 1 | tail -n 1 | grep -oE '\b[0-9]{11}\b') | ||
echo "RUN_ID: $RUN_ID" | ||
gh run view $RUN_ID --log | ||
gh run download $RUN_ID --name labs_test_comments --dir ./labs_test_comments | ||
- name: Post comment if matching changes found | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} #${{ secrets.GH_PR_TOKEN }} | ||
run: | | ||
if ls labs_test_comments/*.md 1> /dev/null 2>&1; then | ||
echo "Changed files found" | ||
echo "Sourcing environment variables from env.sh:" | ||
cat labs_test_comments/env.sh | ||
source labs_test_comments/env.sh | ||
python3 ./.github/scripts/labs_post_comments.py labs_test_comments | ||
else | ||
echo "No changed files found" | ||
fi |
Oops, something went wrong.