Skip to content

Commit ad45523

Browse files
committed
better content to github output
1 parent 2fde67d commit ad45523

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ inputs:
99
required: true
1010
default: '--help'
1111
outputs:
12+
command:
13+
description: 'The command that was executed.'
1214
commitUrl:
1315
description: 'The URL of the commit if that was created successfully.'
16+
hasBranch:
17+
description: 'Whether the branch already exists.'
1418
runs:
1519
using: 'docker'
1620
image: 'Dockerfile'

github.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ const {
99
checkIfBranchExists,
1010
} = require("./index");
1111

12+
const commitCommand = "commit";
13+
const branchCommand = "branch"
14+
1215
const appendLineToFile = (filename, line) => {
1316
fs.appendFile(filename, `${line}\n`, function (err) {
1417
if (err) throw err;
1518
console.log(`Saved data to ${filename}.`);
1619
});
1720
};
1821

22+
const writeResultToGithubOutputFile = (results) => {
23+
if (!!process.env.GITHUB_OUTPUT) {
24+
let line = "";
25+
results.forEach((result) => {
26+
line += `${result.label}=${result.value}\n`;
27+
});
28+
appendLineToFile(process.env.GITHUB_OUTPUT, line);
29+
}
30+
};
31+
1932
yargs
2033
.command(
21-
"commit",
34+
commitCommand,
2235
"Create a commit on a branch",
2336
(yargs) => {
2437
yargs
@@ -92,20 +105,24 @@ yargs
92105
)
93106
.then((response) => {
94107
console.log(`Commit created: ${response.commitUrl}`);
95-
if (!!process.env.GITHUB_OUTPUT) {
96-
appendLineToFile(
97-
process.env.GITHUB_OUTPUT,
98-
`commitUrl=${response.commitUrl}`
99-
);
100-
}
108+
writeResultToGithubOutputFile([
109+
{
110+
label: "command",
111+
value: commitCommand,
112+
},
113+
{
114+
label: "commitUrl",
115+
value: response.commitUrl,
116+
},
117+
]);
101118
})
102119
.catch((error) => {
103120
console.error("Failed to create commit:", error.message);
104121
});
105122
}
106123
)
107124
.command(
108-
"branch",
125+
branchCommand,
109126
"Check if a branch exists",
110127
(yargs) => {
111128
yargs
@@ -137,6 +154,16 @@ yargs
137154
console.log(
138155
`Repository ${owner}/${repo} has ${n} branch named '${branch}'`
139156
);
157+
writeResultToGithubOutputFile([
158+
{
159+
label: "command",
160+
value: branchCommand,
161+
},
162+
{
163+
label: "hasBranch",
164+
value: n.toString(),
165+
},
166+
]);
140167
})
141168
.catch((error) => {
142169
console.error("Failed to check if branch exists:", error.message);

0 commit comments

Comments
 (0)