feature branches#8298
Conversation
melinath
left a comment
There was a problem hiding this comment.
A few questions and change requests below.
| UPSTREAM_OWNER=GoogleCloudPlatform | ||
| UPSTREAM_BRANCH=main | ||
| if [ -n "$BASE_BRANCH" ]; then | ||
| if [ "$BASE_BRANCH" != "main" ]; then |
There was a problem hiding this comment.
FWIW I think this if statement is probably not necessary since main is a valid downstream branch... I think we could always set UPSTREAM_BRANCH=$BASE_BRANCH here.
| function clone_repo() { | ||
| SCRATCH_OWNER=modular-magician | ||
| UPSTREAM_BRANCH=main | ||
| if [ -n "$BASE_BRANCH" ]; then |
There was a problem hiding this comment.
What would you think about checking whether BASE_BRANCH is set once at the top of the file and then setting it to main by default if unset? I think that might let you remove other checks about whether it's set or not? And then you could have UPSTREAM_BRANCH=$BASE_BRANCH as the default in this function.
There was a problem hiding this comment.
That's a good idea. Moved the check to the top of each file.
| # the check of existence of BASE_BRANCH is for backwards-compatability | ||
| if [ -n "$BASE_BRANCH" ]; then | ||
| echo "BASE_BRANCH: $BASE_BRANCH" | ||
| git -C $LOCAL_PATH checkout $BASE_BRANCH |
There was a problem hiding this comment.
Would this work? It seems like the git clone might have to happen before checking out a branch.
FWIW you might also be able to use git clone $GITHUB_PATH $LOCAL_PATH --branch $BASE_BRANCH if there's a default value for BASE_BRANCH.
There was a problem hiding this comment.
Absolutely right. I checked my previous test PR, yeah, it should happen after git clone. Clearly I can't copy and paste 🤦 sorry for all these typos
| @@ -5,6 +5,10 @@ set -e | |||
| function clone_repo() { | |||
There was a problem hiding this comment.
Could you test whether the containers behave as expected, at least for generate-diffs?
There was a problem hiding this comment.
I did test the generate-diff before: #7882
But I will test the change in this PR again to make sure it work as expected
| echo "Checking for modified go files" | ||
| # get the names of changed files and look for go files | ||
| # (ignoring "no matches found" errors from grep) | ||
| gofiles=$(git diff --name-only HEAD~1 | { grep -e "\.go$" -e "go.mod$" -e "go.sum$" || test $? = 1; }) |
There was a problem hiding this comment.
I think this should fix the go file detection issue occurs when no diff generated for the google providers
There was a problem hiding this comment.
I can't get this to run locally so I'm a little hesitant about including it. If it works in cloudbuild then that's fine for now at least, though.
There was a problem hiding this comment.
I'll do a more thorough test on this feature. I'll exclude it from this PR and create a separate PR for it since I don't think feature branch is blocked without this change.
| elif [ "$REPO" == "terraform-google-conversion" ]; then | ||
| UPSTREAM_OWNER=GoogleCloudPlatform | ||
| UPSTREAM_BRANCH=main | ||
| # UPSTREAM_BRANCH=main |
There was a problem hiding this comment.
| # UPSTREAM_BRANCH=main |
| SCRATCH_PATH=https://modular-magician:$GITHUB_TOKEN@github.com/$SCRATCH_OWNER/$GH_REPO | ||
| mkdir -p "$(dirname $LOCAL_PATH)" | ||
| git clone $GITHUB_PATH $LOCAL_PATH | ||
| # git clone $GITHUB_PATH $LOCAL_PATH |
There was a problem hiding this comment.
| # git clone $GITHUB_PATH $LOCAL_PATH |
| mkdir fixtures | ||
| gsutil -m -q cp gs://ci-vcr-cassettes/beta/fixtures/* fixtures/ | ||
| # copy branch specific cassettes over master. This might fail but that's ok if the folder doesnt exist | ||
| if [ "$BASE_BRANCH" != "FEATURE-BRANCH-major-release-5.0.0" ]; then |
There was a problem hiding this comment.
In the future it would be nice to use a more generic matching rule like "does not start with FEATURE-BRANCH-major-release" but this is fine for now and not worth delaying to change probably.
There was a problem hiding this comment.
Let's use FEATURE-BRANCH-major-release-5.0.0 for now and I'll change it to be more generic after we confirm this path working fine in the future.
| - -c | ||
| - git push https://modular-magician:$$GITHUB_TOKEN@github.com/GoogleCloudPlatform/magic-modules $COMMIT_SHA:tpg-sync | ||
| - | | ||
| if [ "$BRANCH_NAME" == "main" ]; then |
There was a problem hiding this comment.
I wonder if using the substitution directly like this might have security issues similar to https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable? It doesn't seem to be documented as an issue on https://cloud.google.com/build/docs/configuring-builds/run-bash-scripts but they do recommend using script with env vars now rather than using bash + args. (But that could just be because it was confusing users to have to sort out what is a substitution vs an env var.)
In any case - I don't think this is an issue since allowed branch names are pretty constrained by git.
| echo "Checking for modified go files" | ||
| # get the names of changed files and look for go files | ||
| # (ignoring "no matches found" errors from grep) | ||
| gofiles=$(git diff --name-only HEAD~1 | { grep -e "\.go$" -e "go.mod$" -e "go.sum$" || test $? = 1; }) |
There was a problem hiding this comment.
I can't get this to run locally so I'm a little hesitant about including it. If it works in cloudbuild then that's fine for now at least, though.
If this PR is for Terraform, I acknowledge that I have:
make testandmake lintin the generated providers to ensure it passes unit and linter tests.Release Note Template for Downstream PRs (will be copied)