Skip to content

feature branches#8298

Merged
shuyama1 merged 11 commits into
GoogleCloudPlatform:mainfrom
shuyama1:feature_branch
Jul 19, 2023
Merged

feature branches#8298
shuyama1 merged 11 commits into
GoogleCloudPlatform:mainfrom
shuyama1:feature_branch

Conversation

@shuyama1

Copy link
Copy Markdown
Member

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Generated Terraform providers, and ran make test and make lint in the generated providers to ensure it passes unit and linter tests.
  • Ran relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read Write release notes before writing my release note below.

Release Note Template for Downstream PRs (will be copied)


@shuyama1 shuyama1 requested a review from melinath July 10, 2023 15:23

@melinath melinath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions and change requests below.

Comment thread .ci/gcb-push-downstream.yml Outdated
Comment thread .ci/gcb-push-downstream.yml Outdated
Comment thread .ci/containers/gcb-terraform-vcr-tester/test_terraform_vcr.sh Outdated
Comment thread .ci/containers/gcb-terraform-vcr-tester/test_terraform_vcr.sh Outdated
Comment thread .ci/gcb-push-downstream.yml
UPSTREAM_OWNER=GoogleCloudPlatform
UPSTREAM_BRANCH=main
if [ -n "$BASE_BRANCH" ]; then
if [ "$BASE_BRANCH" != "main" ]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you test whether the containers behave as expected, at least for generate-diffs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; })

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should fix the go file detection issue occurs when no diff generated for the google providers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shuyama1 shuyama1 requested a review from melinath July 14, 2023 08:58
@shuyama1

Copy link
Copy Markdown
Member Author

The change is tested in #8351 and #8353

elif [ "$REPO" == "terraform-google-conversion" ]; then
UPSTREAM_OWNER=GoogleCloudPlatform
UPSTREAM_BRANCH=main
# UPSTREAM_BRANCH=main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shuyama1 shuyama1 merged commit 4713a03 into GoogleCloudPlatform:main Jul 19, 2023
@shuyama1 shuyama1 deleted the feature_branch branch July 19, 2023 19:03
melinath pushed a commit that referenced this pull request Jul 20, 2023
ericayyliu pushed a commit to ericayyliu/magic-modules that referenced this pull request Jul 26, 2023
wj-chen pushed a commit to wj-chen/magic-modules that referenced this pull request Aug 1, 2023
DanielRieske pushed a commit to bschaatsbergen/magic-modules that referenced this pull request Aug 2, 2023
hao-nan-li pushed a commit to hao-nan-li/magic-modules that referenced this pull request Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants