Skip to content

Commit

Permalink
fix(cli): fix sha acquisiton for windows signing (#1031)
Browse files Browse the repository at this point in the history
<!-- For Coveo Employees only. Fill this section.

CDX-1230

-->

## Proposed changes
Similar problem and similar fix as #988

## Testing

- [x] Manual Tests: Replicated file tree and ran the script. Assessed
the hash was there and complete
  • Loading branch information
louis-bompart authored Nov 17, 2022
1 parent 7efb42d commit dcc3131
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
run: npm i
- name: Get tags
run: node ./scripts/get-tags.mjs
- name: Get commit short hash
run: node ./scripts/get-commit-short-hash.mjs
- name: Build
run: npm run build
- name: Create install kits
Expand All @@ -51,6 +49,9 @@ jobs:
working-directory: ./packages/cli/core
if: ${{matrix.os == 'ubuntu-latest'}}
run: ../../../node_modules/oclif/bin/run pack tarballs
- name: Get commit hash of binaries
run: node ../../../scripts/get-commit-short-hash.mjs
working-directory: ./packages/cli/core
- name: Sign Executable
working-directory: ./packages/cli/core
if: ${{matrix.os == 'windows-latest'}}
Expand Down
27 changes: 16 additions & 11 deletions scripts/get-commit-short-hash.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {exportVariable, setFailed} from '@actions/core';
import {getSHA1fromRef} from '@coveo/semantic-monorepo-tools';
import {readdirSync} from 'node:fs';
import {join} from 'node:path';
import {binariesMatcher} from './oclifArtifactMatchers.mjs';

const getCommitShortHash = async () =>
(await getSHA1fromRef('HEAD')).substring(0, 7);
// Should be executed at the root of the CLI workspace.
const pathToArtifacts = join('dist', process.platform);
const artifacts = readdirSync(pathToArtifacts, {withFileTypes: true});
const someExe = artifacts.find(
(candidate) => candidate.isFile() && candidate.name.endsWith('.exe')
);

(async () => {
try {
const commitShortHash = await getCommitShortHash();
exportVariable('commitSHA1', commitShortHash);
} catch (error) {
setFailed(error.message);
}
})();
if (!binariesMatcher.exec(someExe.name)?.groups?.commitSHA) {
setFailed('Binary does not match');
}
exportVariable(
'commitSHA1',
binariesMatcher.exec(someExe.name).groups.commitSHA
);
11 changes: 5 additions & 6 deletions scripts/get-release-artifact-and-commit-sha.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {mkdirSync, writeFileSync, readdirSync, copyFileSync} from 'fs';
import {resolve, join} from 'path';
import {execSync} from 'node:child_process';
import {spawnSync} from 'child_process';
import {
binariesMatcher,
manifestMatcher,
tarballMatcher,
} from './oclifArtifactMatchers.mjs';

async function main() {
const release = await getLastCliRelease();
Expand All @@ -17,12 +22,6 @@ async function main() {
const getSubDirectoryForTarball = ({version, commitSHA}) =>
join(topLevelDirectory, 'versions', version, commitSHA);
const subDirectoryForManifest = join(topLevelDirectory, 'channels', 'stable');
const binariesMatcher =
/^coveo[_-]{1}(?<version>v?\d+\.\d+\.\d+(-\d+)?)[_.-]{1}(?<commitSHA>\w+)[_-]?(\d+_)?(?<longExt>.*\.(exe|deb|pkg))$/;
const manifestMatcher =
/^coveo-(?<version>v?\d+\.\d+\.\d+(-\d+)?)-(?<commitSHA>\w+)-(?<targetSignature>.*-buildmanifest)$/;
const tarballMatcher =
/^coveo-v?(?<version>\d+\.\d+\.\d+(-\d+)?)-(?<commitSHA>\w+)-(?<targetSignature>[\w-]+).tar\.[gx]z$/;

const determineAssetLocation = (assetName) => {
if (assetName.match(tarballMatcher)) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/oclifArtifactMatchers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const binariesMatcher =
/^coveo[_-]{1}(?<version>v?\d+\.\d+\.\d+(-\d+)?)[_.-]{1}(?<commitSHA>\w+)[_-]?(\d+_)?(?<longExt>.*\.(exe|deb|pkg))$/;
export const manifestMatcher =
/^coveo-(?<version>v?\d+\.\d+\.\d+(-\d+)?)-(?<commitSHA>\w+)-(?<targetSignature>.*-buildmanifest)$/;
export const tarballMatcher =
/^coveo-v?(?<version>\d+\.\d+\.\d+(-\d+)?)-(?<commitSHA>\w+)-(?<targetSignature>[\w-]+).tar\.[gx]z$/;

0 comments on commit dcc3131

Please sign in to comment.