Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 3.22 KB

File metadata and controls

70 lines (49 loc) · 3.22 KB

🚀 Reusable CI workflow for Node

This reusable workflow is part of the City of Helsinki’s GitHub Actions setup, specifically designed to provide an opinionated and consistent CI process for City of Helsinki’s Node projects.

🌟 Key Features

  • Commit Linting: Enforces commit message standards using commitlint.
  • Build and Lint: Build and verifies code style and formatting via yarn.
  • Automated Testing: Runs project tests via yarn.
  • Code Quality Analysis: Performs a SonarQube Cloud scan.
  • Dependency Review: Scans dependency changes in pull requests for known vulnerabilities using GitHub's dependency review action.

📋 Requirements for Projects Using the Workflow

  • commitlint config file is present in the root of the project.
  • SonarQube Cloud is configured with SONAR_TOKEN set in the repository or organization secrets.

🧶 Yarn Commands

  • build the project.
  • lint run eslint or another lint tool.
  • test:coverage runs project tests with coverage.

🪡 Optional Yarn Commands

  • typecheck run tsc check
  • check-size run browser bundle size limits check. The command is run if the .size-limit.js file is found in the app directory.
  • check-dist: run ecmascript checks for build files. The command is run if the .escheckrc file is found in the app directory.

📚 Usage Instructions

To use this reusable workflow, create a project-specific workflow file in your .github/workflows directory. Ensure the uses value is set to City-of-Helsinki/.github/.github/workflows/ci-node.yml@main and secrets is set to inherit. Also provide the following inputs as needed:

🛑 Required Inputs

  • node-version (string): Specifies the Node version to use in the workflow.

🔶 Optional Inputs

  • extra-commands (string): Additional setup commands or checks to execute before running tests. Can be used to set environment variables: echo "EXTRA_TEST_ENV_VAR=test" >> $GITHUB_ENV.
  • typecheck (boolean): Run typecheck command. Default is false.
  • working-directory (string): Repository working directory where to run yarn installation and the tests. Default is . (the repository root).
  • app-directory (string): The subdirectory of the application where the tests are run. Default is working-directory.
  • commitlint-config-file (string): Path to the commitlint config file. If not set, commitlint uses its default config discovery.
  • artifact-name (string): Name for the uploaded build artifact. If empty, defaults to build-artifacts-<node-version>.

🔑 Secrets

  • SONAR_TOKEN: Token for SonarQube Cloud Scan. Required.

📄 Example usage (<own project>/.github/workflows/ci.yml)

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

jobs:
  common:
    uses: City-of-Helsinki/.github/.github/workflows/ci-node.yml@main
    secrets: inherit
    with:
      node-version: 20
    extra-commands: |
      echo "EXTRA_TEST_ENV_VAR=test" >> $GITHUB_ENV