Skip to content

Commit

Permalink
chore(ci): setup nx agents and improve other CI workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Mar 19, 2024
1 parent 4574a95 commit 82eb041
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
runs:
using: 'composite'
steps:
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
with:
version: 8.2

Expand Down
56 changes: 56 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 'Setup Build Tools and Dependencies'
description: Setup node, pnpm, java, flutter, cache, and install dependencies

inputs:
node-version: # id of input
description: 'Node version'
required: false
default: 20

runs:
using: 'composite'
steps:
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4

- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8.2

- name: Setup Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'pnpm'

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- run: java -version
shell: bash

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path
architecture: x64 # optional, x64 or arm64
- run: flutter --version
shell: bash

- name: Cache node_modules
id: cache-modules
uses: actions/cache@v4
with:
lookup-only: true
path: '**/node_modules'
key: pnpm-${{ hashFiles('pnpm-lock.yaml') }}

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

on:
push:
branches:
- develop
pull_request:

# Needed for nx-set-shas when run on the main branch
permissions:
actions: read
contents: read

jobs:
develop:
runs-on: ubuntu-latest
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
timeout-minutes: 60
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install node, pnpm, and dependencies
uses: ./.github/actions/install-dependencies

# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e" targets have been requested
- run: pnpm exec nx-cloud start-ci-run --distribute-on="5 linux-small-js-java-flutter" --stop-agents-after="e2e"

# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track develop origin/develop

- run: pnpm exec nx-cloud record -- nx format:check
- run: pnpm exec nx affected -t lint test build e2e --exclude=smoke --codeCoverage
4 changes: 2 additions & 2 deletions .github/workflows/commintlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4
- uses: wagoid/commitlint-github-action@v5
with:
configFile: '.commitlintrc.js'
configFile: '.commitlintrc.js'
61 changes: 0 additions & 61 deletions .github/workflows/run-e2e-tests.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/run-smoke-tests.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/run-unit-tests.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Nightly Smoke Tests

on:
# Trigger manually or on schedule
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
run_smoke_tests:
name: Smoke Tests
runs-on: ${{ matrix.os }}
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
timeout-minutes: 60
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node-version: [20]
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup node, pnpm, java, flutter, and dependencies
uses: ./.github/actions/setup
with:
node-version: ${{ matrix.node-version }}

- name: Run smoke tests
env:
NX_E2E_CI_CACHE_KEY: smoke-gha-${{ matrix.os }}-${{ matrix.node-version }}
NX_RUN_GROUP: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}
run: pnpm nx test smoke --verbose
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm affected:format
pnpm affected:lint
pnpm affected:test
pnpm sync-preset-schemas
30 changes: 30 additions & 0 deletions .nx/workflow-steps/install-flutter/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { execSync } = require('child_process');

const flutterVersion = process.env.FLUTTER_VERSION || '3.19.3';
const flutterChannel = process.env.FLUTTER_CHANNEL || 'stable';

const flutterPkgName = `flutter_linux_${flutterVersion}-${flutterChannel}.tar.xz`;
const flutterPkgUrl = `https://storage.googleapis.com/flutter_infra_release/releases/${flutterChannel}/linux/${flutterPkgName}`;

runInBash('ls -l /usr/local', { stdio: 'inherit' });

console.log(`Installing Flutter v${flutterVersion}-${flutterChannel} manually`);
execSync(`curl -L ${flutterPkgUrl} | tar -xJf - -C /usr/local`, {
stdio: 'inherit',
});

console.log('Adding Flutter bin to PATH...');
runInBash(
`echo 'export PATH="$PATH:/usr/local/flutter/bin"' >> $HOME/.bashrc`,
{
stdio: 'inherit',
}
);
runInBash('source $HOME/.bashrc', { stdio: 'inherit' });
runInBash('cat $HOME/.bashrc', { stdio: 'inherit' });

execSync('flutter version', { stdio: 'inherit' });

function runInBash(cmd, opts = { stdio: 'inherit' }) {
execSync(`echo "#!/usr/bin/env bash\n\n${cmd}" | bash`, opts);
}
6 changes: 6 additions & 0 deletions .nx/workflow-steps/install-flutter/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Install Flutter
description: Installs Flutter using snap

definition:
using: 'node'
main: 'nx-cloud/.nx/workflow-steps/install-flutter/main.js'
25 changes: 25 additions & 0 deletions .nx/workflow-steps/install-java/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { execSync } = require('child_process');

const javaVersion = process.env.JAVA_VERSION || '17';
const javaDistro = process.env.JAVA_DISTRO || 'ms';

const javaVersionFull = `${javaVersion}-${javaDistro}`;

console.log('Installing Utils(zip, unzip, etc)!');
execSync('sudo apt update', { stdio: 'inherit' });
execSync('sudo apt install zip unzip', { stdio: 'inherit' });

console.log('Installing SDKMan! first');
execSync('curl -s "https://get.sdkman.io" | bash', { stdio: 'inherit' });
runInBash('echo "Current terminal is: $0"', { stdio: 'inherit' });
runInBash('source $HOME/.sdkman/bin/sdkman-init.sh', { stdio: 'inherit' });
runInBash('sdk version', { stdio: 'inherit' });

console.log('Installing Java using SDKMan!');
runInBash(`sdk install java ${javaVersionFull}`, { stdio: 'inherit' });
runInBash(`sdk use java ${javaVersionFull}`, { stdio: 'inherit' });
runInBash('java -version', { stdio: 'inherit' });

function runInBash(cmd, opts = { stdio: 'inherit' }) {
execSync(`echo "#!/usr/bin/env bash\n\n${cmd}" | bash`, opts);
}
6 changes: 6 additions & 0 deletions .nx/workflow-steps/install-java/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Install Java
description: Installs Java using SDKMan!

definition:
using: 'node'
main: 'nx-cloud/.nx/workflow-steps/install-java/main.js'
Loading

0 comments on commit 82eb041

Please sign in to comment.