Skip to content

Commit 9e3edc5

Browse files
authored
Update github action to set tag (#9)
* Update github action to set tag * tag -> head-tag
1 parent 3eeb271 commit 9e3edc5

4 files changed

Lines changed: 41 additions & 15 deletions

File tree

build/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,7 +3999,7 @@ async function execCommand(command, args, options = {}, logError = true) {
39993999
return false;
40004000
}
40014001
}
4002-
async function runAction(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha) {
4002+
async function runAction(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName) {
40034003
const failOnCheckError = standardsFail === "true";
40044004
const valid = verifyInput(opticToken, eventName, owner, repo);
40054005
if (!valid) {
@@ -4038,7 +4038,8 @@ async function runAction(opticToken, githubToken, additionalArgs, standardsFail,
40384038
core.error("Unable to determine base for comparison.");
40394039
return 1;
40404040
}
4041-
const comparisonRun = await diffAll(opticToken, from, additionalArgs);
4041+
const headTag = refName ? `gitbranch:${refName}` : undefined;
4042+
const comparisonRun = await diffAll(opticToken, from, additionalArgs, headTag);
40424043
if (eventName === "pull_request") {
40434044
const commentResult = await prComment(githubToken, owner || "", repo || "", pr || "", sha || "");
40444045
if (!commentResult) {
@@ -4096,14 +4097,15 @@ async function deepen() {
40964097
}
40974098
return true;
40984099
}
4099-
async function diffAll(token, from, additionalArgs) {
4100+
async function diffAll(token, from, additionalArgs, headTag) {
41004101
core.info("Running Optic diff-all");
41014102
return execCommand("optic", [
41024103
"diff-all",
41034104
"--compare-from",
41044105
from,
41054106
"--check",
41064107
"--upload",
4108+
...(headTag ? ["--head-tag", headTag] : []),
41074109
...(additionalArgs ? [additionalArgs] : []),
41084110
], {
41094111
env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }),
@@ -4171,10 +4173,11 @@ const additionalArgs = core.getInput("additional_args");
41714173
const eventName = process.env.GITHUB_EVENT_NAME;
41724174
const headRef = process.env.GITHUB_REF;
41734175
const baseRef = process.env.GITHUB_BASE_REF;
4176+
const refName = process.env.GITHUB_REF_NAME;
41744177
const owner = process.env.GITHUB_REPOSITORY_OWNER;
41754178
const repo = (_a = process.env.GITHUB_REPOSITORY) === null || _a === void 0 ? void 0 : _a.split("/")[1];
41764179
const sha = process.env.GITHUB_SHA;
4177-
(0, action_1.runAction)(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha)
4180+
(0, action_1.runAction)(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName)
41784181
.then((exitCode) => {
41794182
return process.exit(exitCode);
41804183
})

src/__tests__/action.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test("invalid input", async () => {
1414
undefined,
1515
"owner",
1616
"repo",
17-
"abc123"
17+
"abc123",
18+
""
1819
);
1920
expect(exitCode).toBe(1);
2021
});
@@ -32,7 +33,8 @@ test("failed install", async () => {
3233
undefined,
3334
"owner",
3435
"repo",
35-
"abc123"
36+
"abc123",
37+
"main"
3638
);
3739
expect(exitCode).toBe(1);
3840
assertFailedInstall();
@@ -54,7 +56,8 @@ test("pull_request event", async () => {
5456
"main",
5557
"owner",
5658
"repo",
57-
"abc123"
59+
"abc123",
60+
"main"
5861
);
5962
expect(exitCode).toBe(0);
6063
assertInstall();
@@ -78,7 +81,8 @@ test("push event", async () => {
7881
undefined,
7982
"owner",
8083
"repo",
81-
"abc123"
84+
"abc123",
85+
"main"
8286
);
8387
expect(exitCode).toBe(0);
8488
assertInstall();
@@ -103,7 +107,8 @@ test("push event with additional-args", async () => {
103107
undefined,
104108
"owner",
105109
"repo",
106-
"abc123"
110+
"abc123",
111+
"main"
107112
);
108113
expect(exitCode).toBe(0);
109114
assertInstall();
@@ -126,7 +131,8 @@ test("push event with standards failure and standards_fail set to true", async (
126131
undefined,
127132
"owner",
128133
"repo",
129-
"abc123"
134+
"abc123",
135+
"main"
130136
);
131137
expect(exitCode).toBe(1);
132138
assertInstall();
@@ -149,7 +155,8 @@ test("push event with standards failure but standards_fail set to false", async
149155
undefined,
150156
"owner",
151157
"repo",
152-
"abc123"
158+
"abc123",
159+
"main"
153160
);
154161
expect(exitCode).toBe(0);
155162
assertInstall();
@@ -219,6 +226,8 @@ function mockDiffAll(
219226
from,
220227
"--check",
221228
"--upload",
229+
"--head-tag",
230+
"gitbranch:main",
222231
...additionalArgs,
223232
],
224233
expect.objectContaining({

src/action.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export async function runAction(
2929
baseRef: string | undefined,
3030
owner: string | undefined,
3131
repo: string | undefined,
32-
sha: string | undefined
32+
sha: string | undefined,
33+
refName: string | undefined
3334
): Promise<number> {
3435
const failOnCheckError = standardsFail === "true";
3536

@@ -76,7 +77,16 @@ export async function runAction(
7677
return 1;
7778
}
7879

79-
const comparisonRun = await diffAll(opticToken, from, additionalArgs);
80+
const headTag: string | undefined = refName
81+
? `gitbranch:${refName}`
82+
: undefined;
83+
84+
const comparisonRun = await diffAll(
85+
opticToken,
86+
from,
87+
additionalArgs,
88+
headTag
89+
);
8090

8191
if (eventName === "pull_request") {
8292
const commentResult = await prComment(
@@ -167,7 +177,8 @@ async function deepen(): Promise<boolean> {
167177
async function diffAll(
168178
token: string,
169179
from: string,
170-
additionalArgs: string | undefined
180+
additionalArgs: string | undefined,
181+
headTag: string | undefined
171182
): Promise<boolean> {
172183
core.info("Running Optic diff-all");
173184

@@ -179,6 +190,7 @@ async function diffAll(
179190
from,
180191
"--check",
181192
"--upload",
193+
...(headTag ? ["--head-tag", headTag] : []),
182194
...(additionalArgs ? [additionalArgs] : []),
183195
],
184196
{

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const additionalArgs = core.getInput("additional_args");
99
const eventName = process.env.GITHUB_EVENT_NAME;
1010
const headRef = process.env.GITHUB_REF;
1111
const baseRef = process.env.GITHUB_BASE_REF;
12+
const refName = process.env.GITHUB_REF_NAME;
1213
const owner = process.env.GITHUB_REPOSITORY_OWNER;
1314
const repo = process.env.GITHUB_REPOSITORY?.split("/")[1];
1415
const sha = process.env.GITHUB_SHA;
@@ -23,7 +24,8 @@ runAction(
2324
baseRef,
2425
owner,
2526
repo,
26-
sha
27+
sha,
28+
refName
2729
)
2830
.then((exitCode) => {
2931
return process.exit(exitCode);

0 commit comments

Comments
 (0)