Skip to content

Commit d153cfa

Browse files
authored
Merge pull request #50 from crazy-max/github-throw-runtime-token
github: throw if runtime token invalid
2 parents d09114e + c3aa7f2 commit d153cfa

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

__tests__/github.test.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,12 @@ describe('printActionsRuntimeTokenACs', () => {
130130
process.env = originalEnv;
131131
});
132132
it('empty', async () => {
133-
const warnSpy = jest.spyOn(core, 'warning');
134133
process.env.ACTIONS_RUNTIME_TOKEN = '';
135-
await GitHub.printActionsRuntimeTokenACs();
136-
expect(warnSpy).toHaveBeenCalledTimes(1);
137-
expect(warnSpy).toHaveBeenCalledWith(`ACTIONS_RUNTIME_TOKEN not set`);
134+
await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrowError(new Error('ACTIONS_RUNTIME_TOKEN not set'));
138135
});
139136
it('malformed', async () => {
140-
const warnSpy = jest.spyOn(core, 'warning');
141137
process.env.ACTIONS_RUNTIME_TOKEN = 'foo';
142-
await GitHub.printActionsRuntimeTokenACs();
143-
expect(warnSpy).toHaveBeenCalledTimes(1);
144-
expect(warnSpy).toHaveBeenCalledWith(`Cannot parse Actions Runtime Token: Invalid token specified: Cannot read properties of undefined (reading 'replace')`);
138+
await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrowError(new Error("Cannot parse GitHub Actions Runtime Token: Invalid token specified: Cannot read properties of undefined (reading 'replace')"));
145139
});
146140
it('refs/heads/master', async () => {
147141
const infoSpy = jest.spyOn(core, 'info');

src/github.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ export class GitHub {
5959
try {
6060
jwt = GitHub.actionsRuntimeToken;
6161
} catch (e) {
62-
core.warning(`Cannot parse Actions Runtime Token: ${e.message}`);
63-
return;
62+
throw new Error(`Cannot parse GitHub Actions Runtime Token: ${e.message}`);
6463
}
6564
if (!jwt) {
66-
core.warning(`ACTIONS_RUNTIME_TOKEN not set`);
67-
return;
65+
throw new Error(`ACTIONS_RUNTIME_TOKEN not set`);
6866
}
6967
try {
7068
<Array<GitHubActionsRuntimeTokenAC>>JSON.parse(`${jwt.ac}`).forEach(ac => {
@@ -85,7 +83,7 @@ export class GitHub {
8583
core.info(`${ac.Scope}: ${permission}`);
8684
});
8785
} catch (e) {
88-
core.warning(`Cannot parse Actions Runtime Token Access Controls: ${e.message}`);
86+
throw new Error(`Cannot parse GitHub Actions Runtime Token ACs: ${e.message}`);
8987
}
9088
}
9189
}

0 commit comments

Comments
 (0)