Skip to content

Commit d9fff67

Browse files
authored
feat: add options to sync the gh-pages branch with the base branch … (#815)
1 parent 49b341f commit d9fff67

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

docs/nx-ghpages/Executors/deploy.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ Deploy a page to a specified repository's gh-pages branch.
2121
### commitMessage
2222

2323
- (string): Message of the git commit to gh-pages branch
24+
25+
### baseBranch
26+
27+
- (string): Base branch to sync the gh-pages branch with
28+
29+
### syncWithBaseBranch
30+
31+
- (string): Indicate if the gh-pages branch should be synced with the base branch
32+
33+
### syncStrategy
34+
35+
- (string): Git command to use to sync the gh-pages branch with the base branch

packages/nx-ghpages/src/executors/deploy/executor.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const options: BuildExecutorSchema = {
2222
remote: '',
2323
remoteName: '',
2424
commitMessage: '',
25+
baseBranch: '',
26+
syncWithBaseBranch: false,
27+
syncStrategy: 'rebase',
2528
};
2629

2730
describe('Build Executor', () => {

packages/nx-ghpages/src/executors/deploy/executor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { join } from 'path';
66
import { promisify } from 'util';
77

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

1011
const exec = promisify(execCallback);
1112

@@ -60,6 +61,15 @@ export default async function deployExecutor(options: BuildExecutorSchema) {
6061
logger.warn('Resetting gh-pages branch, as it already exists.');
6162
await exec(`git checkout -B gh-pages`, { cwd: directory });
6263
}
64+
if (options.syncWithBaseBranch) {
65+
const baseBranch =
66+
options.baseBranch || readNxJson()?.affected?.defaultBase || 'master';
67+
const syncStrategy = options.syncStrategy;
68+
await exec(`git ${syncStrategy} ${options.remoteName}/${baseBranch}`, {
69+
cwd: directory,
70+
});
71+
}
72+
6373
await exec(`git push -f --set-upstream ${options.remoteName} gh-pages`, {
6474
cwd: directory,
6575
});

packages/nx-ghpages/src/executors/deploy/schema.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ export interface BuildExecutorSchema {
33
directory: string;
44
remoteName: string;
55
commitMessage: string;
6+
baseBranch: string;
7+
syncWithBaseBranch: boolean;
8+
syncStrategy: 'rebase' | 'merge';
69
}

packages/nx-ghpages/src/executors/deploy/schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@
2222
"type": "string",
2323
"description": "Message of the git commit to gh-pages branch",
2424
"default": "chore: :rocket: deploy new version to Github Pages"
25+
},
26+
"baseBranch": {
27+
"type": "string",
28+
"description": "Base branch to sync the gh-pages branch with",
29+
"default": "master"
30+
},
31+
"syncWithBaseBranch": {
32+
"type": "string",
33+
"description": "Indicate if the gh-pages branch should be synced with the base branch",
34+
"default": "false"
35+
},
36+
"syncStrategy": {
37+
"type": "string",
38+
"description": "Git command to use to sync the gh-pages branch with the base branch",
39+
"enum": ["rebase", "merge"],
40+
"default": "rebase"
2541
}
2642
},
2743
"required": ["remote", "directory"]

0 commit comments

Comments
 (0)