Skip to content

Commit

Permalink
ci: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Aug 28, 2021
1 parent f620c6f commit fa34aff
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 102 deletions.
46 changes: 46 additions & 0 deletions .github/actions/build-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build Cache
description: 'Caches our build artifacts'

inputs:
os:
description: OS
required: true
node:
description: Node.js Version
required: true

outputs:
node-cache-hit:
description: Node Modules Cache Hit
value: ${{ steps.cache-node.outputs.cache-hit }}
ts-cache-hit:
description: TypeScript Build Cache Hit
value: ${{ steps.cache-build.outputs.cache-hit }}

runs:
using: "composite"

steps:

- name: Node Modules Caching
id: cache-node
uses: actions/cache@v2
with:
path: |
**/node_modules
key: node-${{ inputs.os }}-{{ inputs.node }}-${{ hashFiles('yarn.lock') }}

- name: Build Caching
id: cache-build
uses: actions/cache@v2
with:
path: |
**/*.js
**/*.js.map
**/*.d.ts
**/*.d.ts.map
**/*.node
**/*.md
packages/core/README.md
!**/node_modules
key: ts-${{ github.sha }}
321 changes: 220 additions & 101 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,127 +1,246 @@
name: Build

on:
workflow_dispatch:
schedule:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule
# Every day at 4am:
- cron: '0 4 * * *'
push:
branches:
- master
workflow_dispatch:
pull_request:
branches:
- master
schedule:
- cron: '0 4 * * *' # Runs every day at 4am: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule

env:
NODE_OPTIONS: --max_old_space_size=4096

jobs:

build:
name: ${{ matrix.os }}, Node.js v${{ matrix.node }}
prepare:

strategy:
fail-fast: false
matrix:
os: [windows-2019, ubuntu-18.04, macos-10.15]
node: ['12.x']
node: ['12.x', '14.x']

name: Prepare ${{ matrix.os }}, Node.js v${{ matrix.node }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # To fetch all history for all branches and tags. (Will be required for caching with lerna: https://github.com/markuplint/markuplint/pull/111)

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- name: Use Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Build
shell: bash
run: |
yarn --skip-integrity-check --network-timeout 100000
yarn lint
npx electron-replace-ffmpeg
npx electron-codecs-test
yarn build:examples
yarn download:plugins
./scripts/check_git_status.sh
env:
NODE_OPTIONS: --max_old_space_size=4096
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9

- name: Test (headless)
if: matrix.tests != 'skip'
shell: bash
run: |
yarn test:theia
- name: Test (browser)
if: matrix.tests != 'skip' && runner.os == 'Linux'
uses: GabrielBB/xvfb-action@v1
with:
run: yarn browser test

- name: Test (electron)
if: matrix.tests != 'skip' && runner.os == 'Linux'
uses: GabrielBB/xvfb-action@v1
with:
run: yarn electron test

publish:
needs: build
if: github.ref == 'refs/heads/master' && github.event_name != 'schedule' # We still publish the manually dispatched workflows: 'workflow_dispatch'.
- uses: actions/checkout@v2

- name: Use Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- uses: ./.github/actions/build-cache
with:
os: ${{ matrix.os }}
node: ${{ matrix.node }}

- name: Prepare Packages
run: yarn install --ignore-engines
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9

- name: Electron Checks
run: |
npx electron-replace-ffmpeg
npx electron-codecs-test
lint:
needs: prepare

strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04]
node: ['12.x']

runs-on: ubuntu-18.04

# The current approach is silly. We should be smarter and use `actions/upload-artifact` and `actions/download-artifact` instead of rebuilding
# everything from scratch again. (git checkout, Node.js install, yarn, etc.) It was not possible to share artifacts on Travis CI without an
# external storage (such as S3), so we did rebuild everything before the npm publish. We should overcome this limitation with GH Actions.
steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- uses: ./.github/actions/build-cache
with:
os: ${{ matrix.os }}
node: ${{ matrix.node }}

- name: Lint
run: yarn lint

unit_tests:
needs: prepare

strategy:
fail-fast: false
matrix:
os: [windows-2019, ubuntu-18.04, macos-10.15]
node: ['12.x', '14.x']

name: Browser Tests ${{ matrix.os }}, Node.js v${{ matrix.node }}
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- uses: ./.github/actions/build-cache
with:
os: ${{ matrix.os }}
node: ${{ matrix.node }}

- name: Unit Tests
run: yarn test:theia

browser_integration_tests:
needs: prepare

strategy:
fail-fast: false
matrix:
# os: [windows-2019, ubuntu-18.04, macos-10.15]
os: [ubuntu-18.04]
node: ['12.x', '14.x']

name: Browser Integration Tests ${{ matrix.os }}, Node.js v${{ matrix.node }}
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- uses: ./.github/actions/build-cache
with:
os: ${{ matrix.os }}
node: ${{ matrix.node }}

- name: Build Browser Example
run: yarn browser build

- name: Download Plugins
run: yarn download:plugins

- name: Browser Integration Tests
uses: GabrielBB/xvfb-action@v1
with:
run: yarn browser test

electron_integration_tests:
needs: prepare

strategy:
fail-fast: false
matrix:
# Electron runs independently from Node.js,
# so we only need to test different operating systems:
os: [windows-2019, ubuntu-18.04, macos-10.15]
node: ['12.x']

name: Electron Integration Tests ${{ matrix.os }}, Node.js v${{ matrix.node }}
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # To fetch all history for all branches and tags. (Will be required for caching with lerna: https://github.com/markuplint/markuplint/pull/111)

- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'

- name: Use Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Pre-Publish
run: |
yarn --skip-integrity-check --network-timeout 100000
yarn build:ts
yarn docs
env:
NODE_OPTIONS: --max_old_space_size=4096
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9

- name: Publish NPM
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
retry_wait_seconds: 30
max_attempts: 3
retry_on: error
command: yarn publish:next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # The variable name comes from here: https://github.com/actions/setup-node/blob/70b9252472eee7495c93bb1588261539c3c2b98d/src/authutil.ts#L48

- name: Publish GH Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gh-pages
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- uses: ./.github/actions/build-cache
with:
os: ${{ matrix.os }}
node: ${{ matrix.node }}

- name: Download Plugins
run: yarn download:plugins

- name: Build Electron Example
run: yarn electron build

- name: Electron Integration Tests
uses: GabrielBB/xvfb-action@v1
with:
run: yarn electron test

# publish:
# needs: prepare
# if: github.ref == 'refs/heads/master' && github.event_name != 'schedule' # We still publish the manually dispatched workflows: 'workflow_dispatch'.
# runs-on: ubuntu-18.04

# # The current approach is silly. We should be smarter and use `actions/upload-artifact` and `actions/download-artifact` instead of rebuilding
# # everything from scratch again. (git checkout, Node.js install, yarn, etc.) It was not possible to share artifacts on Travis CI without an
# # external storage (such as S3), so we did rebuild everything before the npm publish. We should overcome this limitation with GH Actions.

# steps:
# - name: Checkout
# uses: actions/checkout@v2
# with:
# fetch-depth: 0 # To fetch all history for all branches and tags. (Will be required for caching with lerna: https://github.com/markuplint/markuplint/pull/111)

# - name: Use Node.js 12.x
# uses: actions/setup-node@v1
# with:
# node-version: '12.x'
# registry-url: 'https://registry.npmjs.org'

# - name: Use Python 3.x
# uses: actions/setup-python@v2
# with:
# python-version: '3.x'

# - name: Pre-Publish
# run: |
# yarn --skip-integrity-check --network-timeout 100000
# yarn build:ts
# yarn docs
# env:
# NODE_OPTIONS: --max_old_space_size=4096
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9

# - name: Publish NPM
# uses: nick-invision/retry@v2
# with:
# timeout_minutes: 5
# retry_wait_seconds: 30
# max_attempts: 3
# retry_on: error
# command: yarn publish:next
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # The variable name comes from here: https://github.com/actions/setup-node/blob/70b9252472eee7495c93bb1588261539c3c2b98d/src/authutil.ts#L48

# - name: Publish GH Pages
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./gh-pages
Loading

0 comments on commit fa34aff

Please sign in to comment.