Skip to content

Commit 8cba043

Browse files
authored
Merge pull request #1 from yanamura/add-arg
Add suport custom input tag
2 parents 0dc7c3a + 1af343e commit 8cba043

File tree

4 files changed

+95
-6
lines changed

4 files changed

+95
-6
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This action generate git merge diff between tags.
44

55
# Usage
66

7+
## Diff between latest and previous tag
78
```yaml
89
- uses: actions/checkout@v2
910
- run: git fetch --prune --unshallow
@@ -12,6 +13,43 @@ This action generate git merge diff between tags.
1213
uses: yanamura/git-merge-diff@v1
1314
```
1415
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+
1553
> Note: don't forget to fetch.(actions/checkout only fetch depth=0)
1654
1755
## get output(merge diff)

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
name: "git merge diff"
22
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"
312
runs:
413
using: "node12"
514
main: "dist/index.js"

dist/index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,25 @@ module.exports = require("os");
960960
const core = __webpack_require__(470)
961961
const exec = __webpack_require__(986)
962962

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+
963978
async function run() {
979+
const from = core.getInput("from")
980+
const to = core.getInput("to")
981+
964982
let output = ''
965983
const options = {};
966984
options.listeners = {
@@ -980,12 +998,15 @@ async function run() {
980998

981999
output = ''
9821000

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")
9851006
return
9861007
}
9871008

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"`
9891010
console.log(command)
9901011

9911012
await exec.exec(command, [], options).catch(error => {

index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
const core = require('@actions/core')
22
const exec = require('@actions/exec')
33

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+
419
async function run() {
20+
const from = core.getInput("from")
21+
const to = core.getInput("to")
22+
523
let output = ''
624
const options = {};
725
options.listeners = {
@@ -21,12 +39,15 @@ async function run() {
2139

2240
output = ''
2341

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")
2647
return
2748
}
2849

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"`
3051
console.log(command)
3152

3253
await exec.exec(command, [], options).catch(error => {

0 commit comments

Comments
 (0)