Skip to content

Commit

Permalink
fix: github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel committed Nov 3, 2023
1 parent 5aa9b75 commit 3e524ed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/github-action.yaml
Original file line number Diff line number Diff line change
@@ -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: '/'
5 changes: 1 addition & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
20 changes: 12 additions & 8 deletions src/github-action.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down

0 comments on commit 3e524ed

Please sign in to comment.