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 01/10] 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) { From 6b89d94dab6af0cda1329b5ad40c354ae6b019c0 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:00:46 +0100 Subject: [PATCH 02/10] do not use special user --- .github/workflows/ci.yaml | 1 + .github/workflows/github-action.yaml | 2 +- Dockerfile | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c271ea3a..275c3db1 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] diff --git a/.github/workflows/github-action.yaml b/.github/workflows/github-action.yaml index 7e28b94d..78a84939 100644 --- a/.github/workflows/github-action.yaml +++ b/.github/workflows/github-action.yaml @@ -5,7 +5,7 @@ on: types: [opened, synchronize] jobs: - test: + test_github_action: container: node:20.9.0@sha256:62efd17e997bc843aefa4c003ed84f43dfac83fa6228c57c898482e50a02e45c runs-on: ubuntu-latest timeout-minutes: 10 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 From ebe7d8b4a4f8fc8fa945af80945d334e6221eab7 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:04:45 +0100 Subject: [PATCH 03/10] fix ci --- .github/workflows/ci.yaml | 6 +----- ...ithub-action.yaml => local-github-action.yaml} | 5 +---- .github/workflows/published-github-action.yaml | 15 +++++++++++++++ action.yml | 5 ----- 4 files changed, 17 insertions(+), 14 deletions(-) rename .github/workflows/{github-action.yaml => local-github-action.yaml} (85%) create mode 100644 .github/workflows/published-github-action.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 275c3db1..3a2e4c52 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,9 +1,5 @@ name: Main -on: - push: - branches: [ main ] - pull_request: - types: [opened, synchronize] +on: [push, pull_request] jobs: ci: diff --git a/.github/workflows/github-action.yaml b/.github/workflows/local-github-action.yaml similarity index 85% rename from .github/workflows/github-action.yaml rename to .github/workflows/local-github-action.yaml index 78a84939..93f0e519 100644 --- a/.github/workflows/github-action.yaml +++ b/.github/workflows/local-github-action.yaml @@ -1,8 +1,5 @@ name: Test GitHub Action -on: - push: - pull_request: - types: [opened, synchronize] +on: [push, pull_request] jobs: test_github_action: diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml new file mode 100644 index 00000000..a000b9ff --- /dev/null +++ b/.github/workflows/published-github-action.yaml @@ -0,0 +1,15 @@ +name: Test GitHub Action +on: [push, pull_request] + +jobs: + test_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 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' From a2f18f9bdafe2607262d53aa72ededef68e6900d Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:06:24 +0100 Subject: [PATCH 04/10] test something else --- .github/workflows/ci.yaml | 6 +++++- .github/workflows/local-github-action.yaml | 10 +++++++--- .github/workflows/published-github-action.yaml | 10 +++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3a2e4c52..275c3db1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,5 +1,9 @@ name: Main -on: [push, pull_request] +on: + push: + branches: [ main ] + pull_request: + types: [opened, synchronize] jobs: ci: diff --git a/.github/workflows/local-github-action.yaml b/.github/workflows/local-github-action.yaml index 93f0e519..71d3bac2 100644 --- a/.github/workflows/local-github-action.yaml +++ b/.github/workflows/local-github-action.yaml @@ -1,8 +1,12 @@ -name: Test GitHub Action -on: [push, pull_request] +name: Test Local GitHub Action +on: + push: + branches: [ main ] + pull_request: + types: [opened, synchronize] jobs: - test_github_action: + test_local_github_action: container: node:20.9.0@sha256:62efd17e997bc843aefa4c003ed84f43dfac83fa6228c57c898482e50a02e45c runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml index a000b9ff..f2b07918 100644 --- a/.github/workflows/published-github-action.yaml +++ b/.github/workflows/published-github-action.yaml @@ -1,8 +1,12 @@ -name: Test GitHub Action -on: [push, pull_request] +name: Test Published GitHub Action +on: + push: + branches: [ main ] + pull_request: + types: [opened, synchronize] jobs: - test_github_action: + test_published_github_action: container: node:20.9.0@sha256:62efd17e997bc843aefa4c003ed84f43dfac83fa6228c57c898482e50a02e45c runs-on: ubuntu-latest timeout-minutes: 10 From 5594a9e8cadf2c5650654a5416bd2ca5193b8dff Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:08:30 +0100 Subject: [PATCH 05/10] missing version --- .github/workflows/published-github-action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml index f2b07918..cdeeaabe 100644 --- a/.github/workflows/published-github-action.yaml +++ b/.github/workflows/published-github-action.yaml @@ -16,4 +16,4 @@ jobs: uses: actions/checkout@v4 - name: GitHub Action - uses: specfy/stack-analyser + uses: specfy/stack-analyser@1 From 8aaa78ac80982afdb39628cef3763145ec15cac4 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:11:44 +0100 Subject: [PATCH 06/10] proper version --- .github/workflows/published-github-action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml index cdeeaabe..fa26ed9f 100644 --- a/.github/workflows/published-github-action.yaml +++ b/.github/workflows/published-github-action.yaml @@ -16,4 +16,4 @@ jobs: uses: actions/checkout@v4 - name: GitHub Action - uses: specfy/stack-analyser@1 + uses: specfy/stack-analyser@v1.8.1 From fa021cd20f77794a1a00f85ae4ac592946b3c7fe Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:16:39 +0100 Subject: [PATCH 07/10] test if file exists --- .github/workflows/local-github-action.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/local-github-action.yaml b/.github/workflows/local-github-action.yaml index 71d3bac2..7b016049 100644 --- a/.github/workflows/local-github-action.yaml +++ b/.github/workflows/local-github-action.yaml @@ -19,3 +19,9 @@ jobs: 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 From c52f11d8c19e9287f41426ad0a153c0f6c6fe7c8 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:23:52 +0100 Subject: [PATCH 08/10] missing autoload --- .github/workflows/published-github-action.yaml | 6 ++++++ src/github-action.ts | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml index fa26ed9f..a56a381d 100644 --- a/.github/workflows/published-github-action.yaml +++ b/.github/workflows/published-github-action.yaml @@ -17,3 +17,9 @@ jobs: - name: GitHub Action uses: specfy/stack-analyser@v1.8.1 + + - name: Check if file exists + working-directory: ${{ github.workspace }} + run: | + echo "Check if file exists" + cat stack-output.json || exit 1 diff --git a/src/github-action.ts b/src/github-action.ts index 9cd5604f..479ec6bd 100644 --- a/src/github-action.ts +++ b/src/github-action.ts @@ -6,6 +6,7 @@ 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'); @@ -14,9 +15,13 @@ try { const workspace = process.env.GITHUB_WORKSPACE!; 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)); From 84ecdbfb944482a019f77ea57146414d2fc9a0cf Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:26:01 +0100 Subject: [PATCH 09/10] remove leftover --- .github/workflows/ci.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 275c3db1..beee996f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,8 +45,3 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage/cobertura-coverage.xml - - - name: Test github action - uses: ./ - with: - token: ${{ secrets.SPECFY_TOKEN }} From 7978b004bdd775d0be3cd94d00e99c0ccad34726 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:28:54 +0100 Subject: [PATCH 10/10] prepare published test --- .github/workflows/published-github-action.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/published-github-action.yaml b/.github/workflows/published-github-action.yaml index a56a381d..af82bf33 100644 --- a/.github/workflows/published-github-action.yaml +++ b/.github/workflows/published-github-action.yaml @@ -1,9 +1,6 @@ name: Test Published GitHub Action on: - push: - branches: [ main ] - pull_request: - types: [opened, synchronize] + workflow_dispatch: jobs: test_published_github_action: @@ -16,7 +13,7 @@ jobs: uses: actions/checkout@v4 - name: GitHub Action - uses: specfy/stack-analyser@v1.8.1 + uses: specfy/stack-analyser@v1.8.2 - name: Check if file exists working-directory: ${{ github.workspace }}