From a7fae0bff2143641331fe99e2f8804ae484c5c9c Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Thu, 21 Nov 2024 16:35:36 +0000 Subject: [PATCH] internal/ci: update trybot workflow to also do releases We plan to do releases as part of CI/CD for the VSCode extension. That will be triggered by tagging the repository with a semantic version string, e.g. 'v0.0.5'. This version must correspond to the declared version of the extension in extension.cue. This CL extends the trybot workflow to perform such a release on the event of a 'v*' tag. It includes a CUE workflow command that performs the check to ensure the tag on the repo matches the declared version (noting that the declared version is only semver-like). We set the VSCODE_PAT env var based on the cueckoo credentials establish for the purpose of publishing. Signed-off-by: Paul Jolly Change-Id: I1cf4993017a67769f970bd7d727c4f23e69a6077 Dispatch-Trailer: {"type":"trybot","CL":1204445,"patchset":20,"ref":"refs/changes/45/1204445/20","targetBranch":"master"} --- .github/workflows/trybot.yaml | 12 ++++++++++++ extension/extension_tool.cue | 21 +++++++++++++++++++++ internal/ci/github/trybot.cue | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/.github/workflows/trybot.yaml b/.github/workflows/trybot.yaml index 35a662e..33cbd4d 100644 --- a/.github/workflows/trybot.yaml +++ b/.github/workflows/trybot.yaml @@ -3,6 +3,8 @@ name: TryBot "on": push: + tags: + - v* branches: - ci/test - master @@ -140,3 +142,13 @@ jobs: - if: always() name: Check that git is clean at the end of the job run: test -z "$(git status --porcelain)" || (git status; git diff; false) + - working-directory: extension + if: github.repository == 'cue-lang/vscode-cue' && (startsWith(github.ref, 'refs/tags/v')) + name: Check version match + run: cue cmd -t tag=${GITHUB_REF##refs/tags/} checkReleaseVersion + - working-directory: extension + if: github.repository == 'cue-lang/vscode-cue' && (startsWith(github.ref, 'refs/tags/v') || (github.ref == 'refs/heads/ci/test')) + name: Release package + run: npm run publish -- -p $VSCODE_PAT + env: + VSCODE_PAT: ${{ secrets.CUECKOO_VSCODE_PAT }} diff --git a/extension/extension_tool.cue b/extension/extension_tool.cue index d8e38ad..57478f5 100644 --- a/extension/extension_tool.cue +++ b/extension/extension_tool.cue @@ -5,6 +5,7 @@ import ( "list" "strings" + "tool/cli" "tool/exec" "tool/file" ) @@ -65,3 +66,23 @@ command: writebackPackageJSON: { contents: place.stdout } } + +// checkReleaseVersion ensures that the extension-configured version (which is +// not actually a true semver version) corresponds to the string "argument" +// passed via the attribute named tag are equal. We use a rather unpleasant +// hack to force a failure because cue cmd has no such primitive. +command: checkReleaseVersion: { + _version: string @tag(tag) + + let commitVersion = "v" + extension.npm.version + + if commitVersion != _version { + msg: cli.Print & { + text: "commitVersion \(commitVersion) != tag version \(_version)" + } + error: exec.Run & { + $after: msg + cmd: "false" + } + } +} diff --git a/internal/ci/github/trybot.cue b/internal/ci/github/trybot.cue index 8f25209..77c0208 100644 --- a/internal/ci/github/trybot.cue +++ b/internal/ci/github/trybot.cue @@ -27,6 +27,7 @@ workflows: trybot: _repo.bashWorkflow & { on: { push: { + tags: [_repo.releaseTagPattern] branches: list.Concat([[_repo.testDefaultBranch], _repo.protectedBranchPatterns]) // do not run PR branches } pull_request: {} @@ -78,6 +79,12 @@ workflows: trybot: _repo.bashWorkflow & { let extensionStep = { "working-directory": "extension" } + let releaseStep = extensionStep & { + if: "github.repository == '\(_repo.githubRepositoryPath)' && (\(_repo.isReleaseTag))" + } + let releaseOrTestDefaultStep = extensionStep & { + if: "github.repository == '\(_repo.githubRepositoryPath)' && (\(_repo.isReleaseTag) || \(_repo.isTestDefaultBranch))" + } steps: [ for v in _repo.checkoutCode {v}, @@ -141,10 +148,26 @@ workflows: trybot: _repo.bashWorkflow & { // Final checks _repo.checkGitClean, + + // Release steps + releaseStep & { + name: "Check version match" + run: "cue cmd -t tag=\(_versionRef) checkReleaseVersion" + }, + releaseOrTestDefaultStep & { + name: "Release package" + run: "npm run publish -- -p $VSCODE_PAT" + env: VSCODE_PAT: "${{ secrets.CUECKOO_VSCODE_PAT }}" + }, + ] } } +// _versionRef is a workflow job-runtime expression that evaluates to the git +// tag (version) that is being released +_versionRef: "${GITHUB_REF##refs/tags/}" + _installNode: githubactions.#Step & { name: "Install Node" uses: "actions/setup-node@v4"