From a3360899c24db8966d58d892a6e72570998fd3a6 Mon Sep 17 00:00:00 2001 From: Jonathan Matthews Date: Mon, 9 Sep 2024 16:33:22 +0100 Subject: [PATCH] tip.cuelang.org: test if site builds successfully This adds a pair of steps to the end of CI which only run on the repo's default branch (or its pre-submission testing counterpart) in the primary (non-trybot) repo; i.e. after a CL has been submitted. The first step overrides the site's CUE version to be the tip of cue-lang/cue. The second step builds the site to check that the patch we're maintaining to make the site compatible with the CUE tip still does its job and allows the site build to succeed. Later changes will publish the site/source to Netlify/Gerrit, to increase our visibility of any changes. For now, this change just asserts that the site builds successfully. Change-Id: I51f6f7fbada47d6a250ff3ecfb11c212d78b9a70 Signed-off-by: Jonathan Matthews Dispatch-Trailer: {"type":"trybot","CL":1200891,"patchset":5,"ref":"refs/changes/91/1200891/5","targetBranch":"master"} --- .github/workflows/trybot.yaml | 8 ++++++ _scripts/tipUseAlternativeCUE.bash | 44 ++++++++++++++++++++++++++++++ internal/ci/github/trybot.cue | 18 ++++++++++++ 3 files changed, 70 insertions(+) create mode 100755 _scripts/tipUseAlternativeCUE.bash diff --git a/.github/workflows/trybot.yaml b/.github/workflows/trybot.yaml index a8fe3b5b6..5fab75d43 100644 --- a/.github/workflows/trybot.yaml +++ b/.github/workflows/trybot.yaml @@ -234,3 +234,11 @@ jobs: ALGOLIA_INDEX_FILE: ../_public/algolia.json - name: 'tip.cuelang.org: Apply tip''s patch, checking that it applies cleanly' run: _scripts/tipPatchApply.bash + - if: github.repository == 'cue-lang/cuelang.org' && (github.ref == 'refs/heads/master' || (github.ref == 'refs/heads/ci/test')) + name: 'tip.cuelang.org: Resolve the tip version of cue-lang/cue and configure the site to use it' + run: _scripts/tipUseAlternativeCUE.bash + env: + GOPROXY: direct + - if: github.repository == 'cue-lang/cuelang.org' && (github.ref == 'refs/heads/master' || (github.ref == 'refs/heads/ci/test')) + name: 'tip.cuelang.org: Check if the site builds against the tip of cue-lang/cue' + run: _scripts/regenPostInfraChange.bash diff --git a/_scripts/tipUseAlternativeCUE.bash b/_scripts/tipUseAlternativeCUE.bash new file mode 100755 index 000000000..2f9167669 --- /dev/null +++ b/_scripts/tipUseAlternativeCUE.bash @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# tipUseAlternativeCUE.bash [CUE_COMMIT_REF] +# +# tipUseAlternativeCUE resolves the version of CUE available via +# cuelang.org/go@$CUE_COMMIT_REF and overrides the site configuration so that +# this version takes the place of all named CUEs (currently only "latest" and +# "prerelease" are directly overridden, with their versions transitively +# dictating those used by "tip", "default", and "playground"). CUE_COMMIT_REF +# defaults to "master", so that invoking the script with no arguments will use +# the tip of cue-lang/cue. + +versionRef=${1:-master} + +# cd to the parent directory to that containing the script +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.." + +# Resolve $versionRef to a pseudo-version. Notice this intentionally honours +# GOPROXY rather that setting a specific value in the script, allowing the +# setting to be controlled by this script's invocation. +td=$(mktemp -d) +trap "rm -rf $td" EXIT +pushd $td > /dev/null +go mod init mod.example &> /dev/null +go get cuelang.org/go@$versionRef &> /dev/null +version=$(go list -m -f={{.Version}} cuelang.org/go) +popd > /dev/null + +echo "Will use cuelang.org/go@$version" + +# Override all versions of CUE referenced by the site to be $version. +# This might change if any entries are added to the version matrix that +# deliberately make a previous version of CUE available but, for now, we don't +# need that - and could easily make it configurable later. +go run cuelang.org/go/cmd/cue def \ + -t version="$version" \ + -p site \ + --out cue \ + cue: - <tip.cue +_version: _ @tag(version) +versions: cue: [string]: v: _version +EOD diff --git a/internal/ci/github/trybot.cue b/internal/ci/github/trybot.cue index bd937c773..a106b54c4 100644 --- a/internal/ci/github/trybot.cue +++ b/internal/ci/github/trybot.cue @@ -253,6 +253,24 @@ workflows: trybot: _repo.bashWorkflow & { name: "tip.cuelang.org: Apply tip's patch, checking that it applies cleanly" run: "_scripts/tipPatchApply.bash" }, + + json.#step & { + name: "tip.cuelang.org: Resolve the tip version of cue-lang/cue and configure the site to use it" + // Only run in the main repo on the default branch or its designated test branch (i.e not CLs) + // so that CLs aren't blocked by failures caused by unrelated changes. + if: "github.repository == '\(_repo.githubRepositoryPath)' && (github.ref == 'refs/heads/\(_repo.defaultBranch)' || \(_repo.isTestDefaultBranch))" + // Force Go to bypass the module proxy, ensuring that the absolute + // latest CUE pseudo-version is available to test against. + env: GOPROXY: "direct" + run: "_scripts/tipUseAlternativeCUE.bash" + }, + json.#step & { + name: "tip.cuelang.org: Check if the site builds against the tip of cue-lang/cue" + // Only run in the main repo on the default branch or its designated test branch (i.e not CLs) + // so that CLs aren't blocked by failures caused by unrelated changes. + if: "github.repository == '\(_repo.githubRepositoryPath)' && (github.ref == 'refs/heads/\(_repo.defaultBranch)' || \(_repo.isTestDefaultBranch))" + run: "_scripts/regenPostInfraChange.bash" + }, ] }