Skip to content
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

fix!: branch setup for git init #138

Merged
merged 4 commits into from
Jun 7, 2023
Merged

fix!: branch setup for git init #138

merged 4 commits into from
Jun 7, 2023

Conversation

jbrockopp
Copy link
Contributor

@jbrockopp jbrockopp commented Jun 5, 2023

xref: go-vela/community#816

Based off of #122

This change ensures we set the expected branch when invoking git init.

  • for pull_request events, this sets the branch for git init from VELA_PULL_REQUEST_SOURCE
  • for all other events, this sets the branch for git init from VELA_BUILD_BRANCH

To test this, I set up a repo with a default branch of main and a .vela.yml that looks like:

version: "1"

metadata:
  clone: false

steps:
  - name: clone
    image: vela-git:local # built this image with 'make build-static; make docker-build'

  - name: context
    image: alpine:latest
    commands:
      - apk add git
      - git branch
      - git status
      - printenv | sort

Then, I created a new context branch which I modified the README.md and opened a PR that targets main.

Before this change, for both the pull_request and push events, here's a snippet of output from the context step:

<other output>
$ git branch
* main
$ git status
On branch main
nothing to commit, working tree clean

After this change, here's a snippet of output from the context step:

<other output>
$ git branch
* context
$ git status
On branch context
nothing to commit, working tree clean

@jbrockopp jbrockopp added the bug Indicates a bug label Jun 5, 2023
@jbrockopp jbrockopp self-assigned this Jun 5, 2023
@codecov
Copy link

codecov bot commented Jun 5, 2023

Codecov Report

Merging #138 (6d793ed) into main (b41373c) will decrease coverage by 1.53%.
The diff coverage is 25.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #138      +/-   ##
==========================================
- Coverage   49.05%   47.52%   -1.53%     
==========================================
  Files           6        6              
  Lines         424      425       +1     
==========================================
- Hits          208      202       -6     
- Misses        205      210       +5     
- Partials       11       13       +2     
Impacted Files Coverage Δ
cmd/vela-git/main.go 0.00% <0.00%> (ø)
cmd/vela-git/repo.go 100.00% <ø> (ø)
cmd/vela-git/build.go 100.00% <100.00%> (ø)
cmd/vela-git/plugin.go 44.28% <100.00%> (-8.58%) ⬇️

@jbrockopp jbrockopp marked this pull request as ready for review June 5, 2023 18:36
@jbrockopp jbrockopp requested a review from a team as a code owner June 5, 2023 18:36
@@ -67,6 +67,13 @@ func main() {

// Build Flags

&cli.StringFlag{
EnvVars: []string{"PARAMETER_BRANCH", "GIT_BRANCH", "VELA_PULL_REQUEST_SOURCE", "VELA_BUILD_BRANCH"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We specify the VELA_PULL_REQUEST_SOURCE environment variable first intentionally.

This environment variable is ONLY set for pull_request events.

This ensures the CLI library we use will try to set this value from that variable first.

In the event this plugin runs for a non pull_request event, we then source from VELA_BUILD_BRANCH.

If all else fails, we have a fallback value of master to mirror the build.ref flag:

&cli.StringFlag{
EnvVars: []string{"PARAMETER_REF", "GIT_REF", "VELA_BUILD_REF"},
FilePath: "/vela/parameters/git/ref,/vela/secrets/git/ref",
Name: "build.ref",
Usage: "commit reference to clone from the repo",
Value: "refs/heads/master",
},

@plyr4
Copy link
Contributor

plyr4 commented Jun 7, 2023

love it, thanks @jbrockopp
agreed its a fix, should we mark it breaking?

@jbrockopp jbrockopp changed the title fix: branch setup for git init fix!: branch setup for git init Jun 7, 2023
@jbrockopp
Copy link
Contributor Author

love it, thanks @jbrockopp agreed its a fix, should we mark it breaking?

I'm not entirely sure the procedure for bug fixes that are breaking changes 😅

At any rate, I updated the PR description with a ! to denote that; rather be safe than sorry 👍

@wass3rw3rk wass3rw3rk merged commit d84e99d into main Jun 7, 2023
@wass3rw3rk wass3rw3rk deleted the fix/clone/branch branch June 7, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants