Skip to content

Commit d8f0fba

Browse files
authored
fix: fix preview action checking for saved config (#83)
* fix: fix preview action checking for saved config * rename stuff
1 parent d5569ec commit d8f0fba

4 files changed

Lines changed: 57 additions & 38 deletions

File tree

dist/checkoutPRRef.js

Lines changed: 18 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/preview.js

Lines changed: 15 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/checkoutPRRef.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ async function main() {
2929
}
3030

3131
// Callers come in from checkout-pr-ref against base; save the config.
32-
const { savedOAS, savedSha } = await saveConfig({ oasPath, configPath });
33-
if (!savedOAS) {
32+
const { hasOAS, savedSha } = await saveConfig({ oasPath, configPath });
33+
if (!hasOAS) {
3434
throw new Error(`Expected OpenAPI spec at ${oasPath}.`);
3535
}
36-
if (savedSha !== mergeBaseSha) {
36+
if (savedSha && savedSha !== mergeBaseSha) {
3737
throw new Error(
3838
`Expected HEAD to be ${mergeBaseSha}, but was ${savedSha}`,
3939
);

src/config.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ export async function saveConfig({
2424
oasPath?: string;
2525
configPath?: string;
2626
}) {
27-
let savedOAS = false;
28-
let savedConfig = false;
27+
let hasOAS = false;
28+
let hasConfig = false;
2929
let savedSha: string | null = null;
3030

3131
if (oasPath && fs.existsSync(oasPath)) {
32-
savedOAS = true;
32+
hasOAS = true;
3333
await exec.exec("git", ["add", oasPath], { silent: true });
3434
}
3535

3636
if (configPath && fs.existsSync(configPath)) {
37-
savedConfig = true;
37+
hasConfig = true;
3838
await exec.exec("git", ["add", configPath], { silent: true });
3939
}
4040

41-
if (savedOAS || savedConfig) {
41+
if (hasOAS || hasConfig) {
4242
savedSha = (
4343
await exec.getExecOutput("git", ["rev-parse", "HEAD"], { silent: true })
4444
).stdout.trim();
@@ -62,15 +62,24 @@ export async function saveConfig({
6262
{ silent: true },
6363
);
6464

65-
await exec.exec(
66-
"git",
67-
["commit", "--allow-empty", "-m", "Save generated config"],
68-
{ silent: true },
69-
);
70-
await exec.exec("git", ["tag", tag], { silent: true });
65+
const hadChanges =
66+
(
67+
await exec.getExecOutput(
68+
"git",
69+
["commit", "-m", "Save generated config"],
70+
{ silent: true },
71+
)
72+
).exitCode === 0;
73+
74+
if (hadChanges) {
75+
await exec.exec("git", ["tag", tag], { silent: true });
76+
} else {
77+
savedSha = null;
78+
console.log("No changes to save");
79+
}
7180
}
7281

73-
return { savedOAS, savedConfig, savedSha };
82+
return { hasOAS, hasConfig, savedSha };
7483
}
7584

7685
/**

0 commit comments

Comments
 (0)