|
1 |
| -const { exec } = require('child_process'); |
| 1 | +const { exec } = require("child_process"); |
2 | 2 |
|
3 | 3 | // github actions pass inputs as environment variables prefixed with INPUT_ and uppercased
|
4 | 4 | function getInput(key) {
|
5 |
| - var variable = 'INPUT_'+key; |
6 |
| - var result = process.env[variable.toUpperCase()]; |
7 |
| - console.log(`Using input for ${key}: ${result}`); |
8 |
| - return result; |
| 5 | + var variable = "INPUT_" + key; |
| 6 | + var result = process.env[variable.toUpperCase()]; |
| 7 | + console.log(`Using input for ${key}: ${result}`); |
| 8 | + return result; |
9 | 9 | }
|
10 | 10 |
|
11 | 11 | // rather than npm install @actions/core, output using the console logging syntax
|
12 | 12 | // see https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter
|
13 | 13 | function setOutput(key, value) {
|
14 |
| - console.log(`::set-output name=${key}::${value}`) |
| 14 | + console.log(`::set-output name=${key}::${value}`); |
15 | 15 | }
|
16 | 16 |
|
17 | 17 | try {
|
18 |
| - const include = getInput('include'); |
19 |
| - const exclude = getInput('exclude'); |
20 |
| - const commitIsh = getInput('commit-ish'); |
21 |
| - const skipUnshallow = getInput('skip-unshallow') === 'true'; |
| 18 | + const include = getInput("include"); |
| 19 | + const exclude = getInput("exclude"); |
| 20 | + const commitIsh = getInput("commit-ish"); |
| 21 | + const long = getInput("long") === "true"; |
| 22 | + const skipUnshallow = getInput("skip-unshallow") === "true"; |
22 | 23 |
|
23 |
| - var includeOption = ''; |
24 |
| - var excludeOption = ''; |
25 |
| - var commitIshOption = ''; |
| 24 | + var includeOption = ""; |
| 25 | + var excludeOption = ""; |
| 26 | + var commitIshOption = ""; |
| 27 | + var abbrevOption = long ? "" : "--abbrev=0"; |
26 | 28 |
|
27 |
| - if (typeof include === 'string' && include.length > 0) { |
28 |
| - includeOption = `--match '${include}'`; |
29 |
| - } |
| 29 | + if (typeof include === "string" && include.length > 0) { |
| 30 | + includeOption = `--match '${include}'`; |
| 31 | + } |
30 | 32 |
|
31 |
| - if (typeof exclude === 'string' && exclude.length > 0) { |
32 |
| - excludeOption = `--exclude '${exclude}'`; |
33 |
| - } |
| 33 | + if (typeof exclude === "string" && exclude.length > 0) { |
| 34 | + excludeOption = `--exclude '${exclude}'`; |
| 35 | + } |
34 | 36 |
|
35 |
| - if (typeof commitIsh === 'string') { |
36 |
| - if (commitIsh === '' || commitIsh === 'HEAD') { |
37 |
| - console.warn('Passing empty string or HEAD to commit-ish will get the "current" tag rather than "previous". For previous tag, try "HEAD~".'); |
38 |
| - } |
39 |
| - commitIshOption = `'${commitIsh}'`; |
| 37 | + if (typeof commitIsh === "string") { |
| 38 | + if (commitIsh === "" || commitIsh === "HEAD") { |
| 39 | + console.warn( |
| 40 | + 'Passing empty string or HEAD to commit-ish will get the "current" tag rather than "previous". For previous tag, try "HEAD~".' |
| 41 | + ); |
40 | 42 | }
|
| 43 | + commitIshOption = `'${commitIsh}'`; |
| 44 | + } |
41 | 45 |
|
42 |
| - var unshallowCmd = skipUnshallow ? '' : 'git fetch --prune --unshallow &&' |
| 46 | + var unshallowCmd = skipUnshallow ? "" : "git fetch --prune --unshallow &&"; |
43 | 47 |
|
44 |
| - // actions@checkout performs a shallow checkout. Need to unshallow for full tags access. |
45 |
| - var cmd = `${unshallowCmd} git describe --tags --abbrev=0 ${includeOption} ${excludeOption} ${commitIshOption}`.replace(/[ ]+/, ' ').trim(); |
46 |
| - console.log(`Executing: ${cmd}`); |
| 48 | + // actions@checkout performs a shallow checkout. Need to unshallow for full tags access. |
| 49 | + var cmd = `${unshallowCmd} git describe --tags ${abbrevOption} ${includeOption} ${excludeOption} ${commitIshOption}` |
| 50 | + .replace(/[ ]+/, " ") |
| 51 | + .trim(); |
| 52 | + console.log(`Executing: ${cmd}`); |
47 | 53 |
|
48 |
| - exec(cmd, (err, tag, stderr) => { |
49 |
| - if (err) { |
50 |
| - console.error(`Unable to find an earlier tag.\n${stderr}`); |
51 |
| - return process.exit(1); |
52 |
| - } |
53 |
| - console.log(`Outputting tag: ${tag.trim()}`) |
54 |
| - return setOutput('tag', tag.trim()); |
55 |
| - }); |
| 54 | + exec(cmd, (err, tag, stderr) => { |
| 55 | + if (err) { |
| 56 | + console.error(`Unable to find an earlier tag.\n${stderr}`); |
| 57 | + return process.exit(1); |
| 58 | + } |
| 59 | + console.log(`Outputting tag: ${tag.trim()}`); |
| 60 | + return setOutput("tag", tag.trim()); |
| 61 | + }); |
56 | 62 | } catch (error) {
|
57 |
| - core.setFailed(error.message); |
| 63 | + core.setFailed(error.message); |
58 | 64 | }
|
0 commit comments