From ca483113791fd63aec16bb4cf9e28d18fed502ac Mon Sep 17 00:00:00 2001 From: Mathieu Veber <43341681+MathieuVeber@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:08:52 +0200 Subject: [PATCH] feat: add individual format, lint, sonarcloud and test workflows (#23) --- .github/workflows/eslint.yml | 34 ++++++++++ .github/workflows/prettier.yml | 34 ++++++++++ .github/workflows/sonarcloud.yml | 57 +++++++++++++++++ .github/workflows/test.yml | 105 +++++++++++++++++++++++++++++++ .github/workflows/typescript.yml | 40 ++++++++++++ 5 files changed, 270 insertions(+) create mode 100644 .github/workflows/eslint.yml create mode 100644 .github/workflows/prettier.yml create mode 100644 .github/workflows/sonarcloud.yml create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/typescript.yml diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml new file mode 100644 index 0000000..789e918 --- /dev/null +++ b/.github/workflows/eslint.yml @@ -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 diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..ebfce60 --- /dev/null +++ b/.github/workflows/prettier.yml @@ -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 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 0000000..20599e6 --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ba70968 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml new file mode 100644 index 0000000..8f33c4b --- /dev/null +++ b/.github/workflows/typescript.yml @@ -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