Skip to content

Commit

Permalink
Add ability to customize endpoint (#11)
Browse files Browse the repository at this point in the history
* 🚀 Add ability to configure endpoint

* 📄 Document changes

* Testing some more

* 👍 Publish dist items

* 🔧 More testing

* 🔧 Maybe this will work?

* 🔧 More tweaks

* 🚀 Include endpoint input in action.yml

* 📖 Update README examples to point to latest
  • Loading branch information
himynameisdave committed Sep 28, 2021
1 parent bca527c commit 5913e73
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v2
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
```
Expand All @@ -46,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v2
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
run-tests: true
Expand All @@ -63,12 +63,28 @@ jobs:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v2
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
container: ubuntu:20.04
```

### `endpoint`
**Optional** Endpoint passed to FOSSA CLI. Defaults to `app.fossa.com`. [Read more](https://github.com/fossas/spectrometer/blob/master/docs/userguide.md#common-fossa-project-flags).

Example
```yml
jobs:
fossa-scan:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v2
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
endpoint: fossa.my-company.com
```

## Examples
We've provided a few examples of how to use FOSSA's Github Action in your own project. These examples use an API key stored as a Github secret environment variable `fossaAPiKey`.

Expand All @@ -81,7 +97,7 @@ jobs:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v2
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
```
Expand All @@ -98,12 +114,12 @@ jobs:
uses: actions/checkout@v2

- name: "Run FOSSA Scan"
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}

- name: "Run FOSSA Test"
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
run-tests: true
Expand All @@ -121,13 +137,13 @@ jobs:
uses: actions/checkout@v2

- name: "Run FOSSA Scan"
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
container: ubuntu:20.04

- name: "Run FOSSA Test"
uses: fossas/fossa-action@v1
uses: fossas/fossa-action@latest
with:
api-key: ${{secrets.fossaApiKey}}
container: ubuntu:20.04
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ inputs:
default: false
container:
required: false
endpoint:
required: false

runs:
using: node12
Expand Down
13 changes: 11 additions & 2 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import { getInput } from '@actions/core';
export const FOSSA_API_KEY = getInput('api-key', {required: true});
export const CONTAINER = getInput('container', {required: false});
export const RUN_TESTS = getInput('run-tests', {required: false}).toLocaleLowerCase() === 'true';
export const ENDPOINT = getInput('endpoint', {required: false});
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { error, setFailed } from '@actions/core';
import { exec } from '@actions/exec';
import { CONTAINER, FOSSA_API_KEY, RUN_TESTS } from './config';
import {
CONTAINER,
FOSSA_API_KEY,
RUN_TESTS,
ENDPOINT,
} from './config';
import { fetchFossaCli } from './download-cli';

export async function analyze(): Promise<void> {
// Github doesn't always collect exit codes correctly, so we check output
const failedRegex = /(A fatal error occurred|Test failed\. Number of issues found)/;
const getArgs = (cmd: string) => [CONTAINER ? 'container' : null, cmd].filter(arg => arg);
const getEndpointArgs = (): string[] => !ENDPOINT ? [] : [
'--endpoint',
ENDPOINT,
];
const getArgs = (cmd: string) => [
CONTAINER ? 'container' : null,
cmd,
...getEndpointArgs(),
].filter(arg => arg);

// Setup listeners
let output;
Expand Down

0 comments on commit 5913e73

Please sign in to comment.