Skip to content

Commit

Permalink
#34604: Added action mode in the artifact title
Browse files Browse the repository at this point in the history
  • Loading branch information
janssen-tiobe committed Sep 24, 2024
1 parent 0d4d33d commit 920f934
Show file tree
Hide file tree
Showing 11 changed files with 7,090 additions and 6,861 deletions.
993 changes: 601 additions & 392 deletions dist/index.js

Large diffs are not rendered by default.

12,860 changes: 6,438 additions & 6,422 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/configuration/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ export class GithubConfig {
this.commitSha = context.sha;
this.event = this.getGithubEvent();
this.job = context.job;
this.action = context.action;
this.action = context.action.replace('__tiobe_', '');

/**
* Construct the id to use for storing tmpdirs. The action name will
* be appended with a number if there are multiple runs within a job.
* Example: 10897710852_2_TICSQServer__tiobe_tics-github-action_2
* Example: 10897710852_2_TICSQServer_tics-github-action_2
*
* According to the documentation:
* If you use the same script or action more than once in the same job, the name will
* include a suffix that consists of the sequence number preceded by an underscore.
* https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables
*/
const runAttempt = process.env.GITHUB_RUN_ATTEMPT ?? '0';
this.id = `${context.runId.toString()}_${runAttempt}_${this.job}${this.action}`;
this.id = `${context.runId.toString()}_${runAttempt}_${this.job}_${this.action}`;
this.pullRequestNumber = this.getPullRequestNumber();
this.debugger = isDebug();

Expand Down
9 changes: 7 additions & 2 deletions src/github/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { join } from 'canonical-path';

import { logger } from '../helper/logger';
import { handleOctokitError } from '../helper/response';
import { githubConfig, ticsCli } from '../configuration/config';
import { githubConfig, ticsCli, ticsConfig } from '../configuration/config';

export async function uploadArtifact(): Promise<void> {
const artifactClient = create();
Expand All @@ -15,7 +15,12 @@ export async function uploadArtifact(): Promise<void> {
logger.header('Uploading artifact');
const tmpdir = getTmpDir() + '/ticstmpdir';
logger.info(`Logs gotten from ${tmpdir}`);
const response = await artifactClient.uploadArtifact(`${githubConfig.job}${githubConfig.action}_ticstmpdir`, getFilesInFolder(tmpdir), tmpdir);
const response = await artifactClient.uploadArtifact(
// Example TICS_tics-github-action_2_qserver_ticstmpdir
`${githubConfig.job}_${githubConfig.action}_${ticsConfig.mode}_ticstmpdir`,
getFilesInFolder(tmpdir),
tmpdir
);

if (response.failedItems.length > 0) {
logger.debug(`Failed to upload file(s): ${response.failedItems.join(', ')}`);
Expand Down
6 changes: 3 additions & 3 deletions test/.setup/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const githubConfigMock: {
commitSha: 'sha-128',
event: GithubEvent.PUSH,
job: 'TICS',
action: '__tiobe_tics-github-action',
id: '123_TICS_1__tiobe_tics-github-action',
action: 'tics-github-action',
id: '123_TICS_1_tics-github-action',
pullRequestNumber: 1,
debugger: false
};
Expand Down Expand Up @@ -129,7 +129,7 @@ export const contextMock: {
| undefined;
};
} = {
action: '__tiobe_tics-github-action',
action: 'tics-github-action',
apiUrl: 'api.github.com',
repo: {
repo: 'tics-github-action',
Expand Down
3 changes: 3 additions & 0 deletions test/integration/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('pullRequestNumber', () => {
jest.mock('@actions/github', () => {
return {
context: {
action: '_tics-github-action',
payload: {
pull_request: { number: 1 }
},
Expand All @@ -45,6 +46,7 @@ describe('pullRequestNumber', () => {
jest.mock('@actions/github', () => {
return {
context: {
action: '_tics-github-action',
payload: {
pull_request: undefined
},
Expand All @@ -71,6 +73,7 @@ describe('pullRequestNumber', () => {
jest.mock('@actions/github', () => {
return {
context: {
action: '_tics-github-action',
payload: {
pull_request: undefined
},
Expand Down
1 change: 1 addition & 0 deletions test/integration/httpclient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ process.env['http_proxy'] = proxyUrl;

// set required inputs
process.env.GITHUB_REPOSITORY = 'owner/repo';
process.env.GITHUB_ACTION = '_tics-github-action';
process.env.INPUT_GITHUBTOKEN = 'token';
process.env.INPUT_MODE = 'client';
process.env.INPUT_PROJECTNAME = 'tics-github-action';
Expand Down
1 change: 1 addition & 0 deletions test/integration/octokit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ process.env['http_proxy'] = proxyUrl;
// set required inputs
process.env.GITHUB_REPOSITORY = 'owner/repo';
process.env.GITHUB_API_URL = 'https://api.github.com';
process.env.GITHUB_ACTION = '_tics-github-action';
process.env.INPUT_MODE = 'client';
process.env.INPUT_PROJECTNAME = 'tics-github-action';
process.env.INPUT_VIEWERURL = 'http://localhost/tiobeweb/TICS/api/cfg?name=default';
Expand Down
4 changes: 2 additions & 2 deletions test/unit/configuration/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('GitHub Configuration', () => {
});

test('Should set variables taken from context', () => {
contextMock.action = '__tiobe_tics-github-action';
contextMock.action = 'tics-github-action';
contextMock.apiUrl = 'api.github.com';
contextMock.repo = { repo: 'tics-github-action', owner: 'tiobe' };
contextMock.sha = 'sha-128';
Expand All @@ -41,7 +41,7 @@ describe('GitHub Configuration', () => {
reponame: 'tics-github-action',
commitSha: 'sha-128',
event: { name: 'pull_request', isPullRequest: true },
id: `123_1_TICS__tiobe_tics-github-action`,
id: `123_1_TICS_tics-github-action`,
pullRequestNumber: 1
});
});
Expand Down
50 changes: 22 additions & 28 deletions test/unit/github/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,40 @@ describe('Tempdir test', () => {
githubConfigMock.debugger = true;
const tmpdir = getTmpDir();

expect(tmpdir).toStrictEqual('/tmp/tics/123_TICS_1__tiobe_tics-github-action');
expect(tmpdir).toStrictEqual('/tmp/tics/123_TICS_1_tics-github-action');
});

it('Should return empty if variable is set', () => {
ticsCliMock.tmpdir = 'something/else';
const tmpdir = getTmpDir();

expect(tmpdir).toStrictEqual('something/else/123_TICS_1__tiobe_tics-github-action');
expect(tmpdir).toStrictEqual('something/else/123_TICS_1_tics-github-action');
});
});

describe('Artifacts test', () => {
it('Should upload logfile to tmpdir', async () => {
ticsCliMock.tmpdir = '/tmp';

jest
.spyOn(fs, 'readdirSync')
.mockReturnValueOnce([new MockDirent(true, 'file.log', '/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log')]);
jest.spyOn(fs, 'readdirSync').mockReturnValueOnce([new MockDirent(true, 'file.log', '/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log')]);
const mockArtifactClient = new MockArtifactClient([]);
jest.spyOn(artifact, 'create').mockReturnValue(mockArtifactClient);
const uploadSpy = jest.spyOn(mockArtifactClient, 'uploadArtifact');

await uploadArtifact();

expect(uploadSpy).toHaveBeenCalledWith(
'TICS__tiobe_tics-github-action_ticstmpdir',
['/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log'],
'/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir'
'TICS_tics-github-action_client_ticstmpdir',
['/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log'],
'/tmp/123_TICS_1_tics-github-action/ticstmpdir'
);
});

it('Should upload logdir to tmpdir', async () => {
ticsCliMock.tmpdir = '/tmp';

const direntOne = [new MockDirent(false, 'tics', '/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/tics')];
const direntTwo = [new MockDirent(true, 'file.log', '/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/tics/file.log')];
const direntOne = [new MockDirent(false, 'tics', '/tmp/123_TICS_1_tics-github-action/ticstmpdir/tics')];
const direntTwo = [new MockDirent(true, 'file.log', '/tmp/123_TICS_1_tics-github-action/ticstmpdir/tics/file.log')];

jest.spyOn(fs, 'readdirSync').mockReturnValueOnce(direntOne);
jest.spyOn(fs, 'readdirSync').mockReturnValueOnce(direntTwo);
Expand All @@ -62,50 +60,46 @@ describe('Artifacts test', () => {
await uploadArtifact();

expect(uploadSpy).toHaveBeenCalledWith(
'TICS__tiobe_tics-github-action_ticstmpdir',
['/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/tics/file.log'],
'/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir'
'TICS_tics-github-action_client_ticstmpdir',
['/tmp/123_TICS_1_tics-github-action/ticstmpdir/tics/file.log'],
'/tmp/123_TICS_1_tics-github-action/ticstmpdir'
);
});

it('Should call debug logger on failing to upload logfile', async () => {
ticsCliMock.tmpdir = '/tmp';

jest
.spyOn(fs, 'readdirSync')
.mockReturnValueOnce([new MockDirent(true, 'file.log', '/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log')]);
const mockArtifactClient = new MockArtifactClient(['/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log']);
jest.spyOn(fs, 'readdirSync').mockReturnValueOnce([new MockDirent(true, 'file.log', '/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log')]);
const mockArtifactClient = new MockArtifactClient(['/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log']);
jest.spyOn(artifact, 'create').mockReturnValue(mockArtifactClient);
const uploadSpy = jest.spyOn(mockArtifactClient, 'uploadArtifact');
const loggerSpy = jest.spyOn(logger, 'debug');

await uploadArtifact();

expect(uploadSpy).toHaveBeenCalledWith(
'TICS__tiobe_tics-github-action_ticstmpdir',
['/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log'],
'/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir'
'TICS_tics-github-action_client_ticstmpdir',
['/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log'],
'/tmp/123_TICS_1_tics-github-action/ticstmpdir'
);
expect(loggerSpy).toHaveBeenCalledWith(`Failed to upload file(s): /tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log`);
expect(loggerSpy).toHaveBeenCalledWith(`Failed to upload file(s): /tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log`);
});

it('Should call debug logger on upload throwing an error', async () => {
ticsCliMock.tmpdir = '/tmp';

jest
.spyOn(fs, 'readdirSync')
.mockReturnValueOnce([new MockDirent(true, 'file.log', '/tmp/123_TICS__tiobe_tics-github-action/ticstmpdir/file.log')]);
const mockArtifactClient = new MockArtifactClient(['/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log']);
jest.spyOn(fs, 'readdirSync').mockReturnValueOnce([new MockDirent(true, 'file.log', '/tmp/123_TICS_tics-github-action/ticstmpdir/file.log')]);
const mockArtifactClient = new MockArtifactClient(['/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log']);
jest.spyOn(artifact, 'create').mockReturnValue(mockArtifactClient);
const uploadSpy = jest.spyOn(mockArtifactClient, 'uploadArtifact').mockRejectedValue(Error('connection issues'));
const loggerSpy = jest.spyOn(logger, 'debug');

await uploadArtifact();

expect(uploadSpy).toHaveBeenCalledWith(
'TICS__tiobe_tics-github-action_ticstmpdir',
['/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir/file.log'],
'/tmp/123_TICS_1__tiobe_tics-github-action/ticstmpdir'
'TICS_tics-github-action_client_ticstmpdir',
['/tmp/123_TICS_1_tics-github-action/ticstmpdir/file.log'],
'/tmp/123_TICS_1_tics-github-action/ticstmpdir'
);
expect(loggerSpy).toHaveBeenCalledWith(`Failed to upload artifact: connection issues`);
});
Expand Down
18 changes: 9 additions & 9 deletions test/unit/tics/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('test multiple types of configuration', () => {
expect(response.statusCode).toEqual(0);
expect(response.completed).toEqual(true);
expect(spy).toHaveBeenCalledWith(
"/bin/bash -c \"TICS='http://base.com/tiobeweb/TICS/api/cfg?name=default'; TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action' -log 9\"",
"/bin/bash -c \"TICS='http://base.com/tiobeweb/TICS/api/cfg?name=default'; TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action' -log 9\"",
[],
{
listeners: { stderr: expect.any(Function), stdout: expect.any(Function) },
Expand All @@ -126,7 +126,7 @@ describe('test multiple types of configuration', () => {
expect(response.statusCode).toEqual(0);
expect(response.completed).toEqual(true);
expect(spy).toHaveBeenCalledWith(
"powershell \"$env:TICS='http://base.com/tiobeweb/TICS/api/cfg?name=default'; if ($?) {TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action' -log 9}\"",
"powershell \"$env:TICS='http://base.com/tiobeweb/TICS/api/cfg?name=default'; if ($?) {TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action' -log 9}\"",
[],
{
listeners: { stderr: expect.any(Function), stdout: expect.any(Function) },
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('test multiple types of configuration', () => {
expect(response.statusCode).toEqual(0);
expect(response.completed).toEqual(true);
expect(spy).toHaveBeenCalledWith(
"/bin/bash -c \"source <(curl --silent --insecure 'http://base.com/tiobeweb/TICS/install-url') && TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action' -log 9\"",
"/bin/bash -c \"source <(curl --silent --insecure 'http://base.com/tiobeweb/TICS/install-url') && TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action' -log 9\"",
[],
{
listeners: { stderr: expect.any(Function), stdout: expect.any(Function) },
Expand All @@ -181,7 +181,7 @@ describe('test multiple types of configuration', () => {
expect(response.statusCode).toEqual(0);
expect(response.completed).toEqual(true);
expect(spy).toHaveBeenCalledWith(
"powershell \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('http://base.com/tiobeweb/TICS/install-url')); if ($?) {TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action' -log 9}\"",
"powershell \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('http://base.com/tiobeweb/TICS/install-url')); if ($?) {TICS -ide github '@/path/to' -viewer -project 'project' -cdtoken token -calc CS -tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action' -log 9}\"",
[],
{
listeners: { stderr: expect.any(Function), stdout: expect.any(Function) },
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('test multiple types of configuration', () => {
expect(response.statusCode).toEqual(0);
expect(response.completed).toEqual(true);
expect(spy).toHaveBeenCalledWith(
"powershell \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; iex ((New-Object System.Net.WebClient).DownloadString('http://base.com/tiobeweb/TICS/install-url')); if ($?) {TICS -ide github '@/path/to/file.txt' -viewer -project 'project' -cdtoken token -codetype TESTCODE -calc CS -nocalc CW -norecalc CD -recalc CY -tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action'}\"",
"powershell \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; iex ((New-Object System.Net.WebClient).DownloadString('http://base.com/tiobeweb/TICS/install-url')); if ($?) {TICS -ide github '@/path/to/file.txt' -viewer -project 'project' -cdtoken token -codetype TESTCODE -calc CS -nocalc CW -norecalc CD -recalc CY -tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action'}\"",
[],
{
listeners: { stderr: expect.any(Function), stdout: expect.any(Function) },
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('test multiple types of configuration', () => {
expect(response.statusCode).toEqual(0);
expect(response.completed).toEqual(true);
expect(spy).toHaveBeenCalledWith(
"powershell \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; iex ((New-Object System.Net.WebClient).DownloadString('http://base.com/tiobeweb/TICS/install-url')); if ($?) {TICS -ide github . -viewer -project 'project' -branchname main -cdtoken token -codetype TESTCODE -calc CS -nocalc CW -norecalc CD -recalc CY -tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action'}\"",
"powershell \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; iex ((New-Object System.Net.WebClient).DownloadString('http://base.com/tiobeweb/TICS/install-url')); if ($?) {TICS -ide github . -viewer -project 'project' -branchname main -cdtoken token -codetype TESTCODE -calc CS -nocalc CW -norecalc CD -recalc CY -tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action'}\"",
[],
{
listeners: { stderr: expect.any(Function), stdout: expect.any(Function) },
Expand Down Expand Up @@ -289,7 +289,7 @@ describe('getTicsCommand', () => {
expect(command).toContain('-codetype TESTCODE');
expect(command).toContain('-branchname main');
expect(command).not.toContain('-branchdir .');
expect(command).toContain(`-tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action'`);
expect(command).toContain(`-tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action'`);
expect(command).toContain('-log 9');
});

Expand Down Expand Up @@ -321,7 +321,7 @@ describe('getTicsCommand', () => {
expect(command).not.toContain('-codetype TESTCODE');
expect(command).toContain('-branchname main');
expect(command).toContain('-branchdir .');
expect(command).toContain(`-tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action'`);
expect(command).toContain(`-tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action'`);
expect(command).toContain('-log 9');
});

Expand Down Expand Up @@ -353,7 +353,7 @@ describe('getTicsCommand', () => {
expect(command).not.toContain('-codetype TESTCODE');
expect(command).not.toContain('-branchname main');
expect(command).not.toContain('-branchdir .');
expect(command).toContain(`-tmpdir '/home/ubuntu/test/123_TICS_1__tiobe_tics-github-action'`);
expect(command).toContain(`-tmpdir '/home/ubuntu/test/123_TICS_1_tics-github-action'`);
expect(command).toContain('-log 9');
});
});
Expand Down

0 comments on commit 920f934

Please sign in to comment.