Skip to content

Commit

Permalink
First stable changes
Browse files Browse the repository at this point in the history
  • Loading branch information
one-aalam committed Sep 15, 2021
1 parent ae260a6 commit 5ca8de6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
12 changes: 10 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ inputs:
description: 'Destination branch to push changes'
required: false
default: 'main'
astro_path:
description: 'Directory containing the jekyll root folder.'
site_path:
description: 'Directory containing the SSG root folder.'
required: false
default: '.'
site_drafts_dir:
description: 'Directory containing all the drafts in *.md format.'
required: false
default: 'src/drafts'
site_published_dir:
description: 'Directory to contain all the published content in *.md format.'
required: false
default: 'src/pages/blog'
runs:
using: 'node12'
main: 'dist/index.js'
16 changes: 8 additions & 8 deletions 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 dist/index.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { exec } from '@actions/exec'

async function run(): Promise<void> {
try {
const astroPath = core.getInput('astroPath') || '.'
const astroSrcDir = path.join(astroPath, 'src')
const astroDraftsDir = path.join(astroSrcDir, 'drafts')

const sitePath = core.getInput('site_path') || '.'

core.debug(`Starting the scan for future posts...`)
const now = new Date();
Expand All @@ -29,15 +26,18 @@ async function run(): Promise<void> {
const gitEmail = core.getInput('git_email') || '41898282+github-actions[bot]@users.noreply.github.com'
const gitMessage = core.getInput('git_message') || 'Publish Drafts'

const siteDraftsDir = path.join(sitePath, core.getInput('site_drafts_dir') || 'src/drafts')
const sitePublishedDir = path.join(sitePath, core.getInput('site_published_dir') || 'src/pages/blog')

core.debug(`Started the scan at ${now}`)
core.debug(`Scanning all the files available in ${astroDraftsDir}`)
core.debug(`Scanning all the files available in ${siteDraftsDir}`)

if (githubActor) {
await exec('git', ['config', '--global', 'user.email', gitEmail]);
await exec('git', ['config', '--global', 'user.name', gitUsername]);
}

const patterns = [path.join(astroDraftsDir, '*.md')]
const patterns = [path.join(siteDraftsDir, '*.md')]
const globber = await glob.create(patterns.join('\n'), { followSymbolicLinks: false })
for await (const file of globber.globGenerator()) {
fileCount += 1;
Expand All @@ -50,8 +50,8 @@ async function run(): Promise<void> {
const rdate = new Date(Date.parse(filePubDate));
if (rdate.getFullYear() >= 2000) {
if (now.getTime() >= rdate.getTime()) {
core.debug(`Gonna publish ${file} to the "/pages/posts" directory`)
const newFile = path.resolve(astroSrcDir, 'pages', 'posts', basename)
core.debug(`Gonna publish ${file} to the ${sitePublishedDir} directory`)
const newFile = path.resolve(sitePublishedDir, basename)
core.warning(`${file} --> ${newFile}`);
await exec('git', ['mv', file , newFile]);
draftCount += 1
Expand All @@ -64,7 +64,7 @@ async function run(): Promise<void> {
core.warning(`Found ${fileCount} files. Moved drafts: ${draftCount}`);

if (draftCount > 0) {
const remote_repo = `https://${githubActor}:${githubToken}@github.com/${gitUsername}/${githubRepository}.git`;
const remote_repo = `https://${githubActor}:${githubToken}@github.com/${githubRepository}.git`;
await exec('git', ['commit', '-m', gitMessage]);
await exec('git', ['push', remote_repo, `HEAD:${branch}`, '--follow-tags', '--force']);
}
Expand Down

0 comments on commit 5ca8de6

Please sign in to comment.