package base // This file contains gerrithub related definitions etc import ( "encoding/json" "strings" "cue.dev/x/githubactions" ) // trybotWorkflows is a template for trybot-based repos trybotWorkflows: { (trybot.key): githubactions.#Workflow & { name: trybot.name on: { // Run nightly at 2am UTC without a cache to catch flakes. schedule: [{cron: "0 2 * * *"}] // Triggering a trybot job via a workflow_dispatch can be a useful way // to manually or automatically start a job without needing to git push. workflow_dispatch: {} } } "\(trybot.key)_dispatch": trybotDispatchWorkflow "push_tip_to_\(trybot.key)": pushTipToTrybotWorkflow } #dispatch: { type: string CL: int patchset: int targetBranch: *defaultBranch | string let p = strings.Split("\(CL)", "") let rightMostTwo = p[len(p)-2] + p[len(p)-1] ref: *"refs/changes/\(rightMostTwo)/\(CL)/\(patchset)" | string } trybotDispatchWorkflow: bashWorkflow & { #dummyDispatch?: #dispatch name: "Dispatch \(trybot.key)" on: { repository_dispatch: {} push: { // To enable testing of the dispatch itself branches: [testDefaultBranch] } } jobs: { (trybot.key): { "runs-on": linuxSmallMachine + overrideCacheTagDispatch let goodDummyData = json.Marshal(#dummyDispatch) != _|_ // We set the "on" conditions above, but this would otherwise mean we // run for all dispatch events. if: "${{ (\(isTestDefaultBranch) && \(goodDummyData)) || github.event.client_payload.type == '\(trybot.key)' }}" // See the comment below about the need for cases let cases = [ { condition: "!=" expr: "fromJSON(steps.payload.outputs.value)" nameSuffix: "fake data" }, { condition: "==" expr: "github.event.client_payload" nameSuffix: "repository_dispatch payload" }, ] steps: [ writeNetrcFile, { name: "Write fake payload" id: "payload" if: "github.repository == '\(githubRepositoryPath)' && \(isTestDefaultBranch)" // Use bash heredocs so that JSON's use of double quotes does // not get interpreted as shell. Both in the running of the // command itself, which itself is the echo-ing of a command to // $GITHUB_OUTPUT. run: #""" cat <> $GITHUB_OUTPUT value< ~/.netrc machine \(gerritHubHostname) login \(botGerritHubUser) password ${{ secrets.\(botGerritHubUserPasswordSecretsKey) }} EOD chmod 600 ~/.netrc """ }