Skip to content

Commit

Permalink
fix(publisher): fix publishing a saved dry run on a different device …
Browse files Browse the repository at this point in the history
…from the initial dry run
  • Loading branch information
MarshallOfSound committed Nov 21, 2017
1 parent 1920b5f commit a2c33eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/api/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions src/util/publish-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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);
}
}
Expand All @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions test/fast/publish_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit a2c33eb

Please sign in to comment.