Skip to content

Commit

Permalink
chore: convert get-tags to esm (#946)
Browse files Browse the repository at this point in the history
<!-- For Coveo Employees only. Fill this section.

CDX-764

-->

## Proposed changes

When I replaced the get latest tag function we had by the
`@coveo/semantic-monorepo-tools` one, I forgot that
`@coveo/semantic-monorepo-tools` is an ESM package.

Fix: port the get-tags script to esm.

## Testing

https://github.com/coveo/cli/actions/runs/3102070548
  • Loading branch information
louis-bompart authored Sep 28, 2022
1 parent e8d28b9 commit f4ac6be
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 0 additions & 38 deletions scripts/get-tags.js

This file was deleted.

36 changes: 36 additions & 0 deletions scripts/get-tags.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
})();

0 comments on commit f4ac6be

Please sign in to comment.