diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c271ea3a..beee996f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,7 @@ name: Main on: push: + branches: [ main ] pull_request: types: [opened, synchronize] @@ -44,8 +45,3 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage/cobertura-coverage.xml - - - name: Test github action - uses: ./ - with: - token: ${{ secrets.SPECFY_TOKEN }} diff --git a/.github/workflows/local-github-action.yaml b/.github/workflows/local-github-action.yaml new file mode 100644 index 00000000..7b016049 --- /dev/null +++ b/.github/workflows/local-github-action.yaml @@ -0,0 +1,27 @@ +name: Test Local GitHub Action +on: + push: + branches: [ main ] + pull_request: + types: [opened, synchronize] + +jobs: + test_local_github_action: + 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: '/' + + - name: Check if file exists + working-directory: ${{ github.workspace }} + run: | + echo "Check if file exists" + cat stack-output.json || exit 1 diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml new file mode 100644 index 00000000..af82bf33 --- /dev/null +++ b/.github/workflows/published-github-action.yaml @@ -0,0 +1,22 @@ +name: Test Published GitHub Action +on: + workflow_dispatch: + +jobs: + test_published_github_action: + 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: specfy/stack-analyser@v1.8.2 + + - name: Check if file exists + working-directory: ${{ github.workspace }} + run: | + echo "Check if file exists" + cat stack-output.json || exit 1 diff --git a/Dockerfile b/Dockerfile index eedf64b7..0ee3109a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,11 +53,13 @@ RUN true \ && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false # Do not use root to run the app -USER node +# We need to use the root +# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#docker-container-filesystem +# USER node WORKDIR /app -COPY --from=tmp --chown=node:node /app/tmp /app +COPY --from=tmp /app/tmp /app EXPOSE 8080 diff --git a/action.yml b/action.yml index 0e8daa09..f7a497c7 100644 --- a/action.yml +++ b/action.yml @@ -3,11 +3,6 @@ author: Specfy description: |- Run Specfy's Stack Analyser and send update to Specfy API -inputs: - token: - description: |- - Specfy Project's Token - required: true runs: using: 'docker' 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..479ec6bd 100644 --- a/src/github-action.ts +++ b/src/github-action.ts @@ -1,28 +1,37 @@ +import fs from 'node:fs/promises'; +import path from 'node:path'; + import core from '@actions/core'; import { l } from './common/log.js'; import { analyser, FSProvider } from './index.js'; +import './autoload.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); + if (!workspace) { + throw new Error('No workspace env specified'); + } + + // Analyze const res = await analyser({ - provider: new FSProvider({ - path: workspace, - ignorePaths: [], - }), + provider: new FSProvider({ path: workspace }), }); 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) {