Skip to content

Commit

Permalink
internal/ci: use githubactions schema from registry
Browse files Browse the repository at this point in the history
This change uses the WIP githubactions schema from
`github.com/cue-tmp/jsonschema-pub/exp1/githubactions`,

This enables us to remove the code that vendors the schema
from the SchemaStore repository.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Ib57d02be507ad08e7ad726b6c85696d662f50cec
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201986
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
rogpeppe committed Oct 1, 2024
1 parent 92330b4 commit 093a2c6
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 1,080 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/trybot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ jobs:
exit 1
fi
- name: Generate
run: go generate ./...
env:
CUE_LOGINS: ${{ secrets.NOTCUECKOO_CUE_LOGINS }}
run: |-
export CUE_CONFIG_DIR=$(mktemp -d)
echo "$CUE_LOGINS" > $CUE_CONFIG_DIR/logins.json
go generate ./...
if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04')
- name: Check that git is clean at the end of the job
if: always()
Expand Down
6 changes: 6 additions & 0 deletions cue.mod/module.cue
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ module: "cuelang.org/go"
language: {
version: "v0.8.0"
}
deps: {
"github.com/cue-tmp/jsonschema-pub/exp1/githubactions@v0": {
v: "v0.3.0"
default: true
}
}

This file was deleted.

This file was deleted.

22 changes: 11 additions & 11 deletions internal/ci/base/gerrithub.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package base
// This file contains gerrithub related definitions etc

import (
encjson "encoding/json"
"encoding/json"
"strings"

"github.com/SchemaStore/schemastore/src/schemas/json"
"github.com/cue-tmp/jsonschema-pub/exp1/githubactions"
)

// trybotWorkflows is a template for trybot-based repos
trybotWorkflows: {
(trybot.key): json.#Workflow & {
(trybot.key): githubactions.#Workflow & {
on: workflow_dispatch: {}
}
"\(trybot.key)_dispatch": trybotDispatchWorkflow
Expand Down Expand Up @@ -45,7 +45,7 @@ trybotDispatchWorkflow: bashWorkflow & {
(trybot.key): {
"runs-on": linuxMachine

let goodDummyData = [if encjson.Marshal(#dummyDispatch) != _|_ {true}, false][0]
let goodDummyData = [if json.Marshal(#dummyDispatch) != _|_ {true}, false][0]

// We set the "on" conditions above, but this would otherwise mean we
// run for all dispatch events.
Expand All @@ -68,7 +68,7 @@ trybotDispatchWorkflow: bashWorkflow & {
steps: [
writeNetrcFile,

json.#step & {
githubactions.#Step & {
name: "Write fake payload"
id: "payload"
if: "github.repository == '\(githubRepositoryPath)' && \(isTestDefaultBranch)"
Expand All @@ -80,7 +80,7 @@ trybotDispatchWorkflow: bashWorkflow & {
run: #"""
cat <<EOD >> $GITHUB_OUTPUT
value<<DOE
\#(*encjson.Marshal(#dummyDispatch) | "null")
\#(*json.Marshal(#dummyDispatch) | "null")
DOE
EOD
"""#
Expand All @@ -97,7 +97,7 @@ trybotDispatchWorkflow: bashWorkflow & {
for v in cases {
let localBranchExpr = "local_${{ \(v.expr).targetBranch }}"
let targetBranchExpr = "${{ \(v.expr).targetBranch }}"
json.#step & {
githubactions.#Step & {
name: "Trigger \(trybot.name) (\(v.nameSuffix))"
if: "github.event.client_payload.type \(v.condition) '\(trybot.key)'"
run: """
Expand Down Expand Up @@ -174,7 +174,7 @@ pushTipToTrybotWorkflow: bashWorkflow & {
jobs: push: {
steps: [
writeNetrcFile,
json.#step & {
githubactions.#Step & {
name: "Push tip to trybot"
run: """
mkdir tmpgit
Expand Down Expand Up @@ -248,7 +248,7 @@ evictCaches: bashWorkflow & {
steps: [
for v in checkoutCode {v},

json.#step & {
githubactions.#Step & {
name: "Delete caches"
run: """
set -x
Expand All @@ -269,7 +269,7 @@ evictCaches: bashWorkflow & {
"""
},

json.#step & {
githubactions.#Step & {
name: "Trigger workflow runs to repopulate caches"
let branchPatterns = strings.Join(protectedBranchPatterns, " ")

Expand Down Expand Up @@ -343,7 +343,7 @@ evictCaches: bashWorkflow & {
}
}

writeNetrcFile: json.#step & {
writeNetrcFile: githubactions.#Step & {
name: "Write netrc file for \(botGerritHubUser) Gerrithub"
run: """
cat <<EOD > ~/.netrc
Expand Down
40 changes: 20 additions & 20 deletions internal/ci/base/github.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package base
// This file contains aspects principally related to GitHub workflows

import (
encjson "encoding/json"
"encoding/json"
"list"
"strings"
"strconv"

"github.com/SchemaStore/schemastore/src/schemas/json"
"github.com/cue-tmp/jsonschema-pub/exp1/githubactions"
)

bashWorkflow: json.#Workflow & {
bashWorkflow: githubactions.#Workflow & {
jobs: [string]: defaults: run: shell: "bash"
}

installGo: {
#setupGo: json.#step & {
#setupGo: githubactions.#Step & {
name: "Install Go"
uses: "actions/setup-go@v5"
with: {
Expand Down Expand Up @@ -49,7 +49,7 @@ installGo: {
#setupGo,

{
json.#step & {
githubactions.#Step & {
name: "Set common go env vars"
run: """
go env -w GOTOOLCHAIN=local
Expand All @@ -63,7 +63,7 @@ installGo: {
}

checkoutCode: {
#actionsCheckout: json.#step & {
#actionsCheckout: githubactions.#Step & {
name: "Checkout code"
uses: "actions/checkout@v4"

Expand All @@ -90,17 +90,17 @@ checkoutCode: {
// per the bug report at https://github.com/MestreLion/git-tools/issues/47,
// so we first reset all directory timestamps to a static time as a fallback.
// TODO(mvdan): May be unnecessary once the Go bug above is fixed.
json.#step & {
githubactions.#Step & {
name: "Reset git directory modification times"
run: "touch -t 202211302355 $(find * -type d)"
},
json.#step & {
githubactions.#Step & {
name: "Restore git file modification times"
uses: "chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe"
},

{
json.#step & {
githubactions.#Step & {
name: "Try to extract \(dispatchTrailer)"
id: dispatchTrailerStepID
run: """
Expand All @@ -124,7 +124,7 @@ checkoutCode: {

// Safety nets to flag if we ever have a Dispatch-Trailer slip through the
// net and make it to master
json.#step & {
githubactions.#Step & {
name: "Check we don't have \(dispatchTrailer) on a protected branch"
if: "\(isProtectedBranch) && \(containsDispatchTrailer)"
run: """
Expand All @@ -135,7 +135,7 @@ checkoutCode: {
]
}

earlyChecks: json.#step & {
earlyChecks: githubactions.#Step & {
name: "Early git and code sanity checks"
run: *"go run cuelang.org/go/internal/ci/[email protected]" | string
}
Expand Down Expand Up @@ -177,7 +177,7 @@ setupGoActionsCaches: {

let cacheRestoreKeys = "\(#os)-\(#goVersion)"

let cacheStep = json.#step & {
let cacheStep = githubactions.#Step & {
with: {
path: strings.Join(cacheDirs, "\n")

Expand All @@ -197,12 +197,12 @@ setupGoActionsCaches: {
[
// TODO: once https://github.com/actions/setup-go/issues/54 is fixed,
// we could use `go env` outputs from the setup-go step.
json.#step & {
githubactions.#Step & {
name: "Get go mod cache directory"
id: goModCacheDirID
run: #"echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT}"#
},
json.#step & {
githubactions.#Step & {
name: "Get go build/test cache directory"
id: goCacheDirID
run: #"echo "dir=$(go env GOCACHE)" >> ${GITHUB_OUTPUT}"#
Expand Down Expand Up @@ -240,7 +240,7 @@ setupGoActionsCaches: {
//
// Critically we only want to do this in the main repo, not the trybot
// repo.
json.#step & {
githubactions.#Step & {
if: "github.repository == '\(githubRepositoryPath)' && (\(isProtectedBranch) || github.ref == 'refs/heads/\(testDefaultBranch)')"
run: "go clean -testcache"
}
Expand Down Expand Up @@ -270,13 +270,13 @@ isReleaseTag: {
(_matchPattern & {variable: "github.ref", pattern: "refs/tags/\(releaseTagPattern)"}).expr
}

checkGitClean: json.#step & {
checkGitClean: githubactions.#Step & {
name: "Check that git is clean at the end of the job"
if: "always()"
run: "test -z \"$(git status --porcelain)\" || (git status; git diff; false)"
}

repositoryDispatch: json.#step & {
repositoryDispatch: githubactions.#Step & {
#githubRepositoryPath: *githubRepositoryPath | string
#botGitHubUserTokenSecretsKey: *botGitHubUserTokenSecretsKey | string
#arg: _
Expand All @@ -285,11 +285,11 @@ repositoryDispatch: json.#step & {

name: string
run: #"""
\#(_curlGitHubAPI) --fail --request POST --data-binary \#(strconv.Quote(encjson.Marshal(#arg))) https://api.github.com/repos/\#(#githubRepositoryPath)/dispatches
\#(_curlGitHubAPI) --fail --request POST --data-binary \#(strconv.Quote(json.Marshal(#arg))) https://api.github.com/repos/\#(#githubRepositoryPath)/dispatches
"""#
}

workflowDispatch: json.#step & {
workflowDispatch: githubactions.#Step & {
#githubRepositoryPath: *githubRepositoryPath | string
#botGitHubUserTokenSecretsKey: *botGitHubUserTokenSecretsKey | string
#workflowID: string
Expand All @@ -303,7 +303,7 @@ workflowDispatch: json.#step & {

name: string
run: #"""
\#(_curlGitHubAPI) --fail --request POST --data-binary \#(strconv.Quote(encjson.Marshal(#params))) https://api.github.com/repos/\#(#githubRepositoryPath)/actions/workflows/\#(#workflowID)/dispatches
\#(_curlGitHubAPI) --fail --request POST --data-binary \#(strconv.Quote(json.Marshal(#params))) https://api.github.com/repos/\#(#githubRepositoryPath)/actions/workflows/\#(#workflowID)/dispatches
"""#
}

Expand Down
1 change: 0 additions & 1 deletion internal/ci/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@

package ci

//go:generate go run cuelang.org/go/cmd/cue cmd importjsonschema ./vendor
//go:generate go run cuelang.org/go/cmd/cue cmd gen
14 changes: 7 additions & 7 deletions internal/ci/github/release.cue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package github
import (
"list"

"github.com/SchemaStore/schemastore/src/schemas/json"
"github.com/cue-tmp/jsonschema-pub/exp1/githubactions"
)

// _cueVersionRef is a workflow job-runtime expression that evaluates to the
Expand Down Expand Up @@ -50,15 +50,15 @@ workflows: release: _repo.bashWorkflow & {
steps: [
for v in _repo.checkoutCode {v},
for v in installGo {v},
json.#step & {
githubactions.#Step & {
name: "Setup qemu"
uses: "docker/setup-qemu-action@v3"
},
json.#step & {
githubactions.#Step & {
name: "Set up Docker Buildx"
uses: "docker/setup-buildx-action@v3"
},
json.#step & {
githubactions.#Step & {
name: "Docker Login"
uses: "docker/login-action@v3"
with: {
Expand All @@ -67,19 +67,19 @@ workflows: release: _repo.bashWorkflow & {
password: "${{ secrets.CUECKOO_DOCKER_PAT }}"
}
},
json.#step & {
githubactions.#Step & {
name: "Install CUE"
run: "go install ./cmd/cue"
},
json.#step & {
githubactions.#Step & {
name: "Install GoReleaser"
uses: "goreleaser/goreleaser-action@v5"
with: {
"install-only": true
version: _repo.goreleaserVersion
}
},
json.#step & {
githubactions.#Step & {
// Note that the logic for what gets run at release time
// is defined with the release command in CUE.
name: "Run GoReleaser with CUE"
Expand Down
Loading

0 comments on commit 093a2c6

Please sign in to comment.