Skip to content

Commit

Permalink
internal/ci: collapse gerrithub package into base
Browse files Browse the repository at this point in the history
The separation has long been rather awkward, and with hindsight was
definition a premature optimisation or attempt at spotting an API before
a pattern emerges.

If at a later date the need for a split is real, an API for a good split
will likely present itself.

This change should not result in any .github/workflows changes.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ie21c7972dd4e393a0740badececf87ecbef42781
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551539
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
myitcv committed Mar 26, 2023
1 parent 1980621 commit 9729270
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 67 deletions.
15 changes: 15 additions & 0 deletions internal/ci/base/base.cue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
package base

import (
"path"
"strings"
)

Expand All @@ -43,6 +44,20 @@ import (
#protectedBranchPatterns: [...string]
#releaseTagPattern: string

#linuxMachine: string
#gerritHubHostname: string
#gerritHubRepositoryURL: string
#trybotRepositoryURL: *(#githubRepositoryURL + "-" + trybot.key) | string
#botGitHubUserEmail: string
#botGerritHubUser: *#botGitHubUser | string
#botGerritHubUserPasswordSecretsKey: string
#botGerritHubUserEmail: *#botGitHubUserEmail | string

// Pending cuelang.org/issue/1433, hack around defaulting #gerritHubRepository
// based on #repository
let _#repositoryURLNoScheme = strings.Split(#githubRepositoryURL, "//")[1]
#gerritHubRepository: *("https://\(#gerritHubHostname)/a/" + path.Base(path.Dir(_#repositoryURLNoScheme)) + "/" + path.Base(_#repositoryURLNoScheme)) | _

// Define some shared keys and human-readable names.
//
// trybot.key and unity.key are shared with
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,11 @@
// Copyright 2022 The CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package base

// package gerritHub is a collection of features that are common to projects
// that choose to make GerritHub their source of truth, using GitHub Actions
// for CI.
//
// See the documentation for gerritstatusupdater for more information:
//
// github.com/cue-lang/cuelang.org/internal/functions/gerritstatusupdater
//
package gerrithub
// This file contains gerrithub related definitions etc

import (
"path"
"strings"

"github.com/SchemaStore/schemastore/src/schemas/json"
)

#githubRepositoryURL: string
#gerritHubRepositoryURL: string
#trybotKey: string
#trybotRepositoryURL: *(#githubRepositoryURL + "-" + #trybotKey) | string
#botGitHubUser: string
#botGitHubUserTokenSecretsKey: string
#botGitHubUserEmail: string
#botGerritHubUser: *#botGitHubUser | string
#botGerritHubUserPasswordSecretsKey: string
#botGerritHubUserEmail: *#botGitHubUserEmail | string
#gerritHubHostname: string
#linuxMachine: string

// Pending cuelang.org/issue/1433, hack around defaulting #gerritHubRepository
// based on #repository
let _#repositoryURLNoScheme = strings.Split(#githubRepositoryURL, "//")[1]
#gerritHubRepository: *("https://\(#gerritHubHostname)/a/" + path.Base(path.Dir(_#repositoryURLNoScheme)) + "/" + path.Base(_#repositoryURLNoScheme)) | _

#trybotDispatchWorkflow: json.#Workflow & {
#type: string
_#branchNameExpression: "\(#type)/${{ github.event.client_payload.payload.changeID }}/${{ github.event.client_payload.payload.commit }}/${{ steps.gerrithub_ref.outputs.gerrithub_ref }}"
Expand All @@ -58,7 +17,7 @@ let _#repositoryURLNoScheme = strings.Split(#githubRepositoryURL, "//")[1]
"runs-on": #linuxMachine
if: "${{ github.event.client_payload.type == '\(#type)' }}"
steps: [
_#writeNetrcFile,
#writeNetrcFile,
// Out of the entire ref (e.g. refs/changes/38/547738/7) we only
// care about the CL number and patchset, (e.g. 547738/7).
// Note that gerrithub_ref is two path elements.
Expand Down Expand Up @@ -95,13 +54,13 @@ let _#repositoryURLNoScheme = strings.Split(#githubRepositoryURL, "//")[1]
#pushTipToTrybotWorkflow: json.#Workflow & {
jobs: [string]: defaults: run: shell: "bash"

name: "Push tip to \(#trybotKey)"
name: "Push tip to \(trybot.key)"

concurrency: "push_tip_to_trybot"

jobs: push: {
steps: [
_#writeNetrcFile,
#writeNetrcFile,
json.#step & {
name: "Push tip to trybot"
run: """
Expand All @@ -122,7 +81,7 @@ let _#repositoryURLNoScheme = strings.Split(#githubRepositoryURL, "//")[1]

}

_#writeNetrcFile: json.#step & {
#writeNetrcFile: json.#step & {
name: "Write netrc file for cueckoo Gerrithub"
run: """
cat <<EOD > ~/.netrc
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/github/push_tip_to_trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// push_tip_to_trybot "syncs" active branches to the trybot repo.
// Since the workflow is triggered by a push to any of the branches,
// the step only needs to sync the pushed branch.
workflows: push_tip_to_trybot: _gerrithub.#pushTipToTrybotWorkflow & {
workflows: push_tip_to_trybot: _base.#pushTipToTrybotWorkflow & {
on: {
push: branches: core.protectedBranchPatterns
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/github/trybot_dispatch.cue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
package github

// The trybot_dispatch workflow.
workflows: trybot_dispatch: _base.#bashWorkflow & _gerrithub.#trybotDispatchWorkflow & {
workflows: trybot_dispatch: _base.#bashWorkflow & _base.#trybotDispatchWorkflow & {
#type: _base.trybot.key
}
30 changes: 12 additions & 18 deletions internal/ci/github/workflows.cue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package github
import (
"cuelang.org/go/internal/ci/core"
"cuelang.org/go/internal/ci/base"
"cuelang.org/go/internal/ci/gerrithub"

"github.com/SchemaStore/schemastore/src/schemas/json"
)
Expand Down Expand Up @@ -52,23 +51,7 @@ workflows: close({
evict_caches: _
})

// _gerrithub is an instance of ./gerrithub, parameterised by the properties of
// this project
_gerrithub: gerrithub & {
#githubRepositoryURL: core.githubRepositoryURL
#trybotKey: _base.trybot.key
#botGitHubUser: core.botGitHubUser
#botGitHubUserTokenSecretsKey: core.botGitHubUserTokenSecretsKey
#botGitHubUserEmail: core.botGitHubUserEmail
#botGerritHubUser: core.botGitHubUser
#botGerritHubUserPasswordSecretsKey: core.botGerritHubUserPasswordSecretsKey
#botGerritHubUserEmail: core.botGitHubUserEmail
#gerritHubHostname: core.gerritHubHostname
#linuxMachine: core.linuxMachine
}

// _base is an instance of ./base, parameterised by the properties of this
// project
// _base is an instance of ./base, parameterised by the configuration in core
//
// TODO: revisit the naming strategy here. _base and base are very similar.
// Perhaps rename the import to something more obviously not intended to be
Expand All @@ -80,4 +63,15 @@ _base: base & {
#botGitHubUserTokenSecretsKey: core.botGitHubUserTokenSecretsKey
#protectedBranchPatterns: core.protectedBranchPatterns
#releaseTagPattern: core.releaseTagPattern

#githubRepositoryURL: core.githubRepositoryURL
#trybotKey: _base.trybot.key
#botGitHubUser: core.botGitHubUser
#botGitHubUserTokenSecretsKey: core.botGitHubUserTokenSecretsKey
#botGitHubUserEmail: core.botGitHubUserEmail
#botGerritHubUser: core.botGitHubUser
#botGerritHubUserPasswordSecretsKey: core.botGerritHubUserPasswordSecretsKey
#botGerritHubUserEmail: core.botGitHubUserEmail
#gerritHubHostname: core.gerritHubHostname
#linuxMachine: core.linuxMachine
}

0 comments on commit 9729270

Please sign in to comment.