|
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 abbrev = getInput("abbrev"); |
22 | | - const skipUnshallow = getInput("skip-unshallow") === "true"; |
| 18 | + const include = getInput('include'); |
| 19 | + const exclude = getInput('exclude'); |
| 20 | + const commitIsh = getInput('commit-ish'); |
| 21 | + const skipUnshallow = getInput('skip-unshallow') === 'true'; |
| 22 | + const abbrev = getInput("abbrev"); |
23 | 23 |
|
24 | | - var includeOption = ""; |
25 | | - var excludeOption = ""; |
26 | | - var commitIshOption = ""; |
27 | | - var abbrevOption = ""; |
| 24 | + var includeOption = ''; |
| 25 | + var excludeOption = ''; |
| 26 | + var commitIshOption = ''; |
| 27 | + var abbrevOption = ''; |
28 | 28 |
|
29 | | - if (typeof include === "string" && include.length > 0) { |
30 | | - includeOption = `--match '${include}'`; |
31 | | - } |
| 29 | + if (typeof include === 'string' && include.length > 0) { |
| 30 | + includeOption = `--match '${include}'`; |
| 31 | + } |
32 | 32 |
|
33 | | - if (typeof exclude === "string" && exclude.length > 0) { |
34 | | - excludeOption = `--exclude '${exclude}'`; |
35 | | - } |
| 33 | + if (typeof exclude === 'string' && exclude.length > 0) { |
| 34 | + excludeOption = `--exclude '${exclude}'`; |
| 35 | + } |
36 | 36 |
|
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 | | - ); |
| 37 | + if (typeof commitIsh === 'string') { |
| 38 | + if (commitIsh === '' || commitIsh === 'HEAD') { |
| 39 | + console.warn('Passing empty string or HEAD to commit-ish will get the "current" tag rather than "previous". For previous tag, try "HEAD~".'); |
| 40 | + } |
| 41 | + commitIshOption = `'${commitIsh}'`; |
42 | 42 | } |
43 | | - commitIshOption = `'${commitIsh}'`; |
44 | | - } |
45 | 43 |
|
46 | | - if (abbrev !== "false") { |
47 | | - abbrevOption = `--abbrev=${abbrev}`; |
48 | | - } |
| 44 | + if (abbrev !== 'false') { |
| 45 | + abbrevOption = `--abbrev=${abbrev}`; |
| 46 | + } |
49 | 47 |
|
50 | | - var unshallowCmd = skipUnshallow ? "" : "git fetch --prune --unshallow &&"; |
| 48 | + var unshallowCmd = skipUnshallow ? '' : 'git fetch --prune --unshallow &&' |
51 | 49 |
|
52 | | - // actions@checkout performs a shallow checkout. Need to unshallow for full tags access. |
53 | | - var cmd = `${unshallowCmd} git describe --tags ${abbrevOption} ${includeOption} ${excludeOption} ${commitIshOption}` |
54 | | - .replace(/[ ]+/, " ") |
55 | | - .trim(); |
56 | | - console.log(`Executing: ${cmd}`); |
| 50 | + // actions@checkout performs a shallow checkout. Need to unshallow for full tags access. |
| 51 | + var cmd = `${unshallowCmd} git describe --tags ${abbrevOption} ${includeOption} ${excludeOption} ${commitIshOption}`.replace(/[ ]+/, ' ').trim(); |
| 52 | + console.log(`Executing: ${cmd}`); |
57 | 53 |
|
58 | | - exec(cmd, (err, tag, stderr) => { |
59 | | - if (err) { |
60 | | - console.error(`Unable to find an earlier tag.\n${stderr}`); |
61 | | - return process.exit(1); |
62 | | - } |
63 | | - console.log(`Outputting tag: ${tag.trim()}`); |
64 | | - return setOutput("tag", tag.trim()); |
65 | | - }); |
| 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 | + }); |
66 | 62 | } catch (error) { |
67 | | - core.setFailed(error.message); |
| 63 | + core.setFailed(error.message); |
68 | 64 | } |
0 commit comments