From 58ff1af651e606fd1a9aad1c01f669fa0c1149fa Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Fri, 6 Sep 2024 13:27:01 +0100 Subject: [PATCH] tip.cuelang.org: apply the stored patch This adds a step near the end of CI that unconditionally checks that the patch stored at internal/patch/tip.diff still applies to the repo successfully. CI performs this check by actually applying the patch via _scripts/tipPatchApply.bash - any use of this script leaves the repo in a modified/dirty state. The patch contains changes that make the site compatible with the tip of cue-lang/cue's default branch. A follow-up CL will: 1. add a CI step that runs whenever the default branch of this repo is updated and: - forces the site to use the tip of cue-lang/cue - invokes ./_scripts/regenPostInfraChange.bash - checks that the site builds successfully Later changes might also: 2. publish the site (e.g. to the as-yet-unestablished tip.cuelang.org) after (1) succeeds 3. replicate (1) and (2) any time the default branch of cue-lang/cue is updated; 4. push the working trees generated by (1) and/or (3) to a long-running CL, so that the delta is visible/downloadable/etc. Signed-off-by: Paul Jolly Change-Id: I8fe2461cd4caa24d12fda7361b5205ae5c871640 Dispatch-Trailer: {"type":"trybot","CL":1200804,"patchset":8,"ref":"refs/changes/04/1200804/8","targetBranch":"master"} --- .github/workflows/trybot.yaml | 2 ++ _scripts/tipPatchApply.bash | 24 ++++++++++++++++++++++++ _scripts/tipPatchGenerate.bash | 18 ++++++++++++++++++ _scripts/tipPatchPath.bash | 10 ++++++++++ internal/ci/github/trybot.cue | 5 +++++ internal/patch/tip.diff | 13 +++++++++++++ 6 files changed, 72 insertions(+) create mode 100755 _scripts/tipPatchApply.bash create mode 100755 _scripts/tipPatchGenerate.bash create mode 100755 _scripts/tipPatchPath.bash create mode 100644 internal/patch/tip.diff diff --git a/.github/workflows/trybot.yaml b/.github/workflows/trybot.yaml index 07104955d..a8fe3b5b6 100644 --- a/.github/workflows/trybot.yaml +++ b/.github/workflows/trybot.yaml @@ -232,3 +232,5 @@ jobs: ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_INDEX_KEY }} ALGOLIA_INDEX_NAME: cuelang.org ALGOLIA_INDEX_FILE: ../_public/algolia.json + - name: 'tip.cuelang.org: Apply tip''s patch, checking that it applies cleanly' + run: _scripts/tipPatchApply.bash diff --git a/_scripts/tipPatchApply.bash b/_scripts/tipPatchApply.bash new file mode 100755 index 000000000..75055b35e --- /dev/null +++ b/_scripts/tipPatchApply.bash @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# tipPatchApply.bash +# +# tipPatchApply applies the patch stored at $patchPath to the current git +# working tree and index. This patch is intended to make the cuelang.org site +# compatible with the tip version of cue-lang/cue. + +# cd to the parent directory to that containing the script +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.." + +patchPath=$(./_scripts/tipPatchPath.bash) + +# We must be in a clean state first +if test ! -z "$(git status --porcelain)" +then + echo "working tree is not porcelain" + exit 1 +fi + +# --index: working tree and index must be identical. +git apply --index $patchPath diff --git a/_scripts/tipPatchGenerate.bash b/_scripts/tipPatchGenerate.bash new file mode 100755 index 000000000..6c0ef027e --- /dev/null +++ b/_scripts/tipPatchGenerate.bash @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# tipPatchGenerate.bash +# +# tipPatchGenerate takes the current state of the working tree and stores its +# diff against HEAD at $patchPath. This is intended to ease the ongoing, +# repeated generation of the patch that makes the repo compatible with the tip +# of cue-lang/cue. + +# cd to the parent directory to that containing the script +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.." + +patchPath="$(./_scripts/tipPatchPath.bash)" + +# ":^x" excludes changes to "x" from the diff. +git diff HEAD -- . ":^$patchPath" >"$patchPath" diff --git a/_scripts/tipPatchPath.bash b/_scripts/tipPatchPath.bash new file mode 100755 index 000000000..a3e4f2f9b --- /dev/null +++ b/_scripts/tipPatchPath.bash @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# tipPatchPath.bash +# +# tipPatchPath prints the path of the patch file that makes the repo compatible +# with the tip of cue-lang/cue, relative to the repo root. + +echo "internal/patch/tip.diff" diff --git a/internal/ci/github/trybot.cue b/internal/ci/github/trybot.cue index 8e95dfc5b..bd937c773 100644 --- a/internal/ci/github/trybot.cue +++ b/internal/ci/github/trybot.cue @@ -248,6 +248,11 @@ workflows: trybot: _repo.bashWorkflow & { ALGOLIA_INDEX_FILE: "../_public/algolia.json" } }, + + json.#step & { + name: "tip.cuelang.org: Apply tip's patch, checking that it applies cleanly" + run: "_scripts/tipPatchApply.bash" + }, ] } diff --git a/internal/patch/tip.diff b/internal/patch/tip.diff new file mode 100644 index 000000000..ced11b380 --- /dev/null +++ b/internal/patch/tip.diff @@ -0,0 +1,13 @@ +diff --git a/playground/_scripts/revendorToolsInternal.bash b/playground/_scripts/revendorToolsInternal.bash +index 771d24ec..ea3def82 100755 +--- a/playground/_scripts/revendorToolsInternal.bash ++++ b/playground/_scripts/revendorToolsInternal.bash +@@ -29,7 +29,7 @@ popd > /dev/null + + # TODO this is very fragile - we need to move away from this to a proper + # dependency-based approach to minimal copy +-for i in "" filetypes encoding third_party/yaml encoding/yaml astinternal cueexperiment envflag source ++for i in "" filetypes encoding encoding/yaml astinternal cueexperiment envflag source + do + rsync -a --relative --delete $td/$path@$version/internal/./$i/ ./internal/cuelang_org_go_internal/ + find ./internal/cuelang_org_go_internal/$i -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +