Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,818 changes: 4,130 additions & 688 deletions dist/index.js

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3792,6 +3792,34 @@ Apache-2.0
limitations under the License.


tmp
MIT
The MIT License (MIT)

Copyright (c) 2014 KARASZI István

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


tmp-promise
MIT

tr46
MIT

Expand Down
118 changes: 83 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"homepage": "https://github.com/tiobe/tics-github-action#readme",
"dependencies": {
"@actions/artifact": "^4.0.0",
"@actions/artifact-v1": "npm:@actions/artifact@1.1.2",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.1",
Expand Down
54 changes: 49 additions & 5 deletions src/github/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
import { tmpdir } from 'os';
import { readdirSync } from 'fs';
import { tmpdir } from 'os';

import { DefaultArtifactClient } from '@actions/artifact';
import { create } from '@actions/artifact-v1';
import { join } from 'canonical-path';

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

export async function uploadArtifact(): Promise<void> {
const artifactClient = new DefaultArtifactClient();
logger.header('Uploading artifact');

const tmpdir = getTmpDir() + '/ticstmpdir';
// Example TICS_tics-github-action_2_qserver_ticstmpdir
const name = sanitizeArtifactName(`${githubConfig.job}_${githubConfig.action}_${ticsConfig.mode}_ticstmpdir`);

logger.info(`Logs taken from ${tmpdir}`);

if (isGhes()) {
await uploadGhes(name, tmpdir);
} else {
await uploadGithub(name, tmpdir);
}
}

async function uploadGhes(name: string, tmpdir: string): Promise<void> {
const artifactClient = create();

try {
const response = await artifactClient.uploadArtifact(name, getFilesInFolder(tmpdir), tmpdir);

if (response.failedItems.length > 0) {
logger.debug(`Failed to upload file(s): ${response.failedItems.join(', ')}`);
}
logger.info(`Uploaded artifact "${name}" (size: ${createSize(response.size)})`);
} catch (error: unknown) {
const message = handleOctokitError(error);
logger.debug('Failed to upload artifact: ' + message);
}
}

async function uploadGithub(name: string, tmpdir: string): Promise<void> {
const artifactClient = new DefaultArtifactClient();

try {
logger.header('Uploading artifact');
logger.info(`Logs gotten from ${tmpdir}`);
const response = await artifactClient.uploadArtifact(name, getFilesInFolder(tmpdir), tmpdir);

if (response.id && response.size) {
Expand Down Expand Up @@ -78,3 +107,18 @@ function getFilesInFolder(directory: string): string[] {
traverseDirectory(directory);
return files;
}

/**
* Copied from @actions/artifacts v6.2.0
* https://github.com/actions/toolkit/blob/02afeb157764304bb3bfe1a6cfd37258ec3fcf7c/packages/artifact/src/internal/shared/config.ts
*/
function isGhes(): boolean {
const ghUrl = new URL(emptyToNull(process.env.GITHUB_SERVER_URL) ?? 'https://github.com');

const hostname = ghUrl.hostname.trimEnd().toUpperCase();
const isGitHubHost = hostname === 'GITHUB.COM';
const isGheHost = hostname.endsWith('.GHE.COM');
const isLocalHost = hostname.endsWith('.LOCALHOST');

return !isGitHubHost && !isGheHost && !isLocalHost;
}
4 changes: 4 additions & 0 deletions src/helper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
export function isOneOf<T>(value: T, ...args: [T, ...T[]]): boolean {
return args.includes(value);
}

export function emptyToNull(value: string | null | undefined): string | null {
return value !== undefined && value !== null && value !== '' ? value : null;
}
7 changes: 7 additions & 0 deletions test/.setup/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ jest.mock('@actions/artifact', () => {
}))
};
});
jest.mock('@actions/artifact-v1', () => {
return {
create: jest.fn().mockImplementation(() => ({
uploadArtifact: jest.fn()
}))
};
});
jest.mock('fs', () => {
return {
writeFileSync: jest.fn(),
Expand Down
Loading