@@ -29,22 +29,20 @@ class StdoutCapture {
29
29
}
30
30
}
31
31
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" ) ;
35
34
36
- // const cap = new StdoutCapture();
35
+ const cap = new StdoutCapture ( ) ;
37
36
38
- // await run();
37
+ await run ( ) ;
39
38
40
- // cap.stopCapture();
39
+ cap . stopCapture ( ) ;
41
40
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
+ } ) ;
44
43
45
44
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" ) ;
48
46
49
47
const cap = new StdoutCapture ( ) ;
50
48
@@ -55,75 +53,79 @@ test('builds major release based on exclamation mark', async () => {
55
53
expect ( cap . captured ) . toContain ( "set-output name=new_tag,::my-prefix-2.0.0" ) ;
56
54
} ) ;
57
55
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 ( ) ;
61
62
62
- // const cap = new StdoutCapture ();
63
+ cap . stopCapture ( ) ;
63
64
64
- // await run();
65
+ expect ( cap . captured ) . toContain ( "set-output name=new_tag,::my-prefix-1.1.0" ) ;
66
+ } ) ;
65
67
66
- // cap.stopCapture();
68
+ test ( 'builds patch release' , async ( ) => {
69
+ prepare ( "8fe0159ec6ed3bb669765fbce6ed42a0b4adede5" , null ) ;
67
70
68
- // expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.1.0");
69
- // });
71
+ const cap = new StdoutCapture ( ) ;
70
72
71
- // test('builds patch release', async () => {
72
- // process.env.GITHUB_SHA = "8fe0159ec6ed3bb669765fbce6ed42a0b4adede5";
73
- // cp.execSync("git checkout 8fe0159ec6ed3bb669765fbce6ed42a0b4adede5");
73
+ await run ( ) ;
74
74
75
- // const cap = new StdoutCapture ();
75
+ cap . stopCapture ( ) ;
76
76
77
- // await run();
77
+ expect ( cap . captured ) . toContain ( "set-output name=new_tag,::my-prefix-1.0.1" ) ;
78
+ } ) ;
78
79
79
- // cap.stopCapture();
80
+ test ( 'does not build patch release due to dry_run' , async ( ) => {
81
+ prepare ( "8fe0159ec6ed3bb669765fbce6ed42a0b4adede5" , null ) ;
80
82
81
- // expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.0.1");
82
- // });
83
+ process . env . INPUT_dry_run = "true" ;
83
84
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 ( ) ;
87
86
88
- // process.env.INPUT_dry_run = "true" ;
87
+ await run ( ) ;
89
88
90
- // const cap = new StdoutCapture ();
89
+ cap . stopCapture ( ) ;
91
90
92
- // await run();
91
+ expect ( cap . captured ) . toContain ( "::set-output name=dry_run,::true" ) ;
92
+ } ) ;
93
93
94
- // cap.stopCapture();
94
+ test ( 'builds no release due to missing keyword' , async ( ) => {
95
+ prepare ( "3e039e60919e4ad573e11b508be57fb13919f330" , "a-no-release-change" ) ;
95
96
96
- // expect(cap.captured).toContain("::set-output name=dry_run,::true");
97
- // });
97
+ const cap = new StdoutCapture ( ) ;
98
98
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 ( ) ;
102
100
103
- // const cap = new StdoutCapture ();
101
+ cap . stopCapture ( ) ;
104
102
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
+ } ) ;
106
106
107
- // cap.stopCapture();
107
+ test ( 'builds release due to default_bump' , async ( ) => {
108
+ prepare ( "3e039e60919e4ad573e11b508be57fb13919f330" , "a-no-release-change" ) ;
108
109
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" ;
112
111
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 ( ) ;
116
113
117
- // process.env.INPUT_default_bump = "patch" ;
114
+ await run ( ) ;
118
115
119
- // const cap = new StdoutCapture ();
116
+ cap . stopCapture ( ) ;
120
117
121
- // await run();
118
+ expect ( cap . captured ) . toContain ( "set-output name=new_tag,::my-prefix-1.0.1" ) ;
119
+ } ) ;
122
120
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
+ }
124
126
125
- // expect(cap.captured).toContain("set-output name=new_tag,::my-prefix-1.0.1" );
126
- // });
127
+ cp . execSync ( `git checkout ${ rev } ` ) ;
128
+ }
127
129
128
130
function prepareMockRepo ( ) {
129
131
if ( ! fs . existsSync ( "tmp" ) ) {
@@ -132,27 +134,15 @@ function prepareMockRepo() {
132
134
133
135
process . chdir ( "tmp" ) ;
134
136
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" ) ;
138
146
}
139
147
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
+ }
0 commit comments