Skip to content

Instantly share code, notes, and snippets.

@ijlee2
Last active August 29, 2023 21:37
Show Gist options
  • Save ijlee2/1c864ebe96a55f239e80800829ef0bf4 to your computer and use it in GitHub Desktop.
Save ijlee2/1c864ebe96a55f239e80800829ef0bf4 to your computer and use it in GitHub Desktop.
GitHub Actions workflow for Ember apps (yarn)
# The workflow template is designed for Ember apps.
#
# It assumes certain dependencies and scripts in package.json. If
# they don't apply to your project, feel free to remove irrelevant
# code in the workflow. These can be inferred from the job name.
#
# {
# "scripts": {
# "build": "ember build --environment=production",
# "build:test": "ember build --environment=test",
# "deploy": "ember deploy production",
# "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
# "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
# "lint:hbs": "ember-template-lint .",
# "lint:hbs:fix": "ember-template-lint . --fix",
# "lint:js": "eslint . --cache",
# "lint:js:fix": "eslint . --fix",
# "start": "ember serve",
# "test": "ember exam --split=4 --parallel=1"
# },
# "devDependencies": {
# "@percy/cli" (test-app)
# "@percy/ember" (test-app)
# "concurrently" (lint)
# "ember-cli-deploy" (deploy-app)
# "ember-cli-deploy-build" (deploy-app)
# "ember-cli-deploy-git" (deploy-app)
# "ember-exam" (test-app)
# "ember-qunit" (test-app)
# "ember-template-lint" (lint)
# "eslint" (lint)
# },
# }
#
# For more information, please visit:
#
# - https://crunchingnumbers.live/2020/03/17/ci-with-github-actions-for-ember-apps/
# - https://crunchingnumbers.live/2020/08/31/ci-with-github-actions-for-ember-apps-part-2/
#
# Author: Isaac J. Lee (GitHub: @ijlee2)
# Created at: August 31, 2020
# Updated at: December 8, 2022
#
name: CI/CD
on:
push:
branches:
- main
pull_request:
schedule:
# Run the workflow every Monday at 6 am CST
- cron: '0 11 * * MON'
env:
NODE_VERSION: 16
PERCY_PARALLEL_NONCE: ${{ github.run_id }}-${{ github.run_number }}
PERCY_PARALLEL_TOTAL: 4
jobs:
build-app:
name: Build app
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out a copy of the repo
uses: actions/checkout@v3
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build app
run: yarn build:test
- name: Upload app
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
lint:
name: Lint files
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out a copy of the repo
uses: actions/checkout@v3
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
test-app:
name: Test app
needs: [build-app]
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
partition:
- 1
- 2
- 3
- 4
timeout-minutes: 5
steps:
- name: Check out a copy of the repo
uses: actions/checkout@v3
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Download app
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Test
run: npx percy exec -- yarn test --partition=${{ matrix.partition }} --path=dist
env:
PERCY_PARALLEL_NONCE: ${{ env.PERCY_PARALLEL_NONCE }}
PERCY_PARALLEL_TOTAL: ${{ env.PERCY_PARALLEL_TOTAL }}
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
deploy-app:
name: Deploy app
needs: [lint, test-app]
runs-on: ubuntu-latest
timeout-minutes: 5
# Only run on pushes to main branch that aren't from the cron workflow
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && contains(github.ref, 'cron') != true
steps:
- name: Check out a copy of the repo
uses: actions/checkout@v3
- name: Set up Git user
run: |
# Set up a Git user for committing
git config --global user.name "GitHub Actions"
git config --global user.email "actions@users.noreply.github.com"
# Copy the Git Auth from the local config
git config --global "http.https://github.com/.extraheader" \
"$(git config --local --get http.https://github.com/.extraheader)"
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Deploy
run: yarn deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment