From 23d6e9525e9d001ab854b9a973eb91a6c6fe4f48 Mon Sep 17 00:00:00 2001 From: chatton Date: Tue, 12 Sep 2023 13:18:12 +0100 Subject: [PATCH] chore: add ensure golanglint version --- zx/ensure_golanglint_version.mjs | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 zx/ensure_golanglint_version.mjs diff --git a/zx/ensure_golanglint_version.mjs b/zx/ensure_golanglint_version.mjs new file mode 100755 index 0000000..474b513 --- /dev/null +++ b/zx/ensure_golanglint_version.mjs @@ -0,0 +1,35 @@ +#!/usr/bin/env zx + +$.verbose = false; + +async function getGoVersion() { + const goVersionProcess = await $`go version`; + const re = /go version go(.*) / + return re.exec(goVersionProcess.stdout)[1] +} + +try { + + let gitRoot = await $`git rev-parse --show-toplevel`; + gitRoot = gitRoot.stdout.trim(); + const lintPath = `${gitRoot}/.github/workflows/golangci.yml`; + const catOutput = await $`cat ${lintPath}`; + const contents = catOutput.stdout; + + let re = /version:\sv(.*)/ + const targetVersion = re.exec(contents)[1] + + let currentVersion = await $`golangci-lint --version` + re = /golangci-lint has version (.*) built.*/ + currentVersion = re.exec(currentVersion.stdout)[1] + + let goVersion = await getGoVersion() + goVersion = goVersion.substring(0, 4); // strip off the patch version + if (currentVersion !== targetVersion) { + await $`curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /Users/chatton/.gvm/pkgsets/go${goVersion}/global/bin v${targetVersion}` + console.log("updated to version " + targetVersion); + } + +} catch (e) { + await $`exit 0`; +}