diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index b72416a9f9..93b5f3755b 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -32,13 +32,16 @@ jobs: steps: - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3 + with: + # pulls all commits (needed for finding the @coveo/cli version to release) + fetch-depth: 0 - uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3 with: node-version: '16' - name: Setup run: npm i - name: Get tags - run: node ./scripts/get-tags.js # ToDo (PRE_NX): replace by some jq magic + run: node ./scripts/get-tags.mjs - name: Get commit short hash run: node ./scripts/get-commit-short-hash.mjs - name: Build diff --git a/scripts/get-tags.js b/scripts/get-tags.js deleted file mode 100644 index b04bf70d59..0000000000 --- a/scripts/get-tags.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @type {import("@actions/core")} */ -const core = require('@actions/core'); -/** @type {import("@actions/github")} */ -const github = require('@actions/github'); -const {getLastTag} = require('@coveo/semantic-monorepo-tools'); - -const releaseTagRegExp = /refs\/tags\/(release-\d+)/; -const releaseTagPrefix = 'release-'; -const cliTagPrefix = '@coveo/cli@'; - -const getReleaseTag = async () => { - if (github.context.eventName === 'workflow_dispatch') { - return github.context.payload.inputs.version; - } - if (github.context.eventName === 'release') { - const ref = github.context.ref; - const match = releaseTagRegExp.exec(ref); - if (match && match[1]) { - return match[1]; - } - } - core.warning('Tag acquisition failed, fallbacking to the latest'); - return getLastTag(releaseTagPrefix); -}; - -const getCliVersion = async () => - 'v' + (await getLastTag(cliTagPrefix)).split(cliTagPrefix)[1]; - -(async () => { - try { - const releaseTag = await getReleaseTag(); - core.exportVariable('tag', releaseTag); - const cliReleaseVersion = await getCliVersion(); - core.exportVariable('cliversion', cliReleaseVersion); - } catch (error) { - core.setFailed(error.message); - } -})(); diff --git a/scripts/get-tags.mjs b/scripts/get-tags.mjs new file mode 100644 index 0000000000..6034fb078a --- /dev/null +++ b/scripts/get-tags.mjs @@ -0,0 +1,36 @@ +import {warning, exportVariable, setFailed} from '@actions/core'; +import {context} from '@actions/github'; +import {getLastTag} from '@coveo/semantic-monorepo-tools'; + +const releaseTagRegExp = /refs\/tags\/(release-\d+)/; +const releaseTagPrefix = 'release-'; +const cliTagPrefix = '@coveo/cli@'; + +const getReleaseTag = async () => { + if (context.eventName === 'workflow_dispatch') { + return context.payload.inputs.version; + } + if (context.eventName === 'release') { + const ref = context.ref; + const match = releaseTagRegExp.exec(ref); + if (match && match[1]) { + return match[1]; + } + } + warning('Tag acquisition failed, fallbacking to the latest'); + return getLastTag(releaseTagPrefix); +}; + +const getCliVersion = async () => + 'v' + (await getLastTag(cliTagPrefix)).split(cliTagPrefix)[1]; + +(async () => { + try { + const releaseTag = await getReleaseTag(); + exportVariable('tag', releaseTag); + const cliReleaseVersion = await getCliVersion(); + exportVariable('cliversion', cliReleaseVersion); + } catch (error) { + setFailed(error.message); + } +})();