-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6035 from shaneknapp/python-scripts-replace-bash
[DH-301] Python script to replace bash scaffolding in CI/CD and simplify github workflows
- Loading branch information
Showing
3 changed files
with
99 additions
and
225 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,69 @@ | ||
#! /usr/bin/env python | ||
""" | ||
Check the Github environment variables for hub deployments and determine if we | ||
will deploy all hubs or just a subset. | ||
All hubs will be deployed if the environment variable | ||
GITHUB_PR_LABEL_JUPYTERHUB_DEPLOYMENT or GITHUB_PR_LABEL_HUB_IMAGES is set. | ||
Otherwise, the environment variables GITHUB_PR_LABEL_HUB_<HUB_NAME> will be | ||
checked to determine which hubs to deploy. | ||
If no hubs need deploying, nothing will be emitted. | ||
""" | ||
import argparse | ||
import os | ||
|
||
def main(args): | ||
hubs = [] | ||
|
||
# Deploy all hubs by getting deployment names from the dirs in deployments/ | ||
if ( | ||
"GITHUB_PR_LABEL_JUPYTERHUB_DEPLOYMENT" or | ||
"GITHUB_PR_LABEL_HUB_IMAGES" | ||
) in os.environ.keys(): | ||
for deployment in next(os.walk(args.deployments))[1]: | ||
if deployment not in args.ignore: | ||
hubs.append(deployment) | ||
|
||
# Deploy only the modified/flagged hubs by PR labels | ||
else: | ||
hub_labels = [ | ||
k.lower() for k in os.environ.keys() | ||
if k.startswith("GITHUB_PR_LABEL_HUB_") | ||
] | ||
hubs = [x.split("_")[-1] for x in hub_labels] | ||
hubs = [x for x in hubs if x not in args.ignore] | ||
|
||
hubs.sort() | ||
for h in hubs: | ||
if args.only_deploy and h not in args.only_deploy: | ||
continue | ||
print(h) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Get hubs that need to be deployed from environment variables." | ||
) | ||
parser.add_argument( | ||
"--deployments", | ||
"-d", | ||
default="deployments", | ||
help="The directory to search for deployments." | ||
) | ||
parser.add_argument( | ||
"--ignore", | ||
"-i", | ||
nargs="*", | ||
default=["template"], | ||
help="Ignore one or more deployment targets." | ||
) | ||
parser.add_argument( | ||
"--only-deploy", | ||
"-o", | ||
nargs="*", | ||
help="Only deploy the specified hubs." | ||
) | ||
args = parser.parse_args() | ||
|
||
main(args) |
This file was deleted.
Oops, something went wrong.
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