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
22 changes: 11 additions & 11 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- ubuntu-latest
steps:
- name: Checkout Repository Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Detect leaks
Expand All @@ -45,34 +45,34 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Setup Node 20
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- name: Setup Nodejs
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: 20.x
node-version-file: package.json
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Move the committed index.js file
run: mv dist/index.js /tmp
run: mv dist/index.cjs /tmp

- name: Rebuild with tsc
run: npm run build

- name: Rebuild the index.js file
- name: Rebuild the index.cjs file
run: npm run release

- name: Compare the expected and actual index.js files
run: git diff --ignore-all-space dist/index.js /tmp/index.js
run: git diff --ignore-all-space dist/index.cjs /tmp/index.cjs
id: diff

# If index.js was different from expected, upload the expected version as an artifact
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: index.js
path: dist/index.js
name: index.cjs
path: dist/index.cjs
overwrite: true
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
name: Check licenses
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- run: npm ci
- name: Install licensed
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout Repository Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules/
lib/
__tests__/_temp/
coverage
coverage
target/
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 20.11.0
nodejs 24.14.1
65 changes: 35 additions & 30 deletions __tests__/input-helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import * as core from '@actions/core';

import { Inputs } from '../src/constants';
import { getInputs } from '../src/input-helper';

// Mock the @actions/core package
jest.mock('@actions/core');
import {
beforeAll,
beforeEach,
describe,
expect,
it,
jest,
} from '@jest/globals';

import { Inputs } from '../src/constants.ts';
import type { UploadInputs } from '../src/upload-inputs.ts';

const mockGetInput =
jest.fn<(name: string, options?: { required?: boolean }) => string>();
const mockSetFailed = jest.fn<(message: string) => void>();

jest.unstable_mockModule('@actions/core', () => ({
getInput: mockGetInput,
setFailed: mockSetFailed,
}));

let getInputs: () => UploadInputs;

beforeAll(async () => {
({ getInputs } = await import('../src/input-helper.ts'));
});

describe('getInputs', () => {
// Store original process.env to restore after tests
Expand Down Expand Up @@ -37,9 +56,7 @@ describe('getInputs', () => {
};

// Mock the core.getInput function to return our test values
(core.getInput as jest.Mock).mockImplementation(
(name) => mockInputs[name] || ''
);
mockGetInput.mockImplementation((name) => mockInputs[name] || '');

// Execute the function
const result = getInputs();
Expand All @@ -55,7 +72,7 @@ describe('getInputs', () => {
});

// Verify that required inputs were checked
expect(core.getInput).toHaveBeenCalledWith(Inputs.Path, { required: true });
expect(mockGetInput).toHaveBeenCalledWith(Inputs.Path, { required: true });
});

it('should use environment variable for bucket if input not provided', () => {
Expand All @@ -72,9 +89,7 @@ describe('getInputs', () => {
[Inputs.IfNoFilesFound]: 'warn',
};

(core.getInput as jest.Mock).mockImplementation(
(name) => mockInputs[name] || ''
);
mockGetInput.mockImplementation((name) => mockInputs[name] || '');

const result = getInputs();

Expand All @@ -93,9 +108,7 @@ describe('getInputs', () => {
[Inputs.IfNoFilesFound]: 'warn',
};

(core.getInput as jest.Mock).mockImplementation(
(name) => mockInputs[name] || ''
);
mockGetInput.mockImplementation((name) => mockInputs[name] || '');

// Verify that the function throws with the expected error message
expect(() => getInputs()).toThrow('no artifact-bucket supplied');
Expand All @@ -113,9 +126,7 @@ describe('getInputs', () => {
[Inputs.RetentionDays]: '90',
};

(core.getInput as jest.Mock).mockImplementation(
(name) => mockInputs[name] || ''
);
mockGetInput.mockImplementation((name) => mockInputs[name] || '');

const result = getInputs();

Expand All @@ -135,16 +146,13 @@ describe('getInputs', () => {
[Inputs.RetentionDays]: 'invalid', // Non-numeric value
};

(core.getInput as jest.Mock).mockImplementation(
(name) => mockInputs[name] || ''
);
const setFailedMock = core.setFailed as jest.Mock;
mockGetInput.mockImplementation((name) => mockInputs[name] || '');

// Execute function with invalid retention days
getInputs();

// Verify error was properly handled
expect(setFailedMock).toHaveBeenCalledWith('Invalid retention-days');
expect(mockSetFailed).toHaveBeenCalledWith('Invalid retention-days');
});

it('should set failed for invalid ifNoFilesFound', () => {
Expand All @@ -158,16 +166,13 @@ describe('getInputs', () => {
[Inputs.IfNoFilesFound]: '', // Invalid empty value
};

(core.getInput as jest.Mock).mockImplementation(
(name) => mockInputs[name] || ''
);
const setFailedMock = core.setFailed as jest.Mock;
mockGetInput.mockImplementation((name) => mockInputs[name] || '');

// Execute function with invalid ifNoFilesFound
getInputs();

// Verify error was handled with proper message
expect(setFailedMock).toHaveBeenCalledWith(
expect(mockSetFailed).toHaveBeenCalledWith(
expect.stringContaining('Unrecognized if-no-files-found input')
);
});
Expand Down
29 changes: 23 additions & 6 deletions __tests__/search.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { promises as fs } from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';

import * as core from '@actions/core';
import type { GlobOptions } from '@actions/glob';
import * as io from '@actions/io';
import { beforeAll, describe, expect, it, jest } from '@jest/globals';

import { findFilesToUpload } from '../src/search';
import type { SearchResult } from '../src/search.ts';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const mockDebug = jest.fn();
const mockInfo = jest.fn();
const mockWarning = jest.fn();

jest.unstable_mockModule('@actions/core', () => ({
debug: mockDebug,
info: mockInfo,
warning: mockWarning,
}));

let findFilesToUpload: (
searchPath: string,
globOptions?: GlobOptions
) => Promise<SearchResult>;

const root = path.join(__dirname, '_temp', 'search');
const searchItem1Path = path.join(
Expand Down Expand Up @@ -69,13 +88,11 @@ const lonelyFilePath = path.join(

describe('Search', () => {
beforeAll(async () => {
({ findFilesToUpload } = await import('../src/search.ts'));

// mock all output so that there is less noise when running tests
jest.spyOn(console, 'log').mockImplementation(jest.fn());

jest.spyOn(core, 'debug').mockImplementation(jest.fn());
jest.spyOn(core, 'info').mockImplementation(jest.fn());
jest.spyOn(core, 'warning').mockImplementation(jest.fn());

// clear temp directory
await io.rmRF(root);
await fs.mkdir(path.join(root, 'folder-a', 'folder-b', 'folder-c'), {
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ inputs:
concurrency:
description: >
The rate of concurrency
default: 8
default: '8'
run-number:
description: 'Github run number used to identify artifacts'
default: ${{ github.run_number }}
runs:
using: node20
main: 'dist/index.js'
using: node24
main: 'dist/index.cjs'
Loading
Loading