Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Add CI-CD to terra-application-v1 branch (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdadn authored Aug 21, 2023
1 parent b9ea39b commit b7d51ae
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Set default code owners for all files in repo
* @benbcai @jmsv6d @elliott-hoffman-cerner
@cerner/terra-code-owners
50 changes: 37 additions & 13 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
<!--
PLEASE COMPLETE THESE STEPS BEFORE PUBLISHING THE PULL REQUEST:
*Before publishing*
1. Update the title as: [component] changes to component (ex. [terra-button] Added terra-button accessibility guide).
2. Fill out the fields below.
3. Assign yourself to the PR.
4. Add the appropriate package name labels.
5. Add your name to the CONTRIBUTORS.md file. Adding your name to the CONTRIBUTORS.md file signifies agreement to all rights and reservations provided by the License.
-->

### Summary
<!--- Summarize and explain the reason behind these code changes. What are the changes, and why are they necessary? -->
<!--- Summarize and explain the reasoning behind these code changes. What are the changes, and why are they necessary? -->

**What was changed:**


**Why it was changed:**

<!--- Include any issue addressed by this pull request. -->
<!--- Example: Closes #45 -->
Closes #

### Deployment Link
<!---Include the deployment link, if applicable. -->
https://terra-applic-.herokuapp.com/

### Testing
<!-- Demonstrate that these changes are stable. How have these changes been verified? -->

This change was tested using:

- [ ] WDIO
- [ ] Jest
- [ ] Visual testing (please attach a screenshot or recording)
- [ ] Other (please describe below)
- [ ] No tests are needed

### Reviews

In addition to engineering reviews, this PR needs:
<!-- Please include the appropriate "Required" & "Ready" labels (ex. "UX Review Required" and "UX Review Ready"). -->
- [ ] UX review
- [ ] Accessibility review
- [ ] Functional review

### Additional Details
<!-- List anything else that is relevant to this issue. Additional information will help us better understand your changes and speed up the review process. -->

<!--
*Before publishing*
**This PR resolves:**

1. Assign yourself to the PR.
2. Add the appropriate labels
3. Add your name to the CONTRIBUTORS.md file. Adding your name to the CONTRIBUTORS.md file signifies agreement to all rights and reservations provided by the License.
-->
UXPLATFORM-XXXX <!-- Jira Number or issue Number. Please do not link to Jira. -->

---

Thank you for contributing to Terra.
@cerner/terra
15 changes: 15 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Setup Project
description: Steps neccessary to setup the project
runs:
using: "composite"
steps:
- name: Setup Node 14.x
uses: actions/setup-node@v3
with:
node-version: 14.x
- name: Clean Environment
shell: bash
run: npm run clean
- name: Install Dependencies
shell: bash
run: npm install
116 changes: 116 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
name: CI and CD

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
tags:
description: 'Test scenario tags'
required: false
type: boolean
environment:
description: 'Environment to run tests against'
type: environment
required: true
push:
branches: ['terra-application-v1']
pull_request:
branches: ['terra-application-v1']
schedule:
- cron: '0 1 * * SUN'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Project
uses: actions/checkout@v3
- name: Setup Project
uses: ./.github/actions/setup
- if: github.event_name == 'pull_request'
name: Danger
uses: danger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/danger/danger-js/issues/557#issuecomment-664851950
DANGER_DISABLE_TRANSPILATION: true
- name: Linting Project
run: |
npm run lint
- name: Testing Project
run: |
npm run jest
wdio:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
theme: [default, lowlight, fusion]

steps:
- name: Checkout Project
uses: actions/checkout@v3
- name: Setup Project
uses: ./.github/actions/setup
- name: Compile Project Default
run: |
npm run compile:prod -- --output-path build/default
if: matrix.theme == 'default'
- name: Compile Project Lowlight
run: |
npm run compile:lowlight -- --output-path build/lowlight
if: matrix.theme == 'lowlight'
- name: Compile Project Fusion
run: |
npm run compile:fusion -- --output-path build/fusion
if: matrix.theme == 'fusion'
- name: Run WDIO Tests for theme ${{ matrix.theme }}
env:
SITE: build/${{ matrix.theme }}
run: npm run wdio-${{ matrix.theme }}

release-and-deploy:
runs-on: ubuntu-latest

needs: [build, wdio]
if: github.ref == 'refs/heads/terra-application-v1'
steps:
- name: Checkout Project
uses: actions/checkout@v2
- name: Setup GitHub Config
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Setup Project
uses: ./.github/actions/setup
- name: Build
env:
TERRA_DEV_SITE_NEW_RELIC_LICENSE_KEY: ${{ secrets.TERRA_DEV_SITE_NEW_RELIC_LICENSE_KEY }}
TERRA_DEV_SITE_NEW_RELIC_APPLICATION_ID: "141260567"
TERRA_DEV_SITE_PUBLIC_PATH: /terra-application/
run: npm run compile:prod
- name: Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx terra release
# - name: Deploy
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./build
# keep_files: true
# user_name: 'github-actions[bot]'
# user_email: 'github-actions[bot]@users.noreply.github.com'
# commit_message: 'chore(docs): Regenerate docs'
46 changes: 46 additions & 0 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: delete preview on PR close

# only trigger on pull request closed events
on:
pull_request:
types: [closed]

jobs:
delete_preview:
runs-on: ubuntu-latest
env:
PR_PATH: pull/${{github.event.number}}
ENVIRONMENT_NAME: preview-pr-${{ github.event.number }}
steps:
- name: make empty dir
run: mkdir public

- name: delete folder
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
destination_dir: ${{ env.PR_PATH }}

- name: get deployment
id: get-deplpoyment
uses: octokit/[email protected]
with:
route: GET /repos/{repository}/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: set previous deployment as inactive
if: |
steps.get-deplpoyment.outputs.status != '404' &&
toJSON(fromJSON(steps.get-deplpoyment.outputs.data)) != '[]'
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
deployment: ${{ fromJSON(steps.get-deplpoyment.outputs.data)[0].id }}
repository: ${{ github.repository }}
state: inactive
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
128 changes: 128 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: pr-preview

on:
pull_request:
branches: ['terra-application-v1']
jobs:
deploy:
runs-on: ubuntu-latest
env:
PR_PATH: pull/${{ github.event.number }}
TERRA_DEV_SITE_PUBLIC_PATH: "/terra-application/pull/${{ github.event.number }}/"
BASE_URL: "https://engineering.cerner.com/${{ github.event.repository.name }}/pull/${{ github.event.number }}/"
ENVIRONMENT_NAME: preview-pr-${{ github.event.number }}
steps:
- name: check for previous deployment
id: check-previous
uses: octokit/[email protected]
with:
route: GET /repos/{repository}/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: set previous deployment as inactive
if: |
steps.check-previous.outputs.status != '404' &&
toJSON(fromJSON(steps.check-previous.outputs.data)) != '[]'
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJSON(steps.check-previous.outputs.data)[0].id }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: inactive
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: get pull request
id: get-pull-request
uses: octokit/[email protected]
with:
route: GET /repos/{repository}/pulls/{issue_id}
repository: ${{ github.repository }}
issue_id: ${{ github.event.number }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: create deployment
id: create-deployment
uses: octokit/[email protected]
if: |
steps.check-previous.outputs.status != '404'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
route: POST /repos/{repository}/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
transient_environment: true
auto_merge: false
environment: ${{env.ENVIRONMENT_NAME}}
required_contexts: '[]'

- name: set deployment status to in progress
id: start_deployment
uses: octokit/[email protected]
if: |
steps.check-previous.outputs.status != '404'
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJSON(steps.create-deployment.outputs.data).id }}
environment: ${{ env.ENVIRONMENT_NAME }}
environment_url: ${{ env.BASE_URL }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- uses: actions/checkout@v3
with:
ref: ${{ fromJSON(steps.get-pull-request.outputs.data).head.sha }}

- name: setup project
uses: ./.github/actions/setup

- name: build project
env:
TERRA_DEV_SITE_NEW_RELIC_LICENSE_KEY: ${{ secrets.TERRA_DEV_SITE_NEW_RELIC_LICENSE_KEY }}
TERRA_DEV_SITE_NEW_RELIC_APPLICATION_ID: "144458769"
run: npm run compile:prod

- name: deploy the pull request
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
destination_dir: ${{ env.PR_PATH }}

- name: set deployment status to success
id: successful_deployment
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create-deployment.outputs.data).id }}
environment: ${{ env.ENVIRONMENT_NAME }}
environment_url: ${{ env.BASE_URL }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: success
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: set deployment status to failure
id: failed_deployment
uses: octokit/[email protected]
if: failure()
with:
route: POST /repos/{repository}/deployments/{deployment}/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create-deployment.outputs.data).id }}
environment: ${{ env.ENVIRONMENT_NAME }}
environment_url: ${{ env.BASE_URL }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: failure
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
Loading

0 comments on commit b7d51ae

Please sign in to comment.