Skip to content

Commit

Permalink
fix(crates): Resume workspace publish (#392)
Browse files Browse the repository at this point in the history
The crates target is not able to resume a workspace publish because
already published crates cannot be republished. This means a partially
successful publish cannot be retried.

To work around this, the crates target can skip publishing a crate if it
already exists in this version. The downside of this is that we would
silence errors when publishing the wrong version.
  • Loading branch information
jan-auer committed May 11, 2022
1 parent 15a0f22 commit e8b74e0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/targets/crates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ const CARGO_BIN = process.env.CARGO_BIN || DEFAULT_CARGO_BIN;
*/
const VERSION_ERROR = 'failed to select a version for the requirement';

/**
* A message fragment emitted by cargo when publishing fails because the crate
* had already been published in this exact version. This happens especially
* when rerunning a workspace publish after it has failed in the middle.
*/
const REPUBLISH_ERROR = 'is already uploaded';

/**
* Maximum number of attempts including the initial one when publishing fails
* due to a stale cache. After this number of retries, publishing fails.
Expand Down Expand Up @@ -269,7 +276,17 @@ export class CratesTarget extends BaseTarget {
let delay = RETRY_DELAY_SECS;
this.logger.info(`Publishing ${crate.name}`);
await withRetry(
() => spawnProcess(CARGO_BIN, args, { env }),
async () => {
try {
await spawnProcess(CARGO_BIN, args, { env });
} catch (err) {
if (err instanceof Error && err.message.includes(REPUBLISH_ERROR)) {
this.logger.info(`Skipping ${crate.name}, version ${crate.version} already published`);
} else {
throw err;
}
}
},
MAX_ATTEMPTS,

async err => {
Expand Down

0 comments on commit e8b74e0

Please sign in to comment.