Skip to content
Permalink
Browse files

fix(publisher): fix publishing a saved dry run on a different device …

…from the initial dry run
  • Loading branch information
MarshallOfSound committed Nov 21, 2017
1 parent 1920b5f commit a2c33eb87a9cf81b1e0a6d38438cdfd009a79f32
Showing with 12 additions and 9 deletions.
  1. +2 −2 src/api/publish.js
  2. +4 −2 src/util/publish-state.js
  3. +6 −5 test/fast/publish_spec.js
@@ -64,7 +64,7 @@ const publish = async (providedOptions = {}) => {

if (dryRunResume) {
d('attempting to resume from dry run');
const publishes = await PublishState.loadFromDirectory(dryRunDir);
const publishes = await PublishState.loadFromDirectory(dryRunDir, dir);
for (const publishStates of publishes) {
d('publishing for given state set');
await publish({
@@ -106,7 +106,7 @@ const publish = async (providedOptions = {}) => {
if (dryRun) {
d('saving results of make in dry run state', makeResults);
await fs.remove(dryRunDir);
await PublishState.saveToDirectory(dryRunDir, makeResults);
await PublishState.saveToDirectory(dryRunDir, makeResults, dir);
return;
}

@@ -5,7 +5,7 @@ import path from 'path';
const EXTENSION = '.forge.publish';

export default class PublishState {
static async loadFromDirectory(directory) {
static async loadFromDirectory(directory, rootDir) {
if (!await fs.exists(directory)) {
throw new Error(`Attempted to load publish state from a missing directory: ${directory}`);
}
@@ -22,6 +22,7 @@ export default class PublishState {
for (const filePath of filePaths) {
const state = new PublishState(filePath);
await state.load();
state.state.artifacts = state.state.artifacts.map(artifactPath => path.resolve(rootDir, artifactPath));
states.push(state);
}
}
@@ -30,9 +31,10 @@ export default class PublishState {
return publishes;
}

static async saveToDirectory(directory, artifacts) {
static async saveToDirectory(directory, artifacts, rootDir) {
const id = crypto.createHash('SHA256').update(JSON.stringify(artifacts)).digest('hex');
for (const artifact of artifacts) {
artifact.artifacts = artifact.artifacts.map(artifactPath => path.relative(rootDir, artifactPath));
const state = new PublishState(path.resolve(directory, id, 'null'), '', false);
state.setState(artifact);
await state.saveToDisk();
@@ -98,13 +98,13 @@ describe('publish', () => {
const fakeMake = (platform) => {
const ret = [
{ artifacts: [
path.resolve(dir, `artifact1-${platform}`),
path.resolve(dir, `artifact2-${platform}`),
path.resolve(dir, `out/make/artifact1-${platform}`),
path.resolve(dir, `out/make/artifact2-${platform}`),
] }, { artifacts: [
path.resolve(dir, `artifact3-${platform}`),
path.resolve(dir, `out/make/artifact3-${platform}`),
] },
{ artifacts: [
path.resolve(dir, `artifact4-${platform}`),
path.resolve(dir, `out/make/artifact4-${platform}`),
] },
];
const state = {
@@ -172,7 +172,8 @@ describe('publish', () => {

// Make the artifacts for later
for (const artifactPath of data.artifacts) {
await fs.writeFile(artifactPath, artifactPath);
await fs.mkdirp(path.dirname(path.resolve(dir, artifactPath)));
await fs.writeFile(path.resolve(dir, artifactPath), artifactPath);
}
}
}

0 comments on commit a2c33eb

Please sign in to comment.
You can’t perform that action at this time.