Skip to content

Instantly share code, notes, and snippets.

@lydemann
Last active September 20, 2022 20:15
Show Gist options
  • Save lydemann/c57693657e7559bccd4e08d361150981 to your computer and use it in GitHub Desktop.
Save lydemann/c57693657e7559bccd4e08d361150981 to your computer and use it in GitHub Desktop.
# ci.yml
name: CI
env:
# Branching
is-merge: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
is-pull-request: ${{ github.event_name == 'pull_request' }}
NODE_OPTIONS: --max-old-space-size=6144
on:
push:
branches:
- main
pull_request: {}
jobs:
builds:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v3
with:
# Required by nrwl/nx-set-shas
fetch-depth: 0
- name:
'Derive appropriate SHAs for base and head for `nx affected` commands'
uses: nrwl/nx-set-shas@v2
- name: Set up dependencies
uses: ./.github/actions/setup-dependencies
- name: 'PR: Build application if affected by changes in feature branch'
if: env.is-pull-request == 'true'
run: yarn affected:build
- name: 'Merge: Build application'
if: env.is-merge == 'true'
run: yarn build
name: CI
env:
# Branching
is-merge: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
is-pull-request: ${{ github.event_name == 'pull_request' }}
# Node.js
NODE_OPTIONS: --max-old-space-size=6144
on:
push:
branches:
- main
pull_request: {}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v3
with:
# Required by nrwl/nx-set-shas
fetch-depth: 0
- name:
'Derive appropriate SHAs for base and head for `nx affected` commands'
uses: nrwl/nx-set-shas@v2
- name: Set up dependencies
uses: ./.github/actions/setup-dependencies
- name: 'Build application if affected by changes in feature branch'
run: yarn affected:build
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v3
with:
# Required by nrwl/nx-set-shas
fetch-depth: 0
- name:
'Derive appropriate SHAs for base and head for `nx affected` commands'
uses: nrwl/nx-set-shas@v2
- name: Set up dependencies
uses: ./.github/actions/setup-dependencies
- name: Lint Nx workspace
run: yarn nx workspace-lint
- name: 'Lint workspace and affected projects'
run: yarn affected:lint
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v3
with:
# Required by nrwl/nx-set-shas
fetch-depth: 0
- name:
'Derive appropriate SHAs for base and head for `nx affected` commands'
uses: nrwl/nx-set-shas@v2
- name: Set up dependencies
uses: ./.github/actions/setup-dependencies
- name: 'Test affected projects'
run: yarn test
e2e:
name: End-to-end test
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v3
with:
# Required by nrwl/nx-set-shas
fetch-depth: 0
- name:
'Derive appropriate SHAs for base and head for `nx affected` commands'
uses: nrwl/nx-set-shas@v2
- name: Set up dependencies
uses: ./.github/actions/setup-dependencies
- name:
'End-to-end test application if affected by changes in feature
branch'
run: yarn affected:e2e --configuration=ci-production
name: CI
env:
NODE_OPTIONS: --max-old-space-size=6144
on:
push:
branches:
- main
pull_request: {}
jobs:
builds:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run build
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm run test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm run lint
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm run e2e
"scripts": {
"ng": "nx",
"start": "nx serve",
"build": "nx run-many --target=build --all --parallel",
"test": "nx run-many --target=test --all --parallel",
"lint": "nx run-many --target=lint --all --parallel",
"e2e": "nx run-many --target=e2e --all"
}
"scripts": {
"affected:build": "nx affected:build --configuration=production",
"affected:ci": "yarn affected:build && yarn affected:lint && yarn affected:test && yarn affected:e2e --configuration=ci-production",
"affected:e2e": "nx affected:e2e",
"affected:lint": "nx affected:lint --max-warnings=0",
"affected:test": "nx affected:test",
}
name: CI
env:
NODE_OPTIONS: --max-old-space-size=6144
on:
push:
branches:
- main
pull_request: {}
jobs:
builds:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run build
- run: npm run test
- run: npm run lint
- run: npm run e2e
@LayZeeDK
Copy link

LayZeeDK commented Sep 20, 2022

issue: pull_request must be aligned with push (my bad)

# simple-pipeline.yml, cy.yml
on:
  push:
    branches:
      - main
  pull_request: {}

@LayZeeDK
Copy link

LayZeeDK commented Sep 20, 2022

suggestion: add cache parameter to setup-node steps as suggested by @lydemann

# simple-pipeline.yml, cy.yml
        - uses: actions/setup-node@v3
          with:
            node-version: 16
            cache: npm

@lydemann
Copy link
Author

Thanks @LayZeeDK ! Updated it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment