Skip to content

Commit

Permalink
Merge pull request #1 from yanamura/add-arg
Browse files Browse the repository at this point in the history
Add suport custom input tag
  • Loading branch information
yanamura authored May 16, 2020
2 parents 0dc7c3a + 1af343e commit 8cba043
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This action generate git merge diff between tags.

# Usage

## Diff between latest and previous tag
```yaml
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
Expand All @@ -12,6 +13,43 @@ This action generate git merge diff between tags.
uses: yanamura/git-merge-diff@v1
```
or
```yaml
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- name: Diff
id: diff
uses: yanamura/git-merge-diff@v1
with:
from: prev
to: latest
```
## Diff between HEAD and latest tag
```yaml
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- name: Diff
id: diff
uses: yanamura/git-merge-diff@v1
with:
from: latest
to: HEAD
```
## Diff between specified tags
```yaml
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- name: Diff
id: diff
uses: yanamura/git-merge-diff@v1
with:
from: v1.0.0
to: v1.1.0
```
> Note: don't forget to fetch.(actions/checkout only fetch depth=0)
## get output(merge diff)
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: "git merge diff"
description: "generate git merge diff between tags"
inputs:
from:
description: "from tag"
required: false
default: "prev"
to:
description: "to tag"
required: false
default: "latest"
runs:
using: "node12"
main: "dist/index.js"
Expand Down
27 changes: 24 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,25 @@ module.exports = require("os");
const core = __webpack_require__(470)
const exec = __webpack_require__(986)

function getTag(tags, name) {
if (name == "prev") {
if (tags.length < 2) {
core.setFailed("need more than 2 tags.")
return ""
}

return tags[tags.length - 2]
} else if (name == "latest") {
return tags[tags.length - 1]
} else {
return name
}
}

async function run() {
const from = core.getInput("from")
const to = core.getInput("to")

let output = ''
const options = {};
options.listeners = {
Expand All @@ -980,12 +998,15 @@ async function run() {

output = ''

if (tags.length < 2) {
core.setFailed("need more than 2 tags.")
const from_tag = getTag(tags, from)
const to_tag = getTag(tags, to)

if (from_tag.length == 0 || to_tag.length == 0) {
core.setFailed("from or to is invalid")
return
}

const command = `git log ${tags[tags.length - 2]}..${tags[tags.length - 1]} --merges --reverse --pretty=format:"* %b"`
const command = `git log ${from_tag}..${to_tag} --merges --reverse --pretty=format:"* %b"`
console.log(command)

await exec.exec(command, [], options).catch(error => {
Expand Down
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
const core = require('@actions/core')
const exec = require('@actions/exec')

function getTag(tags, name) {
if (name == "prev") {
if (tags.length < 2) {
core.setFailed("need more than 2 tags.")
return ""
}

return tags[tags.length - 2]
} else if (name == "latest") {
return tags[tags.length - 1]
} else {
return name
}
}

async function run() {
const from = core.getInput("from")
const to = core.getInput("to")

let output = ''
const options = {};
options.listeners = {
Expand All @@ -21,12 +39,15 @@ async function run() {

output = ''

if (tags.length < 2) {
core.setFailed("need more than 2 tags.")
const from_tag = getTag(tags, from)
const to_tag = getTag(tags, to)

if (from_tag.length == 0 || to_tag.length == 0) {
core.setFailed("from or to is invalid")
return
}

const command = `git log ${tags[tags.length - 2]}..${tags[tags.length - 1]} --merges --reverse --pretty=format:"* %b"`
const command = `git log ${from_tag}..${to_tag} --merges --reverse --pretty=format:"* %b"`
console.log(command)

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

0 comments on commit 8cba043

Please sign in to comment.