Skip to content

Commit

Permalink
Merge pull request #96 from currents-dev/fix/last-failed-rerun-issue
Browse files Browse the repository at this point in the history
[CSR-1990] fix: cache get command
  • Loading branch information
twk3 authored Dec 16, 2024
2 parents 0991e0d + d06bffb commit 346a922
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/cmd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.6.2-beta.0](https://github.com/currents-dev/currents-reporter/compare/@currents/cmd-v1.6.1...${npm.name}-v1.6.2-beta.0) (2024-12-16)


### Bug Fixes

* cache get command, attach --last-failed flag only if pw was executed ([5cdad86](https://github.com/currents-dev/currents-reporter/commit/5cdad867e73b51bf720cad2660bbe499e4f143f4))

## [1.6.1](https://github.com/currents-dev/currents-reporter/compare/@currents/cmd-v1.6.0...${npm.name}-v1.6.1) (2024-12-11)


Expand Down
2 changes: 1 addition & 1 deletion packages/cmd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@currents/cmd",
"version": "1.6.1",
"version": "1.6.2-beta.0",
"main": "./dist/index.js",
"author": "Currents Software Inc",
"license": "MIT",
Expand Down
8 changes: 7 additions & 1 deletion packages/cmd/src/services/cache/path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { glob } from 'glob';
import { warn } from './lib';
import { MetaFile, warn } from './lib';

export const getLastRunFilePaths = async (outputPath?: string) => {
const prefix = path.resolve(outputPath ?? './test-results');
Expand Down Expand Up @@ -42,3 +42,9 @@ export function filterPaths(filePaths: string[]) {
return true;
});
}

export function wasLastRunFileUploaded(meta: MetaFile | null): boolean {
return meta
? meta.path.some((p) => path.basename(p) === '.last-run.json')
: false;
}
33 changes: 23 additions & 10 deletions packages/cmd/src/services/cache/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { PRESET_OUTPUT_PATH } from '../../commands/cache/options';
import { CacheGetCommandConfig } from '../../config/cache';
import { getCI } from '../../env/ciProvider';
import {
CircleParams,
GithubActionsParams,
GitLabParams,
CircleParams,
} from '../../env/types';
import { writeFileAsync } from '../../lib';
import { MetaFile } from './lib';
import { wasLastRunFileUploaded } from './path';

export async function handlePreLastRunPreset(
config: CacheGetCommandConfig,
Expand All @@ -37,6 +38,9 @@ export async function handlePostLastRunPreset(
meta: MetaFile
) {
switch (ci.provider) {
case 'githubActions':
await dumpPWConfigForGHA(config, ci, meta);
break;
case 'gitlab':
await dumpPwConfigForGitlab(config, ci, meta);
break;
Expand All @@ -62,12 +66,15 @@ async function dumpPwConfigForGitlab(
const nodeIndex = parseIntSafe(ciParams.ciNodeIndex, 1);
const jobTotal = parseIntSafe(ciParams.ciNodeTotal, 1);

const lastFailedOption = runAttempt > 1 ? '--last-failed' : '';
const wasPWExecuted = wasLastRunFileUploaded(meta);
const isLastFailed = runAttempt > 1 && wasPWExecuted;
const lastFailedOption = isLastFailed ? '--last-failed' : '';

let shardOption = '';
if (jobTotal > 1) {
shardOption =
runAttempt > 1 ? '--shard=1/1' : `--shard=${nodeIndex}/${jobTotal}`;
shardOption = isLastFailed
? '--shard=1/1'
: `--shard=${nodeIndex}/${jobTotal}`;
}

const pwCliOptions = [lastFailedOption, shardOption]
Expand All @@ -85,18 +92,22 @@ RUN_ATTEMPT="${runAttempt}"

async function dumpPWConfigForGHA(
config: CacheGetCommandConfig,
ci: ReturnType<typeof getCI>
ci: ReturnType<typeof getCI>,
meta: MetaFile | null = null
) {
const { matrixIndex, matrixTotal } = config;
const ciParams = ci.params as GithubActionsParams;
const runAttempt = parseIntSafe(ciParams.githubRunAttempt, 1);

const lastFailedOption = runAttempt > 1 ? '--last-failed' : '';
const wasPWExecuted = wasLastRunFileUploaded(meta);
const isLastFailed = runAttempt > 1 && wasPWExecuted;
const lastFailedOption = isLastFailed ? '--last-failed' : '';

let shardOption = '';
if (matrixTotal > 1) {
shardOption =
runAttempt > 1 ? '--shard=1/1' : `--shard=${matrixIndex}/${matrixTotal}`;
shardOption = isLastFailed
? '--shard=1/1'
: `--shard=${matrixIndex}/${matrixTotal}`;
}

const pwCliOptions = [lastFailedOption, shardOption]
Expand All @@ -123,11 +134,13 @@ async function dumpPWConfigForCircle(
prevWorkspaceId == ciParams.circleWorkflowWorkspaceId &&
prevWorkflowId !== ciParams.circleWorkflowId;

const lastFailedOption = isRerun ? '--last-failed' : '';
const wasPWExecuted = wasLastRunFileUploaded(meta);
const isLastFailed = isRerun && wasPWExecuted;
const lastFailedOption = isLastFailed ? '--last-failed' : '';

let shardOption = '';
if (nodeTotal > 1) {
shardOption = isRerun
shardOption = isLastFailed
? '--shard=1/1'
: `--shard=${nodeIndex + 1}/${nodeTotal}`;
}
Expand Down

0 comments on commit 346a922

Please sign in to comment.