Skip to content

Commit

Permalink
SCP-49 Adds GH Check on main workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
francostramana committed Jan 22, 2024
1 parent 73dbc23 commit f6457a5
Show file tree
Hide file tree
Showing 8 changed files with 29,538 additions and 798 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- main
- '*'

permissions:
contents: read
Expand All @@ -14,7 +14,7 @@ jobs:
name: GitHub Actions Test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
Expand Down
29,577 changes: 28,790 additions & 787 deletions dist/index.js

Large diffs are not rendered by default.

504 changes: 504 additions & 0 deletions dist/licenses.txt

Large diffs are not rendered by default.

179 changes: 171 additions & 8 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1"
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.11",
Expand Down
1 change: 1 addition & 0 deletions src/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CHECK_NAME = 'SCANOSS Policy Checker'
55 changes: 55 additions & 0 deletions src/libs/GitHubCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { context, getOctokit } from '@actions/github'

Check failure on line 1 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Filename 'GitHubCheck.ts' does not match the naming convention

Check failure on line 1 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Filename 'GitHubCheck.ts' does not match the naming convention
import { getInput } from '@actions/core'

const NO_INITIALIZATE = -1

export class GitHubCheck {
private octokit // TODO: type from actions/github ?

private checkName: string

private checkRunId: number

constructor(checkName: string) {
const GITHUB_TOKEN = getInput('github-token') // TODO: move to inputs.ts file?

this.octokit = getOctokit(GITHUB_TOKEN)
this.checkName = checkName
this.checkRunId = NO_INITIALIZATE
}

async present() {

Check failure on line 21 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Missing return type on function

Check failure on line 21 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Missing return type on function
const result = await this.octokit.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: this.checkName,
head_sha: context.sha
})

this.checkRunId = result.data.id

return result.data
}

async finish(conclusion: any, summary: string, text: string) {

Check failure on line 34 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Missing return type on function

Check failure on line 34 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Unexpected any. Specify a different type

Check failure on line 34 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Missing return type on function

Check failure on line 34 in src/libs/GitHubCheck.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unexpected any. Specify a different type
if (this.checkRunId === NO_INITIALIZATE)
throw new Error(
`Error on finish. Check "${this.checkName}" is not created.`
)

const result = await this.octokit.rest.checks.update({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: this.checkRunId,
status: 'completed',
conclusion,
output: {
title: this.checkName,
summary,
text
}
})

return result.data
}
}
13 changes: 13 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import { CHECK_NAME } from './app.config'
import { GitHubCheck } from './libs/GitHubCheck'

/**
* The main function for the action.
Expand All @@ -12,6 +14,10 @@ export async function run(): Promise<void> {
const repoDir = process.env.GITHUB_WORKSPACE as string
const outputPath = 'results.json'

// init check
const check = new GitHubCheck(CHECK_NAME)
await check.present()

// Declara las opciones para ejecutar el exec
const options: exec.ExecOptions = {}
let output: string = ''

Check failure on line 23 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Type string trivially inferred from a string literal, remove type annotation

Check failure on line 23 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'output' is assigned a value but never used

Check failure on line 23 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Type string trivially inferred from a string literal, remove type annotation

Check failure on line 23 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'output' is assigned a value but never used
Expand All @@ -29,6 +35,13 @@ export async function run(): Promise<void> {
options
)

// finish
await check.finish(
'success',
'Code analysis completed successfully',
'Here are the licenses found:'
)

// set outputs for other workflow steps to use
core.setOutput('result-filepath', outputPath)
} catch (error) {
Expand Down

0 comments on commit f6457a5

Please sign in to comment.