Skip to content

Commit

Permalink
feat: add individual format, lint, sonarcloud and test workflows (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuVeber authored Apr 5, 2024
1 parent 33ee277 commit ca48311
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ESLint

on:
workflow_call:
secrets:
READONLY_NPM_TOKEN:
description: Needed to install private @hedia npm packages
required: true

jobs:
eslint:
runs-on: ubuntu-latest
timeout-minutes: 1

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
always-auth: true
cache: 'npm'
node-version-file: package.json
registry-url: https://registry.npmjs.org
scope: "@hedia"

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.READONLY_NPM_TOKEN }}

- name: Run ESLint
run: npm run eslint
34 changes: 34 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Prettier

on:
workflow_call:
secrets:
READONLY_NPM_TOKEN:
description: Needed to install private @hedia npm packages
required: true

jobs:
prettier:
runs-on: ubuntu-latest
timeout-minutes: 1

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
always-auth: true
cache: 'npm'
node-version-file: package.json
registry-url: https://registry.npmjs.org
scope: "@hedia"

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.READONLY_NPM_TOKEN }}

- name: Run Prettier
run: npm run prettier:check
57 changes: 57 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: SonarCloud

on:
workflow_call:
secrets:
READONLY_NPM_TOKEN:
description: Needed to install private @hedia npm packages
required: true
SONAR_TOKEN:
description: Needed to run SonarCloud Scan
required: true

jobs:
sonarcloud:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of SonarCloud analysis

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
always-auth: true
cache: 'npm'
node-version-file: package.json
registry-url: https://registry.npmjs.org
scope: "@hedia"

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.READONLY_NPM_TOKEN }}

- name: Download Coverage
uses: actions/download-artifact@v4
with:
name: coverage.xml

- name: Select Project
env:
GITHUB_PROJECT: ${{ github.repository }}
run: echo "GITHUB_PROJECT=${GITHUB_PROJECT/\//_}" >> $GITHUB_ENV

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ github.token }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=${{ env.GITHUB_PROJECT }}
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.coverageReportPaths=coverage.xml
105 changes: 105 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Test

on:
workflow_call:
inputs:
postgres:
description: Database used in this workflow. Default to none
required: false
type: string
redis:
description: Whether or not to use Redis in this workflow. Default to false
required: false
default: false
type: boolean

secrets:
READONLY_NPM_TOKEN:
description: Needed to install private @hedia npm packages
required: true
SONAR_TOKEN:
description: Needed to run SonarCloud Scan
required: true
BREVO_API_KEY:
description: Token needed to authenticate requests to Brevo API if any
required: false
PRIVATE_KEY:
description: Private JSON Web Key that might be needed to run test script
required: false
PUBLIC_KEY:
description: Public JSON Web Key that might be needed to run test script
required: false
SLACK_APP_TOKEN:
description: Token to authenticate requests to Slack API if necessary
required: false

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5

services:
postgres:
image: ${{ inputs.postgres && 'postgres' || '' }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: ${{ inputs.postgres }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

redis:
image: ${{ inputs.redis && 'redis' || '' }}
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
always-auth: true
cache: 'npm'
node-version-file: package.json
registry-url: https://registry.npmjs.org
scope: "@hedia"

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.READONLY_NPM_TOKEN }}

- name: Download Build
uses: actions/download-artifact@v4
with:
name: build
path: dist

- name: Setup Service
run: NODE_ENV=test npm run setup --if-present

- name: Run Tests
run: npm run test
env:
BREVO_API_KEY: ${{ secrets.BREVO_API_KEY }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
SLACK_APP_TOKEN: ${{ secrets.SLACK_APP_TOKEN }}

- name: Upload Coverage
uses: actions/upload-artifact@v4
with:
name: coverage.xml
path: coverage.xml
40 changes: 40 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Typescript

on:
workflow_call:
secrets:
READONLY_NPM_TOKEN:
description: Needed to install private @hedia npm packages
required: true

jobs:
typescript:
runs-on: ubuntu-latest
timeout-minutes: 1

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
always-auth: true
cache: 'npm'
node-version-file: package.json
registry-url: https://registry.npmjs.org
scope: "@hedia"

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.READONLY_NPM_TOKEN }}

- name: Build Repository
run: npm run build

- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: build
path: dist

0 comments on commit ca48311

Please sign in to comment.