Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCP-49 Adds GH Check on main workflow #3

Merged
merged 2 commits into from
Jan 23, 2024
Merged
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
8 changes: 5 additions & 3 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ rules:
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'no-shadow': 'warn',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
Expand All @@ -56,7 +57,7 @@ rules:
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
Expand All @@ -76,8 +77,9 @@ rules:
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
'@typescript-eslint/unbound-method': 'error',
'github/array-foreach' : 'off'
}
9 changes: 8 additions & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ on:

permissions:
contents: read
pull-requests: write
checks: write

jobs:
test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
Expand All @@ -22,6 +27,8 @@ jobs:
- name: Test Local Action
id: test-action
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Print output command
run: echo "${{ steps.test-action.outputs.output-command }}"
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{

Check warning on line 1 in .prettierrc.json

View workflow job for this annotation

GitHub Actions / Lint Codebase

File ignored by default.
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
Expand Down
12 changes: 6 additions & 6 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* Unit tests for the action's entrypoint, src/index.ts
*/

import * as main from '../src/main'
import * as main from '../src/main';

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()
const runMock = jest.spyOn(main, 'run').mockImplementation();

describe('index', () => {
it('calls run when imported', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index')
require('../src/index');

expect(runMock).toHaveBeenCalled()
})
})
expect(runMock).toHaveBeenCalled();
});
});
72 changes: 36 additions & 36 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,71 @@
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/

import * as core from '@actions/core'
import * as main from '../src/main'
import * as core from '@actions/core';
import * as main from '../src/main';

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
const runMock = jest.spyOn(main, 'run');

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
const timeRegex = /^\d{2}:\d{2}:\d{2}/;

// Mock the GitHub Actions core library
let debugMock: jest.SpyInstance
let errorMock: jest.SpyInstance
let getInputMock: jest.SpyInstance
let setFailedMock: jest.SpyInstance
let setOutputMock: jest.SpyInstance
let debugMock: jest.SpyInstance;
let errorMock: jest.SpyInstance;
let getInputMock: jest.SpyInstance;
let setFailedMock: jest.SpyInstance;
let setOutputMock: jest.SpyInstance;

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()
jest.clearAllMocks();

debugMock = jest.spyOn(core, 'debug').mockImplementation()
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})
debugMock = jest.spyOn(core, 'debug').mockImplementation();
errorMock = jest.spyOn(core, 'error').mockImplementation();
getInputMock = jest.spyOn(core, 'getInput').mockImplementation();
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation();
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation();
});

it('sets the time output', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return '500'
return '500';
default:
return ''
return '';
}
})
});

await main.run()
expect(runMock).toHaveReturned()
await main.run();
expect(runMock).toHaveReturned();

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
expect(debugMock).toHaveBeenNthCalledWith(2, expect.stringMatching(timeRegex))
expect(debugMock).toHaveBeenNthCalledWith(3, expect.stringMatching(timeRegex))
expect(setOutputMock).toHaveBeenNthCalledWith(1, 'time', expect.stringMatching(timeRegex))
expect(errorMock).not.toHaveBeenCalled()
})
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...');
expect(debugMock).toHaveBeenNthCalledWith(2, expect.stringMatching(timeRegex));
expect(debugMock).toHaveBeenNthCalledWith(3, expect.stringMatching(timeRegex));
expect(setOutputMock).toHaveBeenNthCalledWith(1, 'time', expect.stringMatching(timeRegex));
expect(errorMock).not.toHaveBeenCalled();
});

it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return 'this is not a number'
return 'this is not a number';
default:
return ''
return '';
}
})
});

await main.run()
expect(runMock).toHaveReturned()
await main.run();
expect(runMock).toHaveReturned();

// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'milliseconds not a number')
expect(errorMock).not.toHaveBeenCalled()
})
})
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'milliseconds not a number');
expect(errorMock).not.toHaveBeenCalled();
});
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ branding:

# Define your inputs here.
inputs:
github-token:
description: 'Your GitHub token'
required: true
scanner-parameters:
description: 'Parameters to run a scan'
required: false
Expand Down
Loading
Loading