Skip to content

Commit

Permalink
feat: bootstrap action
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Mar 11, 2024
1 parent 9117798 commit e4787cb
Show file tree
Hide file tree
Showing 22 changed files with 34,998 additions and 2,180 deletions.
41 changes: 0 additions & 41 deletions .devcontainer/devcontainer.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: .nvmrc
cache: npm

- name: Install Dependencies
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: .nvmrc
cache: npm

- name: Install Dependencies
Expand Down Expand Up @@ -56,9 +56,12 @@ jobs:
- name: Test Local Action
id: test-action
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
milliseconds: 1000
curl:
'curl https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs'

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
# - name: Print Output
# id: output
# run: echo "${{ steps.test-action.outputs.time }}"
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: .nvmrc
cache: npm

- name: Install Dependencies
Expand Down
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Repository CODEOWNERS

* @actions/actions-oss-maintainers
* @cerberauth @emmanuelgautier
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright GitHub
Copyright (c) 2024 CerberAuth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ 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.
SOFTWARE.
31 changes: 4 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
# Create a JavaScript Action
# VulnAPI GitHub Action

[![GitHub Super-Linter](https://github.com/actions/javascript-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/actions/javascript-action/actions/workflows/ci.yml/badge.svg)
[![VulnAPI GitHub Action](https://github.com/cerberauth/vulnapi-action/actions/workflows/linter.yml/badge.svg)](https://github.com/cerberauth/vulnapi-action)
![CI](https://github.com/cerberauth/vulnapi-action/actions/workflows/ci.yml/badge.svg)

Use this template to bootstrap the creation of a JavaScript action. :rocket:

This template includes compilation support, tests, a validation workflow,
publishing, and versioning guidance.

If you are new, there's also a simpler introduction in the
[Hello world JavaScript action repository](https://github.com/actions/hello-world-javascript-action).

## Create Your Own Action

To create your own action, you can use this repository as a template! Just
follow the below instructions:

1. Click the **Use this template** button at the top of the repository
1. Select **Create a new repository**
1. Select an owner and name for your new repository
1. Click **Create repository**
1. Clone your new repository

> [!IMPORTANT]
>
> Make sure to remove or update the [`CODEOWNERS`](./CODEOWNERS) file! For
> details on how to use this file, see
> [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners).
Use this action to scan your project for vulnerabilities using the VulnAPI.

## Initial Setup

Expand Down
65 changes: 4 additions & 61 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,23 @@ const core = require('@actions/core')
const main = require('../src/main')

// Mock the GitHub Actions core library
const debugMock = jest.spyOn(core, 'debug').mockImplementation()
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()

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

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

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

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

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)
)
})

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

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'
)
})

it('fails if no input is provided', async () => {
it.skip('fails if no input is provided', async () => {

Check warning on line 19 in __tests__/main.test.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Disabled test
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
throw new Error('Input required and not supplied: milliseconds')
case 'curl':
throw new Error('You must provide curl or openapi input')
default:
return ''
}
Expand All @@ -90,7 +33,7 @@ describe('action', () => {
// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
'Input required and not supplied: milliseconds'
'You must provide curl or openapi input'
)
})
})
24 changes: 0 additions & 24 deletions __tests__/wait.test.js

This file was deleted.

22 changes: 16 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
name: 'The name of your action here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: 'VulnAPI Action'
description:
"GitHub Action to use CerberAuth's VulnAPI to check for vulnerabilities in
your API"
author: 'CerberAuth'

# Define your inputs here.
inputs:
milliseconds:
description: 'Your input description here'
version:
description: 'The version of the VulnAPI to use'
required: true
default: '1000'
default: 'latest'

curl:
description: 'The curl command used to run API vulnerability scans'
required: false

openapi:
description: 'The OpenAPI file used to run API vulnerability scans'
required: false

# Define your outputs here.
outputs:
Expand Down
Loading

0 comments on commit e4787cb

Please sign in to comment.