Skip to content

Commit

Permalink
🚀 Deploy new version [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
pabio-escobar committed Nov 24, 2022
1 parent fbad5a1 commit 36d4ffa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,31 @@ const parseNoteFile = async (dirName, year, file) => {
const date = "date" in attributes && typeof attributes.date === "string"
? new Date(attributes.date)
: "date" in attributes && typeof attributes.date === "number"
? new Date(attributes.date)
? // Arbitiary rule to differentiate ms timestamp from year
attributes.date < 3000
? new Date(`${attributes.date}-01-01`)
: new Date(attributes.date)
: "date" in attributes && attributes.date instanceof Date
? attributes.date
: // Use git file creation date if no date is specified
new Date((0, child_process_1.execSync)(`git log --format=%aD ${dirName}/${year}/${file} | tail -1`).toString().trim());
new Date((0, child_process_1.execSync)(`git log --format=%aD ${dirName}/${year}/${file} | tail -1`)
.toString()
.trim());
const title = ("title" in attributes && typeof attributes.title === "string"
? attributes.title
: body.match(/^# (.*)/m)?.[1])?.trim();
if (!title)
throw new Error(`Unable to parse title in ${path}`);
const excerpt = "excerpt" in attributes && typeof attributes.excerpt === "string"
? attributes.excerpt
: "description" in attributes && typeof attributes.description === "string"
: "description" in attributes &&
typeof attributes.description === "string"
? attributes.description
: "summary" in attributes && typeof attributes.summary === "string"
? attributes.summary
: body.indexOf(title) > -1
? body.substring(body.indexOf(title) + title.length)?.trim() ?? body.trim()
? body.substring(body.indexOf(title) + title.length)?.trim() ??
body.trim()
: body.trim();
return {
slug: file,
Expand All @@ -69,7 +76,8 @@ const run = async () => {
if (!token)
throw new Error("GitHub token not found");
const commitMessage = (0, core_1.getInput)("commitMessage") || ":pencil: Update notes summary [skip ci]";
const commitEmail = (0, core_1.getInput)("commitEmail") || "41898282+github-actions[bot]@users.noreply.github.com";
const commitEmail = (0, core_1.getInput)("commitEmail") ||
"41898282+github-actions[bot]@users.noreply.github.com";
const commitUsername = (0, core_1.getInput)("commitUsername") || "github-actions[bot]";
const dirName = (0, core_1.getInput)("dirName") || "notes";
const allNotes = {};
Expand Down Expand Up @@ -112,20 +120,20 @@ const run = async () => {
content += upcomingNotes;
if (pastNotes.length)
content += pastNotes;
const originalReadmeContents = (0, prettier_1.format)(await (0, fs_extra_1.readFile)((0, path_1.join)(".", "README.md"), "utf-8"), {
parser: "markdown",
});
const originalReadmeContents = (0, prettier_1.format)(await (0, fs_extra_1.readFile)((0, path_1.join)(".", "README.md"), "utf-8"), { parser: "markdown" });
await (0, fs_extra_1.writeFile)((0, path_1.join)(".", "README.md"), (0, prettier_1.format)(`${originalReadmeContents.split("<!--notes-->")[0]}<!--notes-->\n\n${content.trim()}\n<!--/notes-->${originalReadmeContents.split("<!--/notes-->")[1]}`, { parser: "markdown" }));
await (0, fs_extra_1.writeFile)((0, path_1.join)(".", "api.json"), JSON.stringify(Object.values(allNotes)
.flat()
.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()), null, 2) + "\n");
try {
(0, child_process_1.execSync)(`git config --global user.email "${commitEmail}"`, { stdio: "inherit" });
(0, child_process_1.execSync)(`git config --global user.name "${commitUsername}"`, { stdio: "inherit" });
(0, child_process_1.execSync)("git pull", { stdio: "inherit" });
(0, child_process_1.execSync)(`git diff --quiet && git diff --staged --quiet || git commit -am "${commitMessage}"`, {
(0, child_process_1.execSync)(`git config --global user.email "${commitEmail}"`, {
stdio: "inherit",
});
(0, child_process_1.execSync)(`git config --global user.name "${commitUsername}"`, {
stdio: "inherit",
});
(0, child_process_1.execSync)("git pull", { stdio: "inherit" });
(0, child_process_1.execSync)(`git diff --quiet && git diff --staged --quiet || git commit -am "${commitMessage}"`, { stdio: "inherit" });
(0, child_process_1.execSync)("git push", { stdio: "inherit" });
}
catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit 36d4ffa

Please sign in to comment.