Skip to content

Commit

Permalink
feat: add options to sync the gh-pages branch with the base branch … (
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Jan 31, 2024
1 parent 49b341f commit d9fff67
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/nx-ghpages/Executors/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ Deploy a page to a specified repository's gh-pages branch.
### commitMessage

- (string): Message of the git commit to gh-pages branch

### baseBranch

- (string): Base branch to sync the gh-pages branch with

### syncWithBaseBranch

- (string): Indicate if the gh-pages branch should be synced with the base branch

### syncStrategy

- (string): Git command to use to sync the gh-pages branch with the base branch
3 changes: 3 additions & 0 deletions packages/nx-ghpages/src/executors/deploy/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const options: BuildExecutorSchema = {
remote: '',
remoteName: '',
commitMessage: '',
baseBranch: '',
syncWithBaseBranch: false,
syncStrategy: 'rebase',
};

describe('Build Executor', () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/nx-ghpages/src/executors/deploy/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { join } from 'path';
import { promisify } from 'util';

import { BuildExecutorSchema } from './schema';
import { readNxJson } from 'nx/src/config/nx-json';

const exec = promisify(execCallback);

Expand Down Expand Up @@ -60,6 +61,15 @@ export default async function deployExecutor(options: BuildExecutorSchema) {
logger.warn('Resetting gh-pages branch, as it already exists.');
await exec(`git checkout -B gh-pages`, { cwd: directory });
}
if (options.syncWithBaseBranch) {
const baseBranch =
options.baseBranch || readNxJson()?.affected?.defaultBase || 'master';
const syncStrategy = options.syncStrategy;
await exec(`git ${syncStrategy} ${options.remoteName}/${baseBranch}`, {
cwd: directory,
});
}

await exec(`git push -f --set-upstream ${options.remoteName} gh-pages`, {
cwd: directory,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-ghpages/src/executors/deploy/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ export interface BuildExecutorSchema {
directory: string;
remoteName: string;
commitMessage: string;
baseBranch: string;
syncWithBaseBranch: boolean;
syncStrategy: 'rebase' | 'merge';
}
16 changes: 16 additions & 0 deletions packages/nx-ghpages/src/executors/deploy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
"type": "string",
"description": "Message of the git commit to gh-pages branch",
"default": "chore: :rocket: deploy new version to Github Pages"
},
"baseBranch": {
"type": "string",
"description": "Base branch to sync the gh-pages branch with",
"default": "master"
},
"syncWithBaseBranch": {
"type": "string",
"description": "Indicate if the gh-pages branch should be synced with the base branch",
"default": "false"
},
"syncStrategy": {
"type": "string",
"description": "Git command to use to sync the gh-pages branch with the base branch",
"enum": ["rebase", "merge"],
"default": "rebase"
}
},
"required": ["remote", "directory"]
Expand Down

0 comments on commit d9fff67

Please sign in to comment.