Skip to content

Commit

Permalink
add .github/workflows folder to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorpapke committed Jan 29, 2024
1 parent 3ff49b6 commit 8280d7c
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/cd-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CD workflow to deploy app to production environment.
# Defines one job - deploy-to-production.
# Job runs on ubuntu-latest runner.
# Steps:
# - Download build artifact
# - Run CD script to deploy app to production
# Workflow is reusable and triggered via workflow_call.
# Can pass inputs and secrets.

name: CD Production
run-name: Node.js CD (production)
on:
workflow_call: # required when creating a reusable workflow
# inputs:
# config-path:
# required: false
# type: string
# secrets:
# token:
# required: false
jobs:
deploy-to-production:
runs-on: ubuntu-latest
steps:
# - name: Download build
# uses: actions/download-artifact@v3
# with:
# name: next.js-build

- name: Run CD for Production
run: |
echo Perform deployment steps for the production environment
32 changes: 32 additions & 0 deletions .github/workflows/cd-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CD workflow to deploy app to staging environment.
# Defines one job - deploy-to-staging.
# Job runs on ubuntu-latest runner.
# Steps:
# - Download build artifact
# - Run CD script to deploy app to production
# Workflow is reusable and triggered via workflow_call.
# Can pass inputs and secrets.

name: Node.js CD Staging
run-name: Node.js CD (staging)
on:
workflow_call: # required when creating a reusable workflow
# inputs:
# config-path:
# required: false
# type: string
# secrets:
# token:
# required: false
jobs:
deploy-to-staging:
runs-on: ubuntu-latest
steps:
# - name: Download build
# uses: actions/download-artifact@v3
# with:
# name: next.js-build

- name: Run CD for Staging
run: |
echo Perform deployment steps for the staging environment
73 changes: 73 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

name: Continuous Integration
run-name: Node.js CI
on:
workflow_call: # required when creating a reusable workflow
# inputs:
# config-path:
# required: false
# type: string
# secrets:
# token:
# required: false
jobs:
build-and-test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'
- name: Clean install
run: npm ci
- name: Run linter
run: npm run lint
- name: Compile typescript
run: npm run compile
- name: Jest unit tests
run: npm run unit:tests
- name: Test coverage
run: npm run test:coverage

# - name: Run Redux/State Management Tests
# run: npm run redux:tests
#
# - name: Run Component Tests
# run: npm run test:components
#
# - name: Run End-to-End Tests
# run: npm run test:e2e
#
# - name: Run Snapshot Tests
# run: npm run test:snapshot
#
# - name: Run Routing Tests
# run: npm run test:routing
#
# - name: Run API Tests
# run: npm run test:api
#
# - name: Run Integration Tests
# run: npm run test:integration

- name: Build App
run: npm run build --if-present

# https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts
- name: Archive Next.js build
uses: actions/upload-artifact@v3
with:
name: next.js-build
path: .next/
retention-days: 14

- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: docs/coverage/index.html
retention-days: 14
27 changes: 27 additions & 0 deletions .github/workflows/on-new-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This is the CI New Branch Workflow.
# The purpose of this workflow is to automate the process of integrating (CI) code changes
# that are made on new branches or on pull requests targeting the 'main' branch which we use for development.
#
# The workflow is triggered::
# 1. When a new branch is created. This is triggered by the 'create' event.
#
# The workflow consists of a single job: 'CI'.
#
# The 'CI' job:
# - Is defined in the separate '.github/workflows/ci.yml' file.
# - Runs every time the workflow is triggered, regardless of the specific event.
# - Represents the 'Continuous Integration' part of the workflow, where the code changes are built and tested.
#
# This setup ensures that code changes are always integrated and tested (CI) when they're made on a new branch.

name: CI On Branch Creation
run-name: CI (On Branch Creation)

on:

create:

jobs:
CI:
name: on new branch
uses: ./.github/workflows/ci.yml # reusable workflow file path
49 changes: 49 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pull request workflow to run CI on PRs.
# Triggered on opened or reopened pull requests.
# Defines one job that reuses the ci.yml workflow.
# ci.yml will run lint, tests, coverage, build for the PR.

name: CI (on pull-request)
run-name: PR from branch ${{ github.head_ref }}

