Make Log4brains run on Node 18 and 20 #72
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired from https://github.com/backstage/backstage/blob/master/.github/workflows/ci.yml. Thanks! | |
name: CI | |
on: | |
workflow_dispatch: | |
pull_request: | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
quality: | |
strategy: | |
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere | |
matrix: | |
os: [ubuntu-latest] | |
node-version: [20.x] # Active LTS (https://github.com/nodejs/release) | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] | |
# TODO: create a dedicated composite GitHub Action to avoid copy/pastes everywhere | |
- name: use node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
registry-url: https://registry.npmjs.org/ # needed for auth when publishing | |
# Cache every node_modules folder inside the monorepo | |
- name: cache all node_modules | |
id: cache-modules | |
uses: actions/cache@v2 | |
with: | |
path: "**/node_modules" | |
# We use both yarn.lock and package.json as cache keys to ensure that | |
# changes to local monorepo packages bust the cache. | |
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }} | |
# If we get a cache hit for node_modules, there's no need to bring in the global | |
# yarn cache or run yarn install, as all dependencies will be installed already. | |
- name: find location of global yarn cache | |
id: yarn-cache | |
if: steps.cache-modules.outputs.cache-hit != 'true' | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- name: cache global yarn cache | |
uses: actions/cache@v2 | |
if: steps.cache-modules.outputs.cache-hit != 'true' | |
with: | |
path: ${{ steps.yarn-cache.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: yarn install | |
if: steps.cache-modules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
# End of yarn setup | |
# TODO: make dev & test work without having to build everything (inspiration: https://github.com/Izhaki/mono.ts) | |
- name: build | |
run: yarn build | |
- name: format | |
run: yarn format | |
- name: lint | |
run: yarn lint | |
tests: | |
needs: quality | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
node-version: [20.x] # Active LTS (https://github.com/nodejs/release); we test other versions in the main Build workflow because it's too slow | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # fetch all history to make Jest snapshot tests work | |
- name: fetch branch develop | |
run: git fetch origin develop | |
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] (copy/paste of the snippet above) | |
- name: use node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
registry-url: https://registry.npmjs.org/ | |
- name: cache all node_modules | |
id: cache-modules | |
uses: actions/cache@v2 | |
with: | |
path: "**/node_modules" | |
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }} | |
- name: find location of global yarn cache | |
id: yarn-cache | |
if: steps.cache-modules.outputs.cache-hit != 'true' | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- name: cache global yarn cache | |
uses: actions/cache@v2 | |
if: steps.cache-modules.outputs.cache-hit != 'true' | |
with: | |
path: ${{ steps.yarn-cache.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: yarn install | |
if: steps.cache-modules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
# End of yarn setup | |
- name: check for yarn.lock changes | |
id: yarn-lock | |
run: git diff --quiet origin/develop HEAD -- yarn.lock | |
continue-on-error: true | |
# - steps.yarn-lock.outcome == 'success' --> yarn.lock was not changed | |
# - steps.yarn-lock.outcome == 'failure' --> yarn.lock was changed | |
# We have to build all the packages before the tests | |
# Because init-log4brains's integration tests use @log4brains/cli, which uses @log4brains/core | |
# TODO: we should separate tests that require built packages of the others, to get a quicker feedback | |
# Once it's done, we should add "yarn test" in each package's preVersion script | |
- name: build | |
run: | | |
yarn build | |
yarn link-cli | |
echo "$(yarn global bin)" >> $GITHUB_PATH | |
- name: typescript checks | |
run: yarn typescript | |
- name: test changed packages | |
if: ${{ steps.yarn-lock.outcome == 'success' }} | |
run: yarn test --since origin/develop | |
- name: test all packages | |
if: ${{ steps.yarn-lock.outcome == 'failure' }} | |
run: yarn test | |
- name: E2E tests | |
run: yarn e2e |