Skip to content

Commit

Permalink
internal/ci: re-baseline base from cue-lang/cue@2d329b54
Browse files Browse the repository at this point in the history
Includes:

* Use CUE v0.10.0 in go:generate steps (we need a better way of driving
  this).
* Define language.version in the repo's CUE module.
* Changes to use new multi-step installGo.
* Use go1.23.x as the Go version for the repo.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: Icbd05ac770aaf6b49ab400cf9654a1ef7d02e0e1
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue-api-java/+/1200743
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
myitcv committed Sep 6, 2024
1 parent c4bb242 commit 477351d
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
echo Latest commit: $sha
echo "Trigger workflow on cue-lang/cue-api-java"
curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue-api-java/actions/workflows/trybot.yml/dispatches -d "{\"ref\":\"$j\"}"
curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue-api-java/actions/workflows/trybot.yaml/dispatches -d "{\"ref\":\"$j\"}"
# Ensure that the trybot repo has the latest commit for
# this branch. If the force-push results in a commit
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
# We are up-to-date, i.e. the push did nothing, hence we need to trigger a workflow_dispatch
# in the trybot repo.
echo "Trigger workflow on cue-lang/cue-api-java-trybot"
curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue-api-java-trybot/actions/workflows/trybot.yml/dispatches -d "{\"ref\":\"$j\"}"
curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue-api-java-trybot/actions/workflows/trybot.yaml/dispatches -d "{\"ref\":\"$j\"}"
else
echo "Force-push to cue-lang/cue-api-java-trybot did work; nothing to do"
fi
Expand Down
File renamed without changes.
44 changes: 7 additions & 37 deletions .github/workflows/trybot.yml → .github/workflows/trybot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ jobs:
with:
cache: false
go-version: ${{ matrix.go-version }}
- name: Set common go env vars
run: |-
go env -w GOTOOLCHAIN=local
# Dump env for good measure
go env
- name: Install Java
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -113,43 +119,7 @@ jobs:
cp libcue.so cue.dll
working-directory: libcue
- name: Early git and code sanity checks
run: |-
# Ensure that commit messages have a blank second line.
# We know that a commit message must be longer than a single
# line because each commit must be signed-off.
if git log --format=%B -n 1 HEAD | sed -n '2{/^$/{q1}}'; then
echo "second line of commit message must be blank"
exit 1
fi
# All authors, including co-authors, must have a signed-off trailer by email.
# Note that trailers are in the form "Name <email>", so grab the email with sed.
# For now, we require the sorted lists of author and signer emails to match.
# Note that this also fails if a commit isn't signed-off at all.
#
# In Gerrit we already enable a form of this via https://gerrit-review.googlesource.com/Documentation/project-configuration.html#require-signed-off-by,
# but it does not support co-authors nor can it be used when testing GitHub PRs.
commit_authors="$(
{
git log -1 --pretty='%ae'
git log -1 --pretty='%(trailers:key=Co-authored-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
} | sort -u
)"
commit_signers="$(
{
git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
} | sort -u
)"
if [[ "${commit_authors}" != "${commit_signers}" ]]; then
echo "Error: commit author email addresses do not match signed-off-by trailers"
echo
echo "Authors:"
echo "${commit_authors}"
echo
echo "Signers:"
echo "${commit_signers}"
exit 1
fi
run: go run cuelang.org/go/internal/ci/[email protected]
- name: Test
run: mvn clean install package
env:
Expand Down
File renamed without changes.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package json

#job: ((#Workflow & {}).jobs & {x: _}).x
#step: ((#job & {steps: _}).steps & [_])[0]
#job: ((#Workflow & {jobs: _}).jobs & {x: _}).x
#step: ((#job & {steps: _}).steps & [_])[0]

// CUE does not properly encode a JSON Schema oneOf; see
// https://cuelang.org/issue/3165. For now, apply a temporary workaround which
// forces the other option to bottom.
#Workflow: jobs?: [string]: steps?: [...(
{
uses?: _|_
} | {
run?: _|_
}),
]
6 changes: 3 additions & 3 deletions internal/ci/base/base.cue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

