Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for mulitple sites without keeping history #209

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## About

A GitHub Action to deploy to GitHub Pages
A fork of [Crazy-max's GitHub Action](https://github.com/crazy-max/ghaction-github-pages) to deploy to GitHub Pages

![GitHub Pages](.github/ghaction-github-pages.png)

Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'GitHub Pages'
description: 'GitHub Action to deploy to GitHub Pages'
description: 'GitHub Action to deploy mulitple sites to GitHub Pages'
author: 'crazy-max'
branding:
color: 'green'
Expand All @@ -22,6 +22,10 @@ inputs:
description: 'Create incremental commit instead of doing push force'
default: 'false'
required: false
multiple_sites:
description: 'Supports for deployment of multiple sites (one per subdir)'
default: 'false'
required: false
allow_empty_commit:
description: 'Allow an empty commit to be created'
default: 'true'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import addressparser from 'addressparser';
import {copy} from 'fs-extra';
import {copy, emptydirSync} from 'fs-extra';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
Expand All @@ -12,6 +12,7 @@ async function run() {
const repo: string = core.getInput('repo') || process.env['GITHUB_REPOSITORY'] || '';
const targetBranch: string = core.getInput('target_branch') || git.defaults.targetBranch;
const keepHistory: boolean = /true/i.test(core.getInput('keep_history'));
const multipleSites: boolean = /true/i.test(core.getInput('multiple_sites'));
const allowEmptyCommit: boolean = /true/i.test(core.getInput('allow_empty_commit'));
const buildDir: string = core.getInput('build_dir', {required: true});
const absoluteBuildDir: boolean = /true/i.test(core.getInput('absolute_build_dir'));
Expand Down Expand Up @@ -52,7 +53,7 @@ async function run() {

process.chdir(tmpdir);

if (keepHistory && remoteBranchExists) {
if ((keepHistory || multipleSites) && remoteBranchExists) {
core.startGroup(`Cloning ${repo}`);
await git.clone(remoteURL, targetBranch, '.');
core.endGroup();
Expand All @@ -63,10 +64,40 @@ async function run() {
core.endGroup();
}

const buildPath = absoluteBuildDir ? buildDir : path.join(currentdir, buildDir);
if (multipleSites && !keepHistory) {
if (verbose) {
core.info(`Checking if directories need to be emptied`);
}
// Empty the subdirectories that are part of the build in order to keep the others
const files = fs.readdirSync(buildPath);
for (const file of files) {
const sourceSubDir=path.resolve(tmpdir, file);
if (verbose) {
core.info(`Checking if directory ${sourceSubDir} need to be emptied`);
}

if (fs.existsSync(sourceSubDir)) {
if (fs.lstatSync(sourceSubDir).isDirectory()) {
if (verbose) {
core.info(`Subdirectory ${file} must be emptied`);
}
// This directory is part of the build, so empty it to simulate keepHistory
emptydirSync(sourceSubDir);
core.debug(`Emptied subdirectory ${sourceSubDir}`);
} else if (verbose) {
core.info(`${sourceSubDir} is not a directory`);
}
} else if (verbose) {
core.info(`No previous history for ${file}`);

}
}
}

let copyCount = 0;
await core.group(`Copying ${path.join(currentdir, buildDir)} to ${tmpdir}`, async () => {
const sourcePath = absoluteBuildDir ? buildDir : path.join(currentdir, buildDir);
await copy(sourcePath, tmpdir, {
await core.group(`Copying ${buildPath} to ${tmpdir}`, async () => {
await copy(buildPath, tmpdir, {
filter: (src, dest) => {
if (verbose) {
core.info(`${src} => ${dest}`);
Expand Down Expand Up @@ -98,7 +129,7 @@ async function run() {

const isDirty: boolean = await git.isDirty();
core.debug(`isDirty=${isDirty}`);
if (keepHistory && remoteBranchExists && !isDirty) {
if ((keepHistory || multipleSites) && remoteBranchExists && !isDirty) {
core.info('No changes to commit');
return;
}
Expand Down