# Will run CI workflow on an opened or reopened PR for easy reference. For compilation, unit tests, code coverage etc.
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**.tsx' # Run CI on PRs that change .tsx files.
- '**.ts' # Run CI on PRs that change .ts files.
- '**.jsx' # Run CI on PRs that change .jsx files.
- 'app/**/*' # Run CI on PRs that change files in the app folder.
- 'components/**/*' # Run CI on PRs that change files in the components folder.
- 'styles/**/*' # Run CI on PRs that change files in the styles folder.
- '**/*.md' # Run CI on PRs that change .md files.
- '**/*.yml' # Run CI on PRs that change .yml files.
# Add more paths here if needed.

jobs:
Continuous-Integration:
name: on pull request
uses: ./.github/workflows/ci.yml

# set_status_check:
# needs: Continuous-Integration # This job depends on the previous job
# if: always() # tells it to run even if it fails that way we can get the status check
# runs-on: ubuntu-latest
# steps:
# - name: Set GitHub Status Check
# run: |
# STATE="success"
# if [[ "${{ needs.Continuous-Integration.result }}" != "success" ]]; then
# STATE="failure"
# fi
# curl -X POST \
# -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github.v3+json" \
# https://api.github.com/repos/SeattleColleges/nsc-events-nextjs/statuses/${{ github.sha }} \
# -d "{
# \"state\": \"$STATE\",
# \"context\": \"ci.yml\",
# \"description\": \"CI $STATE\",
# \"target_url\": \"https://github.com/SeattleColleges/nsc-events-nextjs/actions/runs/${{ github.run_id }}\"
# }"
55 changes: 55 additions & 0 deletions .github/workflows/on-push-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow defines a CI/CD pipeline for the staging environment

# name: The name of the workflow
# run-name: The name that will display in the GitHub UI for each run

# on.push.branches: This workflow will run on pushes to the "staging" branch

# on.pull_request: This workflow will run on pull requests targeting the "staging" branch
# on.pull_request.types: It will run when pull requests are closed

# jobs.CI: Runs the CI workflow defined in .github/workflows/ci.yml
# CI.if: Only runs if the PR was merged or if it was a push (not a PR)

# jobs.CD: Runs the CD workflow defined in .github/workflows/cd-production.yml
# CD.needs: Runs after the "CI" job completes successfully
# CD.if: Only runs if the PR was merged or if it was a push (not a PR)

name: Main Staging Workflow
run-name: CI-CD Staging

on:
push:
branches: [ "staging"]

pull_request:
branches: [ "staging" ]

types:
- closed
permissions: # we can tighten this up in settings but are able to set customize permissions against GITHUB_TOKEN in Yaml
contents: write
actions: write
checks: write
deployments: write
discussions: write
issues: write
pages: read
packages: write
pull-requests: write
repository-projects: write
security-events: write
statuses: write
jobs:
# redundant check to ensure CI passes before deployment
CI:
if: github.event.pull_request.merged == true || github.event_name == 'push'
name: Push to staging
uses: ./.github/workflows/ci.yml # reusable workflow file path


CD:
if: github.event.pull_request.merged == true || github.event_name == 'push'
name: Deploy to staging
uses: ./.github/workflows/cd-staging.yml # reusable workflow file path
needs: CI
53 changes: 53 additions & 0 deletions .github/workflows/sync-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Workflow to sync main branch changes into staging branch.
# Triggered on pushes to main branch.
# Jobs:
# - CI-preSyncCheck: Runs CI checks on main branch.
# - sync-branch:
# - Checks out staging branch
# - Merges main into staging with --no-ff
# - Pushes merged staging branch
# Merging with --no-ff creates a merge commit to track changes.

name: Sync Main to Staging
run-name: Merge main into Staging

on:
push:
branches: ["main"]
permissions: # we can tighten this up in settings but are able to set customize permissions against GITHUB_TOKEN in Yaml
contents: write
actions: write
checks: write
deployments: write
discussions: write
issues: write
pages: read
packages: write
pull-requests: write
repository-projects: write
security-events: write
statuses: write
jobs:
sync-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all history so we can perform a merge
ref: 'staging'
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git push origin staging
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Merge main(dev) -> staging # git merge main --no-ff -> no fast forwarding makes it easier to track changes
run: |
git checkout main
git pull
git checkout staging
git merge main --no-ff
git push origin staging

0 comments on commit 8280d7c

Please sign in to comment.