Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: github actions #88

Merged
merged 10 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Main
on:
push:
branches: [ main ]
pull_request:
types: [opened, synchronize]

Expand Down Expand Up @@ -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 }}
27 changes: 27 additions & 0 deletions .github/workflows/local-github-action.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .github/workflows/published-github-action.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
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
25 changes: 17 additions & 8 deletions src/github-action.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down