diff --git a/README.md b/README.md index 6a02386..82fd822 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/action.yml b/action.yml index 5c9e1ad..30e33a1 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/dist/index.js b/dist/index.js index a4b98d3..9301177 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 = { @@ -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 => { diff --git a/index.js b/index.js index c23056b..f31f3fe 100644 --- a/index.js +++ b/index.js @@ -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 = { @@ -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 => {