From 3e524eda760da7ccda3b4de4753e94436e7ddb9e Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:35:59 +0100 Subject: [PATCH] fix: github actions --- .github/workflows/github-action.yaml | 20 ++++++++++++++++++++ src/cli.ts | 5 +---- src/github-action.ts | 20 ++++++++++++-------- 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/github-action.yaml diff --git a/.github/workflows/github-action.yaml b/.github/workflows/github-action.yaml new file mode 100644 index 00000000..7e28b94d --- /dev/null +++ b/.github/workflows/github-action.yaml @@ -0,0 +1,20 @@ +name: Test GitHub Action +on: + push: + pull_request: + types: [opened, synchronize] + +jobs: + test: + container: node:20.9.0@sha256:62efd17e997bc843aefa4c003ed84f43dfac83fa6228c57c898482e50a02e45c + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: GitHub Action + uses: ./ + with: + GITHUB_WORKSPACE: '/' diff --git a/src/cli.ts b/src/cli.ts index bd274198..2132bdc3 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -62,10 +62,7 @@ program await timer.setTimeout(500); const res = await analyser({ - provider: new FSProvider({ - path: root, - ignorePaths: [], - }), + provider: new FSProvider({ path: root, ignorePaths: [] }), }); spinner.succeed('Analysed'); diff --git a/src/github-action.ts b/src/github-action.ts index 5b84aefe..9cd5604f 100644 --- a/src/github-action.ts +++ b/src/github-action.ts @@ -1,3 +1,6 @@ +import fs from 'node:fs/promises'; +import path from 'node:path'; + import core from '@actions/core'; import { l } from './common/log.js'; @@ -7,22 +10,23 @@ import { analyser, FSProvider } from './index.js'; try { l.log('Starting Stack Analyser'); - const token = core.getInput('token', { - required: true, - }); + // Because we exec the GitHub Action in a docker env the repo path is in the env var const workspace = process.env.GITHUB_WORKSPACE!; - l.log('hello', token); l.log('workspace', workspace); + // Analyze const res = await analyser({ - provider: new FSProvider({ - path: workspace, - ignorePaths: [], - }), + provider: new FSProvider({ path: workspace, ignorePaths: [] }), }); l.log('Result:', res.toJson(workspace)); + // Output to file + const file = path.join(workspace, 'stack-output.json'); + l.log('Output to file', file); + + await fs.writeFile(file, JSON.stringify(res.toJson(workspace), undefined, 2)); + l.log('Done'); } catch (error: unknown) { if (error instanceof Error) {