Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to re-enable GitHub Actions. (#121)
Fixes #88.
- Loading branch information
Michael Howitz
committed
Sep 8, 2021
1 parent
af45ce3
commit faa88a9
Showing
5 changed files
with
118 additions
and
26 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
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,55 @@ | ||
#!/bin/env python3 | ||
from shared.call import call | ||
from shared.packages import list_packages | ||
import argparse | ||
import itertools | ||
import pathlib | ||
|
||
|
||
org = 'zopefoundation' | ||
base_url = f'https://github.com/{org}' | ||
base_path = pathlib.Path(__file__).parent | ||
types = ['buildout-recipe', 'c-code', 'pure-python', 'zope-product'] | ||
|
||
|
||
parser = argparse.ArgumentParser( | ||
description='Re-enable GitHub Actions for all repos in a packages.txt' | ||
' files.') | ||
parser.add_argument( | ||
'--force-run', | ||
help='Run workflow even it is already enabled.', | ||
action='store_true') | ||
|
||
args = parser.parse_args() | ||
repos = itertools.chain( | ||
*[list_packages(base_path / type / 'packages.txt') | ||
for type in types]) | ||
|
||
|
||
def run_workflow(base_url, org, repo): | ||
"""Manually start the tests.yml workflow of a repository.""" | ||
result = call('gh', 'workflow', 'run', 'tests.yml', '-R', f'{org}/{repo}') | ||
if result.returncode != 0: | ||
print('To enable manually starting workflows clone the repository' | ||
' and run meta/config/config-package.py on it.') | ||
print('Command to clone:') | ||
print(f'git clone {base_url}/{repo}.git') | ||
return False | ||
return True | ||
|
||
|
||
for repo in repos: | ||
print(repo) | ||
wfs = call( | ||
'gh', 'workflow', 'list', '--all', '-R', f'{org}/{repo}', | ||
capture_output=True).stdout | ||
test_line = [x for x in wfs.splitlines() if x.startswith('test')][0] | ||
if 'disabled_inactivity' not in test_line: | ||
print(' ☑️ already enabled') | ||
if args.force_run: | ||
run_workflow(base_url, org, repo) | ||
continue | ||
test_id = test_line.split()[-1] | ||
call('gh', 'workflow', 'enable', test_id, '-R', f'{org}/{repo}') | ||
if run_workflow(base_url, org, repo): | ||
print(' ✅ enabled') |
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,13 @@ | ||
import pathlib | ||
|
||
|
||
def list_packages(path: pathlib.Path) -> list: | ||
"""List the packages in ``path``. | ||
``path`` must point to a packages.txt file. | ||
""" | ||
return [ | ||
p | ||
for p in path.read_text().split('\n') | ||
if p and not p.startswith('#') | ||
] |
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