|
1 |
| -import * as core from '@actions/core' |
2 |
| -import * as util from 'util' |
3 |
| -import * as child_process from 'child_process' |
| 1 | +import * as core from '@actions/core'; |
| 2 | +import * as util from 'util'; |
| 3 | +import * as child_process from 'child_process'; |
4 | 4 |
|
5 | 5 | class GitArgs {
|
6 |
| - readonly command: string |
| 6 | + readonly command: string; |
7 | 7 |
|
8 | 8 | constructor(
|
9 | 9 | readonly ref: string,
|
10 | 10 | readonly directory: string
|
11 | 11 | ) {
|
12 |
| - core.debug(`GitArgs.ref: ${ref}`) |
13 |
| - core.debug(`GitArgs.directory: ${directory}`) |
| 12 | + core.debug(`GitArgs.ref: ${ref}`); |
| 13 | + core.debug(`GitArgs.directory: ${directory}`); |
14 | 14 |
|
15 |
| - this.command = `git -C ${this.directory}` |
16 |
| - core.debug(`GitArgs.command: ${this.command}`) |
| 15 | + this.command = `git -C ${this.directory}`; |
| 16 | + core.debug(`GitArgs.command: ${this.command}`); |
17 | 17 | }
|
18 | 18 | }
|
19 | 19 |
|
20 | 20 | async function exec(command: string) {
|
21 |
| - core.debug(`executing: ${command}`) |
| 21 | + core.debug(`executing: ${command}`); |
22 | 22 |
|
23 |
| - const { stdout, stderr } = await util.promisify(child_process.exec)(command) |
24 |
| - if (stderr) console.error(stderr) |
25 |
| - return stdout |
| 23 | + const {stdout, stderr} = await util.promisify(child_process.exec)(command); |
| 24 | + if (stderr) console.error(stderr); |
| 25 | + return stdout; |
26 | 26 | }
|
27 | 27 |
|
28 | 28 | function annotatedTag(message: string, git: GitArgs) {
|
29 |
| - core.info('Creating annotated tag...') |
30 |
| - return exec(`${git.command} tag -a -f -m "${message}" ${git.ref}`) |
| 29 | + core.info('Creating annotated tag...'); |
| 30 | + return exec(`${git.command} tag -a -f -m "${message}" ${git.ref}`); |
31 | 31 | }
|
32 | 32 |
|
33 | 33 | function lightweightTag(git: GitArgs) {
|
34 |
| - core.info('Creating lightweight tag...') |
35 |
| - return exec(`${git.command} tag -f ${git.ref}`) |
| 34 | + core.info('Creating lightweight tag...'); |
| 35 | + return exec(`${git.command} tag -f ${git.ref}`); |
36 | 36 | }
|
37 | 37 |
|
38 | 38 | function forceBranch(git: GitArgs) {
|
39 |
| - core.info('Updating branch...') |
40 |
| - return exec(`${git.command} branch -f ${git.ref}`) |
| 39 | + core.info('Updating branch...'); |
| 40 | + return exec(`${git.command} branch -f ${git.ref}`); |
41 | 41 | }
|
42 | 42 |
|
43 | 43 | async function setupUser(git: GitArgs) {
|
44 |
| - core.info('Setting up git user...') |
| 44 | + core.info('Setting up git user...'); |
45 | 45 |
|
46 |
| - const { GITHUB_ACTOR } = process.env |
47 |
| - core.debug(`GITHUB_ACTOR: ${GITHUB_ACTOR}`) |
| 46 | + const {GITHUB_ACTOR} = process.env; |
| 47 | + core.debug(`GITHUB_ACTOR: ${GITHUB_ACTOR}`); |
48 | 48 |
|
49 |
| - await exec(`${git.command} config user.name "${GITHUB_ACTOR}"`) |
| 49 | + await exec(`${git.command} config user.name "${GITHUB_ACTOR}"`); |
50 | 50 | await exec(
|
51 | 51 | `${git.command} config user.email "${GITHUB_ACTOR}@users.noreply.github.com"`
|
52 |
| - ) |
| 52 | + ); |
53 | 53 | }
|
54 | 54 |
|
55 | 55 | async function run() {
|
56 | 56 | try {
|
57 | 57 | const git = new GitArgs(
|
58 | 58 | core.getInput('ref') || core.getInput('tag-name') || 'latest',
|
59 | 59 | core.getInput('git-directory')
|
60 |
| - ) |
| 60 | + ); |
61 | 61 |
|
62 |
| - const branch = core.getBooleanInput('force-branch', { required: true }) |
63 |
| - const message = core.getInput('description') |
| 62 | + const branch = core.getBooleanInput('force-branch', {required: true}); |
| 63 | + const message = core.getInput('description'); |
64 | 64 |
|
65 | 65 | if (branch && message)
|
66 | 66 | core.warning(
|
67 | 67 | "You can't set a message when updating a branch, the message will be ignored."
|
68 |
| - ) |
| 68 | + ); |
69 | 69 |
|
70 |
| - core.debug(`branch: ${branch}`) |
71 |
| - core.debug(`message: ${message}`) |
| 70 | + core.debug(`branch: ${branch}`); |
| 71 | + core.debug(`message: ${message}`); |
72 | 72 |
|
73 |
| - core.info(`Running git commands within ${git.directory}`) |
74 |
| - core.info(`Using '${git.ref}' as tag name.`) |
| 73 | + core.info(`Running git commands within ${git.directory}`); |
| 74 | + core.info(`Using '${git.ref}' as tag name.`); |
75 | 75 |
|
76 |
| - await setupUser(git) |
| 76 | + await setupUser(git); |
77 | 77 |
|
78 |
| - if (branch) await forceBranch(git) |
79 |
| - else if (message) await annotatedTag(message, git) |
80 |
| - else await lightweightTag(git) |
| 78 | + if (branch) await forceBranch(git); |
| 79 | + else if (message) await annotatedTag(message, git); |
| 80 | + else await lightweightTag(git); |
81 | 81 |
|
82 |
| - if (branch) core.info('Force-pushing updated branch to repo...') |
83 |
| - else core.info('Pushing updated tag to repo...') |
84 |
| - return await exec(`${git.command} push --force origin ${git.ref}`) |
| 82 | + if (branch) core.info('Force-pushing updated branch to repo...'); |
| 83 | + else core.info('Pushing updated tag to repo...'); |
| 84 | + return await exec(`${git.command} push --force origin ${git.ref}`); |
85 | 85 | } catch (error) {
|
86 |
| - core.setFailed(error instanceof Error ? error.message : error) |
| 86 | + core.setFailed(error instanceof Error ? error.message : error); |
87 | 87 | }
|
88 | 88 | }
|
89 | 89 |
|
90 |
| -run() |
| 90 | +run(); |
0 commit comments