Skip to content

Commit 404f9a1

Browse files
committed
feat: automatic unshallow
1 parent 7891cbf commit 404f9a1

File tree

2 files changed

+72
-75
lines changed

2 files changed

+72
-75
lines changed

__tests__/main.test.ts

+65-75
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,20 @@ class StdoutCapture {
2929
}
3030
}
3131

32-
// test('builds major release', async () => {
33-
// process.env.GITHUB_SHA = "7f42496b3e66a58642227e2200e6405c07537e5d";
34-
// cp.execSync("git checkout 7f42496b3e66a58642227e2200e6405c07537e5d");
32+
test('builds major release', async () => {
33+
prepare("7f42496b3e66a58642227e2200e6405c07537e5d", "master");
3534

36-
// const cap = new StdoutCapture();
35+
const cap = new StdoutCapture();
3736

38-
// await run();
37+
await run();
3938

40-
// cap.stopCapture();
39+
cap.stopCapture();
4140

42-
// expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-2.0.0");
43-
// });
41+
expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-2.0.0");
42+
});
4443

4544
test('builds major release based on exclamation mark', async () => {
46-
process.env.GITHUB_SHA = "ca5452210e047aa2e81021db45562f0b1c85a56c";
47-
cp.execSync("git checkout ca5452210e047aa2e81021db45562f0b1c85a56c");
45+
prepare("ca5452210e047aa2e81021db45562f0b1c85a56c", "a-different-breaking-change");
4846

4947
const cap = new StdoutCapture();
5048

@@ -55,75 +53,79 @@ test('builds major release based on exclamation mark', async () => {
5553
expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-2.0.0");
5654
});
5755

58-
// test('builds minor release', async () => {
59-
// process.env.GITHUB_SHA = "5b6c18f88b275b9654ea6f0448126c743133b5ff";
60-
// cp.execSync("git checkout 5b6c18f88b275b9654ea6f0448126c743133b5ff");
56+
test('builds minor release', async () => {
57+
prepare("5b6c18f88b275b9654ea6f0448126c743133b5ff", null);
58+
59+
const cap = new StdoutCapture();
60+
61+
await run();
6162

62-
// const cap = new StdoutCapture();
63+
cap.stopCapture();
6364

64-
// await run();
65+
expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.1.0");
66+
});
6567

66-
// cap.stopCapture();
68+
test('builds patch release', async () => {
69+
prepare("8fe0159ec6ed3bb669765fbce6ed42a0b4adede5", null);
6770

68-
// expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.1.0");
69-
// });
71+
const cap = new StdoutCapture();
7072

71-
// test('builds patch release', async () => {
72-
// process.env.GITHUB_SHA = "8fe0159ec6ed3bb669765fbce6ed42a0b4adede5";
73-
// cp.execSync("git checkout 8fe0159ec6ed3bb669765fbce6ed42a0b4adede5");
73+
await run();
7474

75-
// const cap = new StdoutCapture();
75+
cap.stopCapture();
7676

77-
// await run();
77+
expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.0.1");
78+
});
7879

79-
// cap.stopCapture();
80+
test('does not build patch release due to dry_run', async () => {
81+
prepare("8fe0159ec6ed3bb669765fbce6ed42a0b4adede5", null);
8082

81-
// expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.0.1");
82-
// });
83+
process.env.INPUT_dry_run = "true";
8384

84-
// test('does not build patch release due to dry_run', async () => {
85-
// process.env.GITHUB_SHA = "8fe0159ec6ed3bb669765fbce6ed42a0b4adede5";
86-
// cp.execSync("git checkout 8fe0159ec6ed3bb669765fbce6ed42a0b4adede5");
85+
const cap = new StdoutCapture();
8786

88-
// process.env.INPUT_dry_run = "true";
87+
await run();
8988

90-
// const cap = new StdoutCapture();
89+
cap.stopCapture();
9190

92-
// await run();
91+
expect(cap.captured).toContain("::set-output name=dry_run,::true");
92+
});
9393

94-
// cap.stopCapture();
94+
test('builds no release due to missing keyword', async () => {
95+
prepare("3e039e60919e4ad573e11b508be57fb13919f330", "a-no-release-change");
9596

96-
// expect(cap.captured).toContain("::set-output name=dry_run,::true");
97-
// });
97+
const cap = new StdoutCapture();
9898

99-
// test('builds no release due to missing keyword', async () => {
100-
// process.env.GITHUB_SHA = "3e039e60919e4ad573e11b508be57fb13919f330";
101-
// cp.execSync("git checkout 3e039e60919e4ad573e11b508be57fb13919f330");
99+
await run();
102100

103-
// const cap = new StdoutCapture();
101+
cap.stopCapture();
104102

105-
// await run();
103+
expect(cap.captured).not.toContain("::set-output name=new_tag");
104+
expect(cap.captured).toContain("::error::Nothing to bump - not building release");
105+
});
106106

107-
// cap.stopCapture();
107+
test('builds release due to default_bump', async () => {
108+
prepare("3e039e60919e4ad573e11b508be57fb13919f330", "a-no-release-change");
108109

109-
// expect(cap.captured).not.toContain("::set-output name=new_tag");
110-
// expect(cap.captured).toContain("::error::Nothing to bump - not building release");
111-
// });
110+
process.env.INPUT_default_bump = "patch";
112111

113-
// test('builds release due to default_bump', async () => {
114-
// process.env.GITHUB_SHA = "3e039e60919e4ad573e11b508be57fb13919f330";
115-
// cp.execSync("git checkout 3e039e60919e4ad573e11b508be57fb13919f330");
112+
const cap = new StdoutCapture();
116113

117-
// process.env.INPUT_default_bump = "patch";
114+
await run();
118115

119-
// const cap = new StdoutCapture();
116+
cap.stopCapture();
120117

121-
// await run();
118+
expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.0.1");
119+
});
122120

123-
// cap.stopCapture();
121+
function prepare(rev, branch) {
122+
process.env.GITHUB_SHA = rev;
123+
if (branch) {
124+
cp.execSync(`git fetch origin ${branch} --depth=1`);
125+
}
124126

125-
// expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.0.1");
126-
// });
127+
cp.execSync(`git checkout ${rev}`);
128+
}
127129

128130
function prepareMockRepo() {
129131
if (!fs.existsSync("tmp")) {
@@ -132,27 +134,15 @@ function prepareMockRepo() {
132134

133135
process.chdir("tmp");
134136

135-
if (!fs.existsSync("github-tag-action-mock-repo")) {
136-
console.log("Cloning https://github.com/hennejg/github-tag-action-mock-repo.git");
137-
cp.execSync("git clone https://github.com/hennejg/github-tag-action-mock-repo.git");
137+
const name = "github-tag-action-mock-repo";
138+
if (!fs.existsSync(name)) {
139+
console.log(`Cloning https://github.com/hennejg/${name}`);
140+
cp.execSync(`git init ${name}`);
141+
142+
process.chdir(name);
143+
144+
cp.execSync(`git remote add origin https://github.com/hennejg/${name}.git`);
145+
cp.execSync("git fetch origin --no-tags --prune --depth=1 --no-recurse-submodules");
138146
}
139147

140-
process.chdir("github-tag-action-mock-repo");
141-
}
142-
// test('wait 500 ms', async () => {
143-
// const start = new Date();
144-
// await wait(500);
145-
// const end = new Date();
146-
// var delta = Math.abs(end.getTime() - start.getTime());
147-
// expect(delta).toBeGreaterThan(450);
148-
// });
149-
150-
// // shows how the runner will run a javascript action with env / stdout protocol
151-
// test('test runs', () => {
152-
// process.env['INPUT_MILLISECONDS'] = '500';
153-
// const ip = path.join(__dirname, '..', 'lib', 'main.js');
154-
// const options: cp.ExecSyncOptions = {
155-
// env: process.env
156-
// };
157-
// console.log(cp.execSync(`node ${ip}`, options).toString());
158-
// });
148+
}

src/lib.ts

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ export async function run() {
6565
.split(",")
6666
.every(branch => !GITHUB_REF.replace("refs/heads/", "").match(branch));
6767

68+
// if directory is shallow, unshallow it
69+
const shallow = (await exec("git rev-parse --is-shallow-repository")).stdout.trim();
70+
if (shallow.match("true")) {
71+
await exec("git fetch --unshallow");
72+
}
73+
74+
// fetch tags
6875
await exec("git fetch --tags");
6976

7077
const hasTag = !!(await exec("git tag")).stdout.trim();

0 commit comments

Comments
 (0)