From fce2449a4c5cb3262abe7e1a6b2b50d751426f74 Mon Sep 17 00:00:00 2001 From: Win San Date: Fri, 14 Jun 2024 10:26:48 -0500 Subject: [PATCH 1/3] fix(container): skip "label" rule evaluation in container execution (#380) * Skip label rule evaluation in container exectution * Add skip label evaluation tests --- pipeline/container.go | 27 ++++-------- pipeline/container_test.go | 86 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 19 deletions(-) diff --git a/pipeline/container.go b/pipeline/container.go index 3d427cb0..8e2e55f1 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -152,32 +152,21 @@ func (c *Container) Execute(r *RuleData) (bool, error) { if c == nil { return false, nil } - // skip evaluating path in ruleset - // - // the compiler is the component responsible for - // choosing whether a container will run based - // off the files changed for a build + + // Skip evaluating path, comment, and label in ruleset, + // as the worker lacks necessary rule data. // - // the worker doesn't have any record of - // what files changed for a build so we - // should "skip" evaluating what the - // user provided for the path element + // The compiler determines whether a container will run based on + // these rules. c.Ruleset.If.Path = []string{} c.Ruleset.Unless.Path = []string{} - // skip evaluating comment in ruleset - // - // the compiler is the component responsible for - // choosing whether a container will run based - // off the PR comment matching the pipeline comment - // - // the worker doesn't have any record of - // the PR comment so we - // should "skip" evaluating what the - // user provided for the PR comment c.Ruleset.If.Comment = []string{} c.Ruleset.Unless.Comment = []string{} + c.Ruleset.If.Label = []string{} + c.Ruleset.Unless.Label = []string{} + // check if the build is in a running state if strings.EqualFold(r.Status, constants.StatusRunning) { // treat the ruleset status as success diff --git a/pipeline/container_test.go b/pipeline/container_test.go index 3f5e3a45..a7ae573c 100644 --- a/pipeline/container_test.go +++ b/pipeline/container_test.go @@ -749,6 +749,92 @@ func TestPipeline_Container_Execute(t *testing.T) { }, want: true, }, + { // pull request labeled success container with build success + container: &Container{ + Name: "pull-request-labeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + If: Rules{ + Branch: []string{"fix/1234"}, + Event: []string{constants.EventPull + constants.ActionLabeled}, + Label: []string{"enhancement", "documentation"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:labeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request unlabeled success container with build success + container: &Container{ + Name: "pull-request-unlabeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + If: Rules{ + Event: []string{constants.EventPull + constants.ActionUnlabeled}, + Label: []string{"enhancement"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:unlabeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request labeled unless ruleset, success container with build success + container: &Container{ + Name: "pull-request-labeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + Unless: Rules{ + Branch: []string{"fix/1234"}, + Event: []string{constants.EventPull + constants.ActionLabeled}, + Label: []string{"enhancement", "documentation"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:labeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request unlabeled unless ruleset, success container with build success + container: &Container{ + Name: "pull-request-unlabeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + Unless: Rules{ + Event: []string{constants.EventPull + constants.ActionUnlabeled}, + Label: []string{"enhancement"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:unlabeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, } // run tests From d09a797bd3f3b41a31ad277be307ade0f03acc76 Mon Sep 17 00:00:00 2001 From: david may <1301201+wass3r@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:36:42 -0500 Subject: [PATCH 2/3] fix(lint): use proper formats field (#381) Co-authored-by: Easton Crupper <65553218+ecrupper@users.noreply.github.com> --- .golangci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 4ae4c744..0047b8cf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,7 +8,10 @@ # outputs it results from the linters it executes. output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number + formats: + - format: json + path: stderr + - format: colored-line-number # print lines of code with issue, default is true print-issued-lines: true From 35a80cf28676f37b322073d244513962a3e6ea2e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:40:06 -0500 Subject: [PATCH 3/3] chore(deps): update all non-major dependencies (#379) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 8 ++++---- .github/workflows/reviewdog.yml | 4 ++-- .github/workflows/schema.yml | 2 +- .github/workflows/test.yml | 4 ++-- .github/workflows/validate.yml | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7433661c..4471ecbe 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,7 +35,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: install go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 @@ -47,7 +47,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8 + uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -58,7 +58,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8 + uses: github/codeql-action/autobuild@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -72,4 +72,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8 + uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10 diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 68ea470a..a3459fcc 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -12,7 +12,7 @@ jobs: steps: - name: clone - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: install go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 @@ -36,7 +36,7 @@ jobs: steps: - name: clone - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: install go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 diff --git a/.github/workflows/schema.yml b/.github/workflows/schema.yml index 57f62ac7..38ac6c3f 100644 --- a/.github/workflows/schema.yml +++ b/.github/workflows/schema.yml @@ -13,7 +13,7 @@ jobs: steps: - name: clone - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: install go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60108803..0972d060 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: steps: - name: clone - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: install go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 @@ -29,7 +29,7 @@ jobs: go test -race -covermode=atomic -coverprofile=coverage.out ./... - name: coverage - uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1 + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: token: ${{ secrets.CODECOV_TOKEN }} file: coverage.out diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 700684ba..7783d860 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -14,7 +14,7 @@ jobs: steps: - name: clone - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: install go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1