// Package parameters
githubRepositoryPath: *(URLPath & {#url: githubRepositoryURL, _}) | string
githubRepositoryPath: *(URLPath & {#url: githubRepositoryURL, _}) | string
githubRepositoryURL: *("https://github.com/" + githubRepositoryPath) | string
gerritHubHostname: "review.gerrithub.io"
gerritHubRepositoryURL: *("https://\(gerritHubHostname)/a/" + githubRepositoryPath) | string
Expand All @@ -55,7 +55,7 @@ botGerritHubUser: *botGitHubUser | string
botGerritHubUserPasswordSecretsKey: *(strings.ToUpper(botGitHubUser) + "_GERRITHUB_PASSWORD") | string
botGerritHubUserEmail: *botGitHubUserEmail | string

workflowFileExtension: ".yml"
workflowFileExtension: ".yaml"

linuxMachine: string

Expand All @@ -67,7 +67,7 @@ codeReview: #codeReview & {
// Define some shared keys and human-readable names.
//
// trybot.key and unity.key are shared with
// github.com/cue-sh/tools/cmd/cueckoo. The keys are used across various CUE
// github.com/cue-lang/contrib-tools/cmd/cueckoo. The keys are used across various CUE
// workflows and their consistency in those various locations is therefore
// crucial. As such, we assert specific values for the keys here rather than
// just deriving values from the human-readable names.
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/base/codereview.cue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// #codeReview defines the schema of a codereview.cfg file that
// sits at the root of a repository. codereview.cfg is the configuration
// file that drives golang.org/x/review/git-codereview. This config
// file is also used by github.com/cue-sh/tools/cmd/cueckoo.
// file is also used by github.com/cue-lang/contrib-tools/cmd/cueckoo.
#codeReview: {
gerrit?: string
github?: string
Expand Down
90 changes: 45 additions & 45 deletions internal/ci/base/github.cue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,51 @@ bashWorkflow: json.#Workflow & {
jobs: [string]: defaults: run: shell: "bash"
}

installGo: json.#step & {
name: "Install Go"
uses: "actions/setup-go@v5"
with: {
// We do our own caching in setupGoActionsCaches.
cache: false
"go-version": string
installGo: {
#setupGo: json.#step & {
name: "Install Go"
uses: "actions/setup-go@v5"
with: {
// We do our own caching in setupGoActionsCaches.
cache: false
"go-version": string
}
}

// Why set GOTOOLCHAIN here? As opposed to an environment variable
// elsewhere? No perfect answer to this question but here is the thinking:
//
// Setting the variable here localises it with the installation of Go. Doing
// it elsewhere creates distance between the two steps which are
// intrinsically related. And it's also hard to do: "when we use this step,
// also ensure that we establish an environment variable in the job for
// GOTOOLCHAIN".
//
// Environment variables can only be set at a workflow, job or step level.
// Given we currently use a matrix strategy which varies the Go version,
// that rules out using an environment variable based approach, because the
// Go version is only available at runtime via GitHub actions provided
// context. Whether we should instead be templating multiple workflows (i.e.
// exploding the matrix ourselves) is a different question, but one that
// has performance implications.
//
// So as clumsy as it is to use a step "template" that includes more than
// one step, it's the best option available to us for now.
[
#setupGo,

{
json.#step & {
name: "Set common go env vars"
run: """
go env -w GOTOOLCHAIN=local
# Dump env for good measure
go env
"""
}
},
]
}

checkoutCode: {
Expand Down Expand Up @@ -100,44 +137,7 @@ checkoutCode: {

earlyChecks: json.#step & {
name: "Early git and code sanity checks"
run: #"""
# Ensure that commit messages have a blank second line.
# We know that a commit message must be longer than a single
# line because each commit must be signed-off.
if git log --format=%B -n 1 HEAD | sed -n '2{/^$/{q1}}'; then
echo "second line of commit message must be blank"
exit 1
fi
# All authors, including co-authors, must have a signed-off trailer by email.
# Note that trailers are in the form "Name <email>", so grab the email with sed.
# For now, we require the sorted lists of author and signer emails to match.
# Note that this also fails if a commit isn't signed-off at all.
#
# In Gerrit we already enable a form of this via https://gerrit-review.googlesource.com/Documentation/project-configuration.html#require-signed-off-by,
# but it does not support co-authors nor can it be used when testing GitHub PRs.
commit_authors="$(
{
git log -1 --pretty='%ae'
git log -1 --pretty='%(trailers:key=Co-authored-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
} | sort -u
)"
commit_signers="$(
{
git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
} | sort -u
)"
if [[ "${commit_authors}" != "${commit_signers}" ]]; then
echo "Error: commit author email addresses do not match signed-off-by trailers"
echo
echo "Authors:"
echo "${commit_authors}"
echo
echo "Signers:"
echo "${commit_signers}"
exit 1
fi
"""#
run: *"go run cuelang.org/go/internal/ci/[email protected]" | string
}

curlGitHubAPI: {
Expand Down
6 changes: 3 additions & 3 deletions internal/ci/gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 The CUE Authors
// Copyright 2021 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.
Expand All @@ -14,5 +14,5 @@

package ci

//go:generate go run cuelang.org/go/cmd/cue@v0.8.1 cmd importjsonschema ./vendor
//go:generate go run cuelang.org/go/cmd/cue@v0.8.1 cmd gen
//go:generate go run cuelang.org/go/cmd/cue@v0.10.0 cmd importjsonschema ./vendor
//go:generate go run cuelang.org/go/cmd/cue@v0.10.0 cmd gen
11 changes: 6 additions & 5 deletions internal/ci/github/trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ workflows: trybot: _repo.bashWorkflow & {
steps: [
for v in _repo.checkoutCode {v},

_installGo,
for v in _installGo {v},
_installJava,

// cachePre must come after installing Go,
Expand Down Expand Up @@ -86,7 +86,8 @@ workflows: trybot: _repo.bashWorkflow & {
}

_installGo: _repo.installGo & {
with: "go-version": goVersionVal
#setupGo: with: "go-version": goVersionVal
_
}

_installJava: json.#step & {
Expand All @@ -103,12 +104,12 @@ workflows: trybot: _repo.bashWorkflow & {
uses: "actions/checkout@v4"
with: {
repository: "cue-lang/libcue"
path: "libcue"
path: "libcue"
}
}

_buildLibcue: json.#step & {
name: "Build libcue"
name: "Build libcue"
"working-directory": "libcue"
// The name of the shared library is target-dependent.
// Build libcue with all possible names so we're covered
Expand All @@ -122,7 +123,7 @@ workflows: trybot: _repo.bashWorkflow & {

_mavenTest: json.#step & {
name: "Test"
env: LD_LIBRARY_PATH: "${{ github.workspace }}/libcue"
env: LD_LIBRARY_PATH: "${{ github.workspace }}/libcue"
env: DYLD_LIBRARY_PATH: "${{ github.workspace }}/libcue"
run: "mvn clean install package"
}
Expand Down
6 changes: 3 additions & 3 deletions internal/ci/vendor/vendor_tool.cue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 The CUE Authors
// Copyright 2021 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.
Expand Down Expand Up @@ -26,7 +26,7 @@ import (
// project which "vendors" the various workflow-related
// packages can specify "cue" as the value so that unity
// tests can specify the cmd/cue binary to use.
_cueCmd: string | *"go run cuelang.org/go/cmd/cue@v0.8.1" @tag(cue_cmd)
_cueCmd: string | *"go run cuelang.org/go/cmd/cue@v0.10.0" @tag(cue_cmd)

// For the commands below, note we use simple yet hacky path resolution, rather
// than anything that might derive the module root using go list or similar, in
Expand All @@ -40,7 +40,7 @@ command: importjsonschema: {

// Tip link for humans:
// https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/5ffe36662a8fcab3c32e8fbca39c5253809e6913/src/schemas/json/github-workflow.json"
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/88d26ad0d451cbd5ebc70218062850aa905bdf18/src/schemas/json/github-workflow.json"
}
import: exec.Run & {
_outpath: path.FromSlash("../../cue.mod/pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue", "unix")
Expand Down

0 comments on commit 477351d

Please sign in to comment.