-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DH-301] Python script to replace bash scaffolding in CI/CD and simplify github workflows #6035
Merged
shaneknapp
merged 14 commits into
berkeley-dsep-infra:staging
from
shaneknapp:python-scripts-replace-bash
Aug 28, 2024
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6fd9cb1
script and workflow to get deployments from deployments/ subdir
shaneknapp d931fa1
forgot about staging
shaneknapp ac0f289
newline at EOF
shaneknapp 84f6b64
docstring ftw
shaneknapp c888a45
must remember: double quotes, not single. double quotes, not single…
shaneknapp d462e9a
formatting
shaneknapp 88fbf92
python really helps clean things up
shaneknapp f9ad125
add arg to allow us to limit hub deployments to only specific ones
shaneknapp ddacff1
seriously hating bash
shaneknapp 739c19a
reformat comments to be a bit more clear
shaneknapp 8d31b03
more explainy comments
shaneknapp 132acfa
grammarizing the crap out of comments
shaneknapp 9f64914
might as well explicitly call python to execute these scripts... can…
shaneknapp a7b591a
bashenannigans
shaneknapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
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 specific hubs | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felder : sanity check here. the github action that grabs labels from a push exports them to env vars in the format of
GITHUB_PR_LABEL_<whatever>=1
. in this case, i want to check for the labels ofjupyterhub-deployment
and/orhub-images
(stored as the vars in the code snippet above).if i want to check if these are indeed set, the way i do it here (
if [[ -n ${GITHUB_PR_LABEL_HUB_IMAGES} || -n ${GITHUB_PR_LABEL_JUPYTERHUB_DEPLOYMENT} ]]
) is correct, yes?(i did a bunch of testing on the CLI and this seems to give us what we want but a 2nd pair of eyes is always nice etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shaneknapp -n evaluates to true if the variable is not set to the empty string. You may want to use -v instead which evaluates to true if the variable is set. -v also expects the name of the variable as opposed to an expansion of the variable.
So you may want to try
if [[ -v GITHUB_PR_LABEL_HUB_IMAGES || -v GITHUB_PR_LABEL_JUPYTERHUB_DEPLOYMENT ]]
Example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, lemme try that... i'll set some labels to test this when i merge to staging