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

🐛 add fallback lookup for actions/upload-artifact v3/node20 branch #599

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/server/post_results_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package server
import (
"context"
"io"
"net/http"
"os"

"github.com/google/go-github/v42/github"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -112,3 +114,36 @@ var _ = Describe("E2E Test: getAndVerifyWorkflowContent", func() {
AssertInvalidWorkflowContent("testdata/results/imposter-commit-results.json", "imposter commit")
})
})

// helper function to setup a github verifier with an appropriately set token.
func getGithubVerifier() githubVerifier {
httpClient := http.DefaultClient
token, _ := readGitHubTokens()
if token != "" {
httpClient.Transport = githubTransport{
token: token,
}
}
return githubVerifier{
ctx: context.Background(),
client: github.NewClient(httpClient),
}
}

var _ = Describe("E2E Test: githubVerifier_contains", func() {
Context("E2E Test: Validate known good commits", func() {
It("can detect actions/upload-artifact v3-node20 commits", func() {
gv := getGithubVerifier()
c, err := gv.contains("actions", "upload-artifact", "97a0fba1372883ab732affbe8f94b823f91727db")
Expect(err).Should(BeNil())
Expect(c).To(BeTrue())
})

It("can detect github/codeql-action backport commits", func() {
gv := getGithubVerifier()
c, err := gv.contains("github", "codeql-action", "a82bad71823183e5b120ab52d521460ecb0585fe")
Expect(err).Should(BeNil())
Expect(c).To(BeTrue())
})
})
})
9 changes: 8 additions & 1 deletion app/server/verify_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,23 @@ func (g *githubVerifier) contains(owner, repo, hash string) (bool, error) {
if contains {
return true, nil
}

switch {
// github/codeql-action has commits from their v1 and v2 release branch that don't show up in the default branch
// this isn't the best approach for now, but theres no universal "does this commit belong to this repo" call
if owner == "github" && repo == "codeql-action" {
case owner == "github" && repo == "codeql-action":
contains, err = g.branchContains("releases/v2", owner, repo, hash)
if err != nil {
return false, err
}
if !contains {
contains, err = g.branchContains("releases/v1", owner, repo, hash)
}

// add fallback lookup for actions/upload-artifact v3/node20 branch
// https://github.com/actions/starter-workflows/pull/2348#discussion_r1536228344
case owner == "actions" && repo == "upload-artifact":
contains, err = g.branchContains("v3/node20", owner, repo, hash)
}
return contains, err
}
Expand Down
Loading