Skip to content

Commit d3e101b

Browse files
authored
Add dry-run input (#144)
Co-authored-by: CrazyMax <[email protected]>
1 parent 1424fdc commit d3e101b

File tree

6 files changed

+143
-102
lines changed

6 files changed

+143
-102
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
branches:
88
- 'dev'
99
- 'releases/v*'
10+
pull_request:
11+
branches:
12+
- 'dev'
13+
- 'releases/v*'
1014

1115
jobs:
1216
ci:
@@ -92,5 +96,6 @@ jobs:
9296
target_branch: ${{ matrix.target_branch }}
9397
keep_history: ${{ matrix.keep_history }}
9498
build_dir: public
99+
dry-run: ${{ github.event_name == 'pull_request' }}
95100
env:
96101
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Following inputs can be used as `step.with` keys
138138
| `commit_message` | String | Commit message (default `Deploy to GitHub pages`) |
139139
| `fqdn` | String | Write the given domain name to the CNAME file |
140140
| `jekyll` | Bool | Allow Jekyll to build your site (default `true`) |
141+
| `dry-run` | Bool | If enabled, nothing will be pushed (default `false`) |
141142

142143
### environment variables
143144

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ inputs:
4545
description: 'Allow Jekyll to build your site'
4646
default: 'true'
4747
required: false
48+
dry-run:
49+
description: 'If enabled, nothing will be pushed'
50+
default: 'false'
51+
required: false
4852

4953
runs:
5054
using: 'node12'

dist/index.js

Lines changed: 68 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/git.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as exec from './exec';
1+
import * as mexec from './exec';
2+
import * as exec from '@actions/exec';
23

34
export const defaults = {
45
targetBranch: 'gh-pages',
@@ -7,51 +8,51 @@ export const defaults = {
78
message: 'Deploy to GitHub pages'
89
};
910

10-
const git = async (args: string[] = []): Promise<string> => {
11-
return await exec.exec(`git`, args, true).then(res => {
11+
export async function remoteBranchExists(remoteURL: string, branch: string): Promise<boolean> {
12+
return await mexec.exec('git', ['ls-remote', '--heads', remoteURL, branch], true).then(res => {
1213
if (res.stderr != '' && !res.success) {
1314
throw new Error(res.stderr);
1415
}
15-
return res.stdout.trim();
16-
});
17-
};
18-
19-
export async function remoteBranchExists(remoteURL: string, branch: string): Promise<boolean> {
20-
return await git(['ls-remote', '--heads', remoteURL, branch]).then(output => {
21-
return output.trim().length > 0;
16+
return res.stdout.trim().length > 0;
2217
});
2318
}
2419

2520
export async function clone(remoteURL: string, branch: string, dest: string): Promise<void> {
26-
await git(['clone', '--quiet', '--branch', branch, '--depth', '1', remoteURL, dest]);
21+
await exec.exec('git', ['clone', '--quiet', '--branch', branch, '--depth', '1', remoteURL, dest]);
2722
}
2823

2924
export async function init(dest: string): Promise<void> {
30-
await git(['init', dest]);
25+
await exec.exec('git', ['init', dest]);
3126
}
3227

3328
export async function checkout(branch: string): Promise<void> {
34-
await git(['checkout', '--orphan', branch]);
29+
await exec.exec('git', ['checkout', '--orphan', branch]);
3530
}
3631

3732
export async function isDirty(): Promise<boolean> {
38-
return await git(['status', '--short']).then(output => {
39-
return output.trim().length > 0;
33+
return await mexec.exec('git', ['status', '--short'], true).then(res => {
34+
if (res.stderr != '' && !res.success) {
35+
throw new Error(res.stderr);
36+
}
37+
return res.stdout.trim().length > 0;
4038
});
4139
}
4240

4341
export async function hasChanges(): Promise<boolean> {
44-
return await git(['status', '--porcelain']).then(output => {
45-
return output.trim().length > 0;
42+
return await mexec.exec('git', ['status', '--porcelain'], true).then(res => {
43+
if (res.stderr != '' && !res.success) {
44+
throw new Error(res.stderr);
45+
}
46+
return res.stdout.trim().length > 0;
4647
});
4748
}
4849

4950
export async function setConfig(key: string, value: string): Promise<void> {
50-
await git(['config', key, value]);
51+
await exec.exec('git', ['config', key, value]);
5152
}
5253

5354
export async function add(pattern: string): Promise<void> {
54-
await git(['add', '--all', pattern]);
55+
await exec.exec('git', ['add', '--all', pattern]);
5556
}
5657

5758
export async function commit(allowEmptyCommit: boolean, author: string, message: string): Promise<void> {
@@ -64,12 +65,15 @@ export async function commit(allowEmptyCommit: boolean, author: string, message:
6465
args.push('--author', author);
6566
}
6667
args.push('--message', message);
67-
await git(args);
68+
await exec.exec('git', args);
6869
}
6970

7071
export async function showStat(): Promise<string> {
71-
return await git(['show', `--stat-count=2000`, 'HEAD']).then(output => {
72-
return output;
72+
return await mexec.exec('git', ['show', `--stat-count=2000`, 'HEAD'], true).then(res => {
73+
if (res.stderr != '' && !res.success) {
74+
throw new Error(res.stderr);
75+
}
76+
return res.stdout.trim();
7377
});
7478
}
7579

@@ -80,5 +84,5 @@ export async function push(remoteURL: string, branch: string, force: boolean): P
8084
args.push('--force');
8185
}
8286
args.push(remoteURL, branch);
83-
await git(args);
87+
await exec.exec('git', args);
8488
}

0 commit comments

Comments
 (0)