Skip to content

Commit

Permalink
Merge pull request #24 from Sauloxd/ft-properly-cleanup-manifest
Browse files Browse the repository at this point in the history
improve manifest sync to always clean and add
  • Loading branch information
Sauloxd authored Mar 16, 2022
2 parents dda8364 + 9b4c2d0 commit 2564cf8
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 48 deletions.
26 changes: 11 additions & 15 deletions packages/action/dist/index.js

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

2 changes: 1 addition & 1 deletion packages/action/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/action/dist/services/comment-app-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ${pathsForBranch.apps.map(formatToListedLink).join('')}
`;
return body;
function formatToListedLink(app) {
return ` - [${app.name}](${app.githubPagesUrl})\n`;
return ` - [${app.name}](${encodeURI(app.githubPagesUrl)})\n`;
}
};
const CommentApi = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/action/dist/services/remove-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.removeApp = (0, log_error_1.withError)(function removeApp(params) {
yield (0, retry_1.retry)(5)(() => __awaiter(this, void 0, void 0, function* () {
yield git.hardReset((0, user_input_1.userInput)().ghPagesBranch);
yield io.rmRF(params.branch.name);
manifest.removeApp(params.branch.name);
yield manifest.removeApps(params.branch.name);
yield git.stageChanges([
params.branch.name,
!(0, user_input_1.userInput)().skipIndexHtml && 'index.html',
Expand Down
3 changes: 2 additions & 1 deletion packages/action/dist/services/sync-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ exports.syncApps = (0, log_error_1.withError)(function syncApps(params) {
-> Will move (and override) the build result on '${app.dist}' to '${paths.byHeadCommit}' in ${(0, user_input_1.userInput)().ghPagesBranch}"
`);
}
yield manifest.removeApps(params.branch.name);
yield git.hardReset((0, user_input_1.userInput)().ghPagesBranch);
for (const app of (0, user_input_1.userInput)().apps) {
const paths = fileManager.paths(params, app);
manifest.replaceApp(params, app);
const tmpDir = (0, user_input_1.userInput)().tmpDir + '/' + paths.byHeadCommit;
yield io.cp(tmpDir, paths.byHeadCommit, {
recursive: true,
Expand All @@ -65,6 +65,7 @@ exports.syncApps = (0, log_error_1.withError)(function syncApps(params) {
yield git.stageChanges([paths.byHeadCommit]);
core.debug('Finished copying');
}
yield manifest.addApps(params);
yield git.stageChanges([
!(0, user_input_1.userInput)().skipIndexHtml && 'index.html',
'manifest.json',
Expand Down
19 changes: 7 additions & 12 deletions packages/action/dist/utils/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.githubPagesUrl = exports.getBranchPaths = exports.replaceApp = exports.removeApp = void 0;
exports.githubPagesUrl = exports.getBranchPaths = exports.addApps = exports.removeApps = void 0;
const fs = __importStar(require("fs"));
const core = __importStar(require("@actions/core"));
const default_1 = require("../template/default");
Expand All @@ -38,31 +38,26 @@ const log_error_1 = require("./log-error");
// Due to poorly designed API,
// All functions here that depends on `getManifest()`
// will break if operations are called outside "github pages" branch!
exports.removeApp = (0, log_error_1.withError)(function removeApp(branch) {
exports.removeApps = (0, log_error_1.withError)(function removeApp(branch) {
return __awaiter(this, void 0, void 0, function* () {
const manifest = getManifest();
delete manifest[branch];
syncManifest(manifest);
});
});
const replaceApp = function replaceApp(params, appInput) {
var _a;
const addApps = function addApp(params) {
return __awaiter(this, void 0, void 0, function* () {
const manifest = getManifest();
const apps = ((_a = manifest[params.branch.name]) === null || _a === void 0 ? void 0 : _a.apps) || [];
const index = apps.findIndex((app) => app.name === appInput.slug);
const newApp = buildApp(params, appInput);
if (index > -1) {
apps[index] = newApp;
}
else {
const apps = [];
for (const app of (0, user_input_1.userInput)().apps) {
const newApp = buildApp(params, app);
apps.push(newApp);
}
manifest[params.branch.name] = Object.assign(Object.assign({}, manifest[params.branch.name]), { apps });
syncManifest(manifest);
});
};
exports.replaceApp = replaceApp;
exports.addApps = addApps;
function getBranchPaths(branch) {
const manifest = getManifest();
return manifest[branch];
Expand Down
2 changes: 1 addition & 1 deletion packages/action/src/services/comment-app-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ${pathsForBranch.apps.map(formatToListedLink).join('')}
return body;

function formatToListedLink(app: App) {
return ` - [${app.name}](${app.githubPagesUrl})\n`;
return ` - [${app.name}](${encodeURI(app.githubPagesUrl)})\n`;
}
};
const CommentApi = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/action/src/services/remove-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const removeApp = withError(async function removeApp(
await retry(5)(async () => {
await git.hardReset(userInput().ghPagesBranch);
await io.rmRF(params.branch.name);
manifest.removeApp(params.branch.name);
await manifest.removeApps(params.branch.name);
await git.stageChanges([
params.branch.name,
!userInput().skipIndexHtml && 'index.html',
Expand Down
7 changes: 4 additions & 3 deletions packages/action/src/services/sync-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ export const syncApps = withError(async function syncApps(
`);
}

await manifest.removeApps(params.branch.name);

await git.hardReset(userInput().ghPagesBranch);

for (const app of userInput().apps) {
const paths = fileManager.paths(params, app);

manifest.replaceApp(params, app);

const tmpDir = userInput().tmpDir + '/' + paths.byHeadCommit;

await io.cp(tmpDir, paths.byHeadCommit, {
Expand All @@ -47,6 +46,8 @@ export const syncApps = withError(async function syncApps(
core.debug('Finished copying');
}

await manifest.addApps(params);

await git.stageChanges([
!userInput().skipIndexHtml && 'index.html',
'manifest.json',
Expand Down
17 changes: 5 additions & 12 deletions packages/action/src/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,19 @@ import { withError } from './log-error';
// All functions here that depends on `getManifest()`
// will break if operations are called outside "github pages" branch!

export const removeApp = withError(async function removeApp(branch: string) {
export const removeApps = withError(async function removeApp(branch: string) {
const manifest = getManifest();

delete manifest[branch];

syncManifest(manifest);
});

export const replaceApp = async function replaceApp(
params: SanitizedPayloadParams,
appInput: UserInput['apps'][number]
) {
export const addApps = async function addApp(params: SanitizedPayloadParams) {
const manifest = getManifest();
const apps = manifest[params.branch.name]?.apps || [];
const index = apps.findIndex((app) => app.name === appInput.slug);
const newApp = buildApp(params, appInput);

if (index > -1) {
apps[index] = newApp;
} else {
const apps: App[] = [];
for (const app of userInput().apps) {
const newApp = buildApp(params, app);
apps.push(newApp);
}

Expand Down

0 comments on commit 2564cf8

Please sign in to comment.