Skip to content

Commit 2873c0d

Browse files
laurentsimonnaveensrinivasan
authored andcommitted
e2e for GITHUB_TOKEN
1 parent a46313c commit 2873c0d

File tree

4 files changed

+119
-7
lines changed

4 files changed

+119
-7
lines changed

.github/workflows/integration.yml

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,89 @@ jobs:
7474
run: |
7575
go mod download
7676
77-
- name: Run E2E #using retry because the GitHub token is being throttled.
77+
- name: Run PAT E2E #using retry because the GitHub token is being throttled.
7878
uses: nick-invision/retry@7f8f3d9f0f62fe5925341be21c2e8314fd4f7c7c
7979
env:
8080
GITHUB_AUTH_TOKEN: ${{ secrets.GH_AUTH_TOKEN }}
8181
with:
8282
max_attempts: 3
8383
retry_on: error
8484
timeout_minutes: 30
85-
command: make e2e
85+
command: make e2e-pat
86+
87+
- name: codecov
88+
uses: codecov/codecov-action@e3c560433a6cc60aec8812599b7844a7b4fa0d71 # 2.1.0
89+
with:
90+
files: ./e2e-coverage.out
91+
verbose: true
92+
93+
- name: find comment
94+
uses: peter-evans/find-comment@1769778a0c5bd330272d749d12c036d65e70d39d # v1.2.0
95+
id: fc
96+
with:
97+
issue-number: ${{ github.event.pull_request.number || github.event.client_payload.pull_request.number }}
98+
comment-author: 'github-actions[bot]'
99+
body-includes: Integration tests ran for
100+
101+
- name: create or update comment
102+
uses: peter-evans/create-or-update-comment@c9fcb64660bc90ec1cc535646af190c992007c32 # v1.4.5
103+
with:
104+
issue-number: ${{ github.event.pull_request.number || github.event.client_payload.pull_request.number }}
105+
comment-id: ${{ steps.fc.outputs.comment-id }}
106+
body: |
107+
Integration tests ${{ job.status }} for
108+
[${{ github.event.client_payload.slash_command.args.named.sha || github.event.pull_request.head.sha }}]
109+
(https://github.com/ossf/scorecard/actions/runs/${{ github.run_id }})
110+
111+
integration-gh-token:
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Harden Runner
115+
uses: step-security/harden-runner@bdb12b622a910dfdc99a31fdfe6f45a16bc287a4 # v1
116+
with:
117+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
118+
119+
- name: pull_request actions/checkout
120+
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v2.3.4
121+
with:
122+
ref: ${{ github.event.pull_request.head.sha }}
123+
124+
- name: setup-go
125+
uses: actions/setup-go@f6164bd8c8acb4a71fb2791a8b6c4024ff038dab # v2.2.0
126+
with:
127+
go-version: '1.17'
128+
129+
- name: Cache builds
130+
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
131+
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09 #v2.1.7
132+
with:
133+
# In order:
134+
# * Module download cache
135+
# * Build cache (Linux)
136+
# * Build cache (Mac)
137+
# * Build cache (Windows)
138+
path: |
139+
~/go/pkg/mod
140+
~/.cache/go-build
141+
~/Library/Caches/go-build
142+
%LocalAppData%\go-build
143+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
144+
restore-keys: |
145+
${{ runner.os }}-go-
146+
147+
- name: Prepare test env
148+
run: |
149+
go mod download
150+
151+
- name: Run GITHUB_TOKEN E2E #using retry because the GitHub token is being throttled.
152+
uses: nick-invision/retry@7f8f3d9f0f62fe5925341be21c2e8314fd4f7c7c
153+
env:
154+
GITHUB_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
with:
156+
max_attempts: 3
157+
retry_on: error
158+
timeout_minutes: 30
159+
command: make e2e-gh-token
86160

87161
- name: codecov
88162
uses: codecov/codecov-action@e3c560433a6cc60aec8812599b7844a7b4fa0d71 # 2.1.0

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ cron-github-server-docker:
277277

278278
##@ Tests
279279
################################# make test ###################################
280-
test-targets = unit-test e2e ci-e2e
280+
test-targets = unit-test e2e-pat e2e-gh-token ci-e2e
281281
.PHONY: test $(test-targets)
282282
test: $(test-targets)
283283

@@ -293,8 +293,13 @@ ifndef GITHUB_AUTH_TOKEN
293293
$(error GITHUB_AUTH_TOKEN is undefined)
294294
endif
295295

296-
e2e: ## Runs e2e tests. Requires GITHUB_AUTH_TOKEN env var to be set to GitHub personal access token
297-
e2e: build-scorecard check-env | $(GINKGO)
296+
e2e-pat: ## Runs e2e tests. Requires GITHUB_AUTH_TOKEN env var to be set to GitHub personal access token
297+
e2e-pat: build-scorecard check-env | $(GINKGO)
298298
# Run e2e tests. GITHUB_AUTH_TOKEN with personal access token must be exported to run this
299-
$(GINKGO) --race -p -v -cover -coverprofile=e2e-coverage.out ./...
299+
TOKEN_TYPE="PAT" $(GINKGO) --race -p -v -cover -coverprofile=e2e-coverage.out ./...
300+
301+
e2e-gh-token: ## Runs e2e tests. Requires GITHUB_AUTH_TOKEN env var to be set to default GITHUB_TOKEN
302+
e2e-gh-token: build-scorecard check-env | $(GINKGO)
303+
# Run e2e tests. GITHUB_AUTH_TOKEN set to secrets.GITHUB_TOKEN must be used to run this.
304+
TOKEN_TYPE="GITHUB_TOKEN" $(GINKGO) --race -p -v -cover -coverprofile=e2e-coverage.out ./...
300305
###############################################################################

e2e/branch_protection_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import (
2727
scut "github.com/ossf/scorecard/v4/utests"
2828
)
2929

30-
var _ = Describe("E2E TEST:"+checks.CheckBranchProtection, func() {
30+
var _ = Describe("E2E TEST PAT:"+checks.CheckBranchProtection, func() {
3131
Context("E2E TEST:Validating branch protection", func() {
32+
skipIfTokenIs(githubWorkflowDefaultTokenType, checks.CheckBranchProtection+" does not support GITHUB_TOKEN")
33+
3234
It("Should get non-admin branch protection on other repositories", func() {
3335
dl := scut.TestDetailLogger{}
3436
repo, err := githubrepo.MakeGithubRepo("ossf-tests/scorecard-check-branch-protection-e2e")

e2e/e2e_suite_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package e2e
1616

1717
import (
18+
"fmt"
1819
"os"
1920
"testing"
2021

@@ -35,6 +36,36 @@ func TestE2e(t *testing.T) {
3536

3637
var logger *log.Logger
3738

39+
type tokenType int
40+
41+
const (
42+
patTokenType tokenType = iota
43+
githubWorkflowDefaultTokenType
44+
)
45+
46+
var tokType tokenType
47+
48+
func skipIfTokenIs(t tokenType, msg string) {
49+
if tokType == t {
50+
Skip(msg)
51+
}
52+
}
53+
54+
func skipIfTokenIsNot(t tokenType, msg string) {
55+
if tokType != t {
56+
Skip(msg)
57+
}
58+
}
59+
3860
var _ = BeforeSuite(func() {
3961
logger = log.NewLogger(log.DebugLevel)
62+
tt := os.Getenv("TOKEN_TYPE")
63+
switch tt {
64+
case "PAT":
65+
tokType = patTokenType
66+
case "GITHUB_TOKEN":
67+
tokType = githubWorkflowDefaultTokenType
68+
default:
69+
panic(fmt.Sprintf("invald TOKEN_TYPE: %s", tt))
70+
}
4071
})

0 commit comments

Comments
 (0)