Skip to content

Commit 95a88a5

Browse files
committed
internal/ci: add gcloud auth to the e2e tests
And un-skip the test script, now that it's set up to run in CI. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I7000939a0c8200426d6d8d174c564fa72246461a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1171938 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent d947a69 commit 95a88a5

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

.github/workflows/trybot.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,28 @@ jobs:
182182
run: go test -race ./...
183183
env:
184184
GORACE: atexit_sleep_ms=10
185+
- name: gcloud auth for end-to-end tests
186+
id: auth
187+
if: |-
188+
github.repository == 'cue-lang/cue' && ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
189+
Dispatch-Trailer: {"type":"')))) && (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
190+
uses: google-github-actions/auth@v1
191+
with:
192+
credentials_json: ${{ secrets.E2E_GCLOUD_KEY }}
193+
- if: |-
194+
github.repository == 'cue-lang/cue' && ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
195+
Dispatch-Trailer: {"type":"')))) && (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
196+
name: gcloud setup for end-to-end tests
197+
uses: google-github-actions/setup-gcloud@v1
185198
- if: |-
186199
github.repository == 'cue-lang/cue' && ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
187200
Dispatch-Trailer: {"type":"')))) && (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
188201
name: End-to-end test
202+
env:
203+
GITHUB_TOKEN: ${{ secrets.E2E_GITHUB_TOKEN }}
189204
run: |-
190205
cd internal/e2e
191206
go test
192-
env:
193-
GITHUB_TOKEN: ${{ secrets.E2E_GITHUB_TOKEN }}
194207
- if: (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
195208
name: Check
196209
run: |-

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ cmd/cue/cue
1010
# We use test module paths like mod.test or externalmod.test.
1111
# Don't exclude those as if they were test binaries.
1212
!**/*mod.test
13+
14+
# Ignore generated credentials from google-github-actions/auth,
15+
# a GitHub Actions step used in CI for the tests in internal/e2e.
16+
# Note that CI requires a clean git repo when it finishes,
17+
# so we don't want it to think the credentials file is untracked.
18+
gha-creds-*.json

internal/ci/github/trybot.cue

+30-15
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ workflows: trybot: _repo.bashWorkflow & {
7575
_goTestRace & {
7676
if: _isLatestLinux
7777
},
78-
_e2eTest,
78+
for v in _e2eTestSteps {v},
7979
_goCheck,
8080
_repo.checkGitClean,
8181
]
@@ -115,24 +115,39 @@ workflows: trybot: _repo.bashWorkflow & {
115115
run: "go test ./..."
116116
}
117117

118-
_e2eTest: json.#step & {
119-
name: "End-to-end test"
118+
_e2eTestSteps: [... json.#step & {
120119
// The end-to-end tests require a github token secret and are a bit slow,
121120
// so we only run them on pushes to protected branches and on one
122121
// environment in the source repo.
123122
if: "github.repository == '\(_repo.githubRepositoryPath)' && \(_repo.isProtectedBranch) && \(_isLatestLinux)"
124-
125-
// The secret is the fine-grained access token "cue-lang/cue ci e2e for modules-testing"
126-
// owned by the porcuepine bot account with read+write access to repo administration and code
127-
// on the entire cue-labs-modules-testing org. Note that porcuepine is also an org admin,
128-
// since otherwise the repo admin access to create and delete repos does not work.
129-
env: GITHUB_TOKEN: "${{ secrets.E2E_GITHUB_TOKEN }}"
130-
131-
run: """
132-
cd internal/e2e
133-
go test
134-
"""
135-
}
123+
}] & [
124+
// Two setup steps per the upstream docs:
125+
// https://github.com/google-github-actions/setup-gcloud#service-account-key-json
126+
{
127+
name: "gcloud auth for end-to-end tests"
128+
id: "auth"
129+
uses: "google-github-actions/auth@v1"
130+
// E2E_GCLOUD_KEY is a key for the service account cue-e2e-ci,
131+
// which has the Artifact Registry Repository Administrator role.
132+
with: credentials_json: "${{ secrets.E2E_GCLOUD_KEY }}"
133+
},
134+
{
135+
name: "gcloud setup for end-to-end tests"
136+
uses: "google-github-actions/setup-gcloud@v1"
137+
},
138+
{
139+
name: "End-to-end test"
140+
// The secret is the fine-grained access token "cue-lang/cue ci e2e for modules-testing"
141+
// owned by the porcuepine bot account with read+write access to repo administration and code
142+
// on the entire cue-labs-modules-testing org. Note that porcuepine is also an org admin,
143+
// since otherwise the repo admin access to create and delete repos does not work.
144+
env: GITHUB_TOKEN: "${{ secrets.E2E_GITHUB_TOKEN }}"
145+
run: """
146+
cd internal/e2e
147+
go test
148+
"""
149+
},
150+
]
136151

137152
_goCheck: json.#step & {
138153
// These checks can vary between platforms, as different code can be built

internal/e2e/testdata/script/gcloud_upload.txtar

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# to an off-the-shelf OCI registry which requires authentication.
33
# Then fetch that module as a dependency via cmd/cue.
44

5-
skip 'TODO(mvdan): set up a service account key on GitHub Actions'
6-
75
gcloud-auth-docker # sets: MODULE, CUE_REGISTRY, CUE_REGISTRY_HOST, CLOUDSDK_CONFIG
86
env DOCKER_CONFIG=$WORK/docker-config
97
env-fill docker-config/config.json

0 commit comments

Comments
 (0)