Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ci #6

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Setup

description: Setup Node.js, cache and install dependencies

runs:
using: composite
steps:
# Needed for nx affected command, it set the BASE and HEAD env variables
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3

- name: Determine Node.js version
id: node_version
shell: bash
run: echo "node_version=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- uses: pnpm/action-setup@v2
with:
version: 8.6.11
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: pnpm
node-version: ${{ steps.node_version.outputs.node_version }}
# This doesn't just set the registry url, but also sets
# the right configuration in .npmrc that reads NPM token
# from NPM_AUTH_TOKEN environment variable.
# It actually creates a .npmrc in a temporary folder
# and sets the NPM_CONFIG_USERCONFIG environment variable.
registry-url: https://registry.npmjs.org

- name: Install dependencies
shell: bash
run: pnpm install
89 changes: 89 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: CI

on:
push:
branches:
- main
pull_request: {}

concurrency:
# Group concurrency on workflow, then:
# - Is merge run? Group on branch name (`refs/heads/main`)
# - Is pull request? Group on pull request branch name, for example `feat/add-awesome-feature`
group: >-
${{ github.workflow }}-${{
github.event_name == 'push'
&& github.ref
|| github.head_ref
}}
# Run merge workflows in sequence to prevent parallel deployments and releases
# Cancel stale pull request runs in progress for the same branch
cancel-in-progress: ${{ github.event_name != 'push' }}

env:
NODE_OPTIONS: --max-old-space-size=6144

jobs:
# We're using Nx Cloud for Distributed Task Execution
# Reference: https://nx.dev/using-nx/dte
#
# The coordinator outputs the combination of task outputs from the agents,
# both terminal and file outputs
dte_coordinator:
name: DTE Coordinator
uses: nrwl/ci/.github/workflows/[email protected]
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
permissions:
contents: read
actions: read
with:
main-branch-name: main
# Must match dte_agents.number-of-agents
number-of-agents: 4
# The --stop-agents-after parameter must match the task target listed last
# in the parallel-commands-on-agents command list
# The --agent-count parameter must match the number-of-agents parameter
init-commands: |
yarn nx-cloud start-ci-run --stop-agents-after="e2e" --agent-count=4
# Commands run in parallel on this DTE coordinator
parallel-commands: |
yarn nx-cloud record -- yarn nx format:check
# Commands distributed between DTE agents
# Distribution strategy for 2 vCPUs per hosted runner (GitHub Free):
# lint: 2 tasks assigned at a time, 1 task per vCPU
# test: 1 task assigned at a time with 2 parallel processes, 1 process per vCPU
# build: 2 tasks assigned at a time, 1 task per vCPU
# e2e: 1 task assigned at a time, 1 task total
parallel-commands-on-agents: |
yarn nx run-many --all --target=lint --configuration=report --parallel=2 --max-warnings=0
yarn nx run-many --all --target=test --configuration=coverage --parallel=1 --max-workers=2
yarn nx affected --target=build --parallel=2
yarn nx affected --target=e2e --parallel=1
# Commands run sequentially on this DTE coordinator after parallel jobs
# final-commands: |

# We're using Nx Cloud for Distributed Task Execution
# Reference: https://nx.dev/using-nx/dte
#
# Agents receive tasks to execute in bulk whenever they are ready or have
# finished their previous tasks
dte_agents:
name: DTE Agents
uses: nrwl/ci/.github/workflows/[email protected]
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
permissions:
contents: read
actions: read
with:
# The Free GitHub plan has a limit of 20 concurrent jobs on Ubuntu images
# Reference: https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration
# If we need to, we can optimize for 2 simultaneous workflow runs:
# 2 x 1 main job = 2 concurrent jobs
# 2 x 9 agent jobs = 18 concurrent jobs
# Total = 20 concurrent jobs
#
# However, we don't have many projects or targets in this workspace, so we
# lower the number of agents to reduce spent compute time.
number-of-agents: 4
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.16.0