mirror of
https://code.forgejo.org/docker/actions-toolkit.git
synced 2025-06-25 07:08:22 -04:00
github: printActionsRuntimeToken
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
40e9a15129
commit
ad59af8cf2
2 changed files with 41 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
||||||
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
|
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import {GitHub} from '../src/github';
|
import {GitHub} from '../src/github';
|
||||||
import {GitHubRepo} from '../src/types/github';
|
import {GitHubRepo} from '../src/types/github';
|
||||||
|
@ -110,3 +111,33 @@ describe('actionsRuntimeToken', () => {
|
||||||
expect(runtimeToken.iss).toEqual('vstoken.actions.githubusercontent.com');
|
expect(runtimeToken.iss).toEqual('vstoken.actions.githubusercontent.com');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('printActionsRuntimeToken', () => {
|
||||||
|
const originalEnv = process.env;
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
process.env = {
|
||||||
|
...originalEnv
|
||||||
|
};
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
process.env = originalEnv;
|
||||||
|
});
|
||||||
|
it('empty', async () => {
|
||||||
|
const execSpy = jest.spyOn(core, 'info');
|
||||||
|
process.env.ACTIONS_RUNTIME_TOKEN = '';
|
||||||
|
GitHub.printActionsRuntimeToken();
|
||||||
|
expect(execSpy).toHaveBeenCalledWith(`ACTIONS_RUNTIME_TOKEN not set`);
|
||||||
|
});
|
||||||
|
it('prints ac', () => {
|
||||||
|
const execSpy = jest.spyOn(core, 'info');
|
||||||
|
process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(__dirname, 'fixtures', 'runtimeToken.txt')).toString().trim();
|
||||||
|
GitHub.printActionsRuntimeToken();
|
||||||
|
expect(execSpy).toHaveBeenCalledWith(`[
|
||||||
|
{
|
||||||
|
"Scope": "refs/heads/master",
|
||||||
|
"Permission": 3
|
||||||
|
}
|
||||||
|
]`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {GitHub as Octokit} from '@actions/github/lib/utils';
|
import {GitHub as Octokit} from '@actions/github/lib/utils';
|
||||||
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
import {Context} from '@actions/github/lib/context';
|
import {Context} from '@actions/github/lib/context';
|
||||||
import jwt_decode from 'jwt-decode';
|
import jwt_decode from 'jwt-decode';
|
||||||
|
@ -52,4 +53,13 @@ export class GitHub {
|
||||||
const token = process.env['ACTIONS_RUNTIME_TOKEN'] || '';
|
const token = process.env['ACTIONS_RUNTIME_TOKEN'] || '';
|
||||||
return token ? jwt_decode<GitHubActionsRuntimeToken>(token) : {};
|
return token ? jwt_decode<GitHubActionsRuntimeToken>(token) : {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async printActionsRuntimeToken() {
|
||||||
|
const actionsRuntimeToken = process.env['ACTIONS_RUNTIME_TOKEN'];
|
||||||
|
if (actionsRuntimeToken) {
|
||||||
|
core.info(JSON.stringify(JSON.parse(GitHub.actionsRuntimeToken.ac as string), undefined, 2));
|
||||||
|
} else {
|
||||||
|
core.info(`ACTIONS_RUNTIME_TOKEN not set`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue