Skip to content

Commit 69a7fbd

Browse files
add fallback lookup for actions/upload-artifact v3/node20 branch (#599)
Signed-off-by: Spencer Schrock <[email protected]>
1 parent 79a615f commit 69a7fbd

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/server/post_results_e2e_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ package server
1717
import (
1818
"context"
1919
"io"
20+
"net/http"
2021
"os"
2122

23+
"github.com/google/go-github/v42/github"
2224
. "github.com/onsi/ginkgo/v2"
2325
. "github.com/onsi/gomega"
2426

@@ -112,3 +114,36 @@ var _ = Describe("E2E Test: getAndVerifyWorkflowContent", func() {
112114
AssertInvalidWorkflowContent("testdata/results/imposter-commit-results.json", "imposter commit")
113115
})
114116
})
117+
118+
// helper function to setup a github verifier with an appropriately set token.
119+
func getGithubVerifier() githubVerifier {
120+
httpClient := http.DefaultClient
121+
token, _ := readGitHubTokens()
122+
if token != "" {
123+
httpClient.Transport = githubTransport{
124+
token: token,
125+
}
126+
}
127+
return githubVerifier{
128+
ctx: context.Background(),
129+
client: github.NewClient(httpClient),
130+
}
131+
}
132+
133+
var _ = Describe("E2E Test: githubVerifier_contains", func() {
134+
Context("E2E Test: Validate known good commits", func() {
135+
It("can detect actions/upload-artifact v3-node20 commits", func() {
136+
gv := getGithubVerifier()
137+
c, err := gv.contains("actions", "upload-artifact", "97a0fba1372883ab732affbe8f94b823f91727db")
138+
Expect(err).Should(BeNil())
139+
Expect(c).To(BeTrue())
140+
})
141+
142+
It("can detect github/codeql-action backport commits", func() {
143+
gv := getGithubVerifier()
144+
c, err := gv.contains("github", "codeql-action", "a82bad71823183e5b120ab52d521460ecb0585fe")
145+
Expect(err).Should(BeNil())
146+
Expect(c).To(BeTrue())
147+
})
148+
})
149+
})

app/server/verify_workflow.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,23 @@ func (g *githubVerifier) contains(owner, repo, hash string) (bool, error) {
263263
if contains {
264264
return true, nil
265265
}
266+
267+
switch {
266268
// github/codeql-action has commits from their v1 and v2 release branch that don't show up in the default branch
267269
// this isn't the best approach for now, but theres no universal "does this commit belong to this repo" call
268-
if owner == "github" && repo == "codeql-action" {
270+
case owner == "github" && repo == "codeql-action":
269271
contains, err = g.branchContains("releases/v2", owner, repo, hash)
270272
if err != nil {
271273
return false, err
272274
}
273275
if !contains {
274276
contains, err = g.branchContains("releases/v1", owner, repo, hash)
275277
}
278+
279+
// add fallback lookup for actions/upload-artifact v3/node20 branch
280+
// https://github.com/actions/starter-workflows/pull/2348#discussion_r1536228344
281+
case owner == "actions" && repo == "upload-artifact":
282+
contains, err = g.branchContains("v3/node20", owner, repo, hash)
276283
}
277284
return contains, err
278285
}

0 commit comments

Comments
 (0)