Skip to content

Commit 2fde67d

Browse files
committed
set commit url in github action output
1 parent ad258c0 commit 2fde67d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
description: 'Arguments to pass to the Dockerfile entrypoint.'
99
required: true
1010
default: '--help'
11+
outputs:
12+
commitUrl:
13+
description: 'The URL of the commit if that was created successfully.'
1114
runs:
1215
using: 'docker'
1316
image: 'Dockerfile'

github.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require("fs");
12
const yargs = require("yargs");
23
const CURRENT_VERSION = require("./package.json").version;
34

@@ -8,6 +9,13 @@ const {
89
checkIfBranchExists,
910
} = require("./index");
1011

12+
const appendLineToFile = (filename, line) => {
13+
fs.appendFile(filename, `${line}\n`, function (err) {
14+
if (err) throw err;
15+
console.log(`Saved data to ${filename}.`);
16+
});
17+
};
18+
1119
yargs
1220
.command(
1321
"commit",
@@ -83,7 +91,13 @@ yargs
8391
commitDescription
8492
)
8593
.then((response) => {
86-
console.log(JSON.stringify(response, null, 2));
94+
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+
}
87101
})
88102
.catch((error) => {
89103
console.error("Failed to create commit:", error.message);
@@ -120,7 +134,6 @@ yargs
120134
checkIfBranchExists(owner, repo, branch)
121135
.then((response) => {
122136
const n = response ? "a" : "no";
123-
//console.log(JSON.stringify(response, null, 2));
124137
console.log(
125138
`Repository ${owner}/${repo} has ${n} branch named '${branch}'`
126139
);

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ async function createCommitOnBranch(
178178
const response = await client
179179
.mutation(graphqlRequest.query, graphqlRequest.variables)
180180
.toPromise();
181-
return response;
181+
return {
182+
data: response,
183+
commitUrl: response?.data?.createCommitOnBranch?.commit?.url || null
184+
};
182185
} catch (error) {
183186
console.error(
184187
`Error while performing commit action via GraphQL API: ${error.message}`

0 commit comments

Comments
 (0)