package base // This file contains gerrithub related definitions etc import ( encjson "encoding/json" "strings" "github.com/SchemaStore/schemastore/src/schemas/json" ) // trybotWorkflows is a template for trybot-based repos trybotWorkflows: { (trybot.key): json.#Workflow & { on: workflow_dispatch: {} } "\(trybot.key)_dispatch": trybotDispatchWorkflow "push_tip_to_\(trybot.key)": pushTipToTrybotWorkflow "evict_caches": evictCaches } #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: [string]: defaults: run: shell: "bash" jobs: { (trybot.key): { "runs-on": linuxMachine let goodDummyData = [if encjson.Marshal(#dummyDispatch) != _|_ {true}, false][0] // 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, json.#step & { 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 """ }