File tree Expand file tree Collapse file tree 4 files changed +95
-6
lines changed Expand file tree Collapse file tree 4 files changed +95
-6
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ This action generate git merge diff between tags.
4
4
5
5
# Usage
6
6
7
+ ## Diff between latest and previous tag
7
8
``` yaml
8
9
- uses : actions/checkout@v2
9
10
- run : git fetch --prune --unshallow
@@ -12,6 +13,43 @@ This action generate git merge diff between tags.
12
13
uses : yanamura/git-merge-diff@v1
13
14
` ` `
14
15
16
+ or
17
+
18
+ ` ` ` yaml
19
+ - uses : actions/checkout@v2
20
+ - run : git fetch --prune --unshallow
21
+ - name : Diff
22
+ id : diff
23
+ uses : yanamura/git-merge-diff@v1
24
+ with :
25
+ from : prev
26
+ to : latest
27
+ ` ` `
28
+
29
+ ## Diff between HEAD and latest tag
30
+ ` ` ` yaml
31
+ - uses : actions/checkout@v2
32
+ - run : git fetch --prune --unshallow
33
+ - name : Diff
34
+ id : diff
35
+ uses : yanamura/git-merge-diff@v1
36
+ with :
37
+ from : latest
38
+ to : HEAD
39
+ ` ` `
40
+
41
+ ## Diff between specified tags
42
+ ` ` ` yaml
43
+ - uses : actions/checkout@v2
44
+ - run : git fetch --prune --unshallow
45
+ - name : Diff
46
+ id : diff
47
+ uses : yanamura/git-merge-diff@v1
48
+ with :
49
+ from : v1.0.0
50
+ to : v1.1.0
51
+ ` ` `
52
+
15
53
> Note: don't forget to fetch.(actions/checkout only fetch depth=0)
16
54
17
55
## get output(merge diff)
Original file line number Diff line number Diff line change 1
1
name : " git merge diff"
2
2
description : " generate git merge diff between tags"
3
+ inputs :
4
+ from :
5
+ description : " from tag"
6
+ required : false
7
+ default : " prev"
8
+ to :
9
+ description : " to tag"
10
+ required : false
11
+ default : " latest"
3
12
runs :
4
13
using : " node12"
5
14
main : " dist/index.js"
Original file line number Diff line number Diff line change @@ -960,7 +960,25 @@ module.exports = require("os");
960
960
const core = __webpack_require__ ( 470 )
961
961
const exec = __webpack_require__ ( 986 )
962
962
963
+ function getTag ( tags , name ) {
964
+ if ( name == "prev" ) {
965
+ if ( tags . length < 2 ) {
966
+ core . setFailed ( "need more than 2 tags." )
967
+ return ""
968
+ }
969
+
970
+ return tags [ tags . length - 2 ]
971
+ } else if ( name == "latest" ) {
972
+ return tags [ tags . length - 1 ]
973
+ } else {
974
+ return name
975
+ }
976
+ }
977
+
963
978
async function run ( ) {
979
+ const from = core . getInput ( "from" )
980
+ const to = core . getInput ( "to" )
981
+
964
982
let output = ''
965
983
const options = { } ;
966
984
options . listeners = {
@@ -980,12 +998,15 @@ async function run() {
980
998
981
999
output = ''
982
1000
983
- if ( tags . length < 2 ) {
984
- core . setFailed ( "need more than 2 tags." )
1001
+ const from_tag = getTag ( tags , from )
1002
+ const to_tag = getTag ( tags , to )
1003
+
1004
+ if ( from_tag . length == 0 || to_tag . length == 0 ) {
1005
+ core . setFailed ( "from or to is invalid" )
985
1006
return
986
1007
}
987
1008
988
- const command = `git log ${ tags [ tags . length - 2 ] } ..${ tags [ tags . length - 1 ] } --merges --reverse --pretty=format:"* %b"`
1009
+ const command = `git log ${ from_tag } ..${ to_tag } --merges --reverse --pretty=format:"* %b"`
989
1010
console . log ( command )
990
1011
991
1012
await exec . exec ( command , [ ] , options ) . catch ( error => {
Original file line number Diff line number Diff line change 1
1
const core = require ( '@actions/core' )
2
2
const exec = require ( '@actions/exec' )
3
3
4
+ function getTag ( tags , name ) {
5
+ if ( name == "prev" ) {
6
+ if ( tags . length < 2 ) {
7
+ core . setFailed ( "need more than 2 tags." )
8
+ return ""
9
+ }
10
+
11
+ return tags [ tags . length - 2 ]
12
+ } else if ( name == "latest" ) {
13
+ return tags [ tags . length - 1 ]
14
+ } else {
15
+ return name
16
+ }
17
+ }
18
+
4
19
async function run ( ) {
20
+ const from = core . getInput ( "from" )
21
+ const to = core . getInput ( "to" )
22
+
5
23
let output = ''
6
24
const options = { } ;
7
25
options . listeners = {
@@ -21,12 +39,15 @@ async function run() {
21
39
22
40
output = ''
23
41
24
- if ( tags . length < 2 ) {
25
- core . setFailed ( "need more than 2 tags." )
42
+ const from_tag = getTag ( tags , from )
43
+ const to_tag = getTag ( tags , to )
44
+
45
+ if ( from_tag . length == 0 || to_tag . length == 0 ) {
46
+ core . setFailed ( "from or to is invalid" )
26
47
return
27
48
}
28
49
29
- const command = `git log ${ tags [ tags . length - 2 ] } ..${ tags [ tags . length - 1 ] } --merges --reverse --pretty=format:"* %b"`
50
+ const command = `git log ${ from_tag } ..${ to_tag } --merges --reverse --pretty=format:"* %b"`
30
51
console . log ( command )
31
52
32
53
await exec . exec ( command , [ ] , options ) . catch ( error => {
You can’t perform that action at this time.
0 commit comments