Skip to content

Commit

Permalink
👷 update Github action
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnsonMao committed Dec 28, 2023
1 parent 9e5a9f1 commit 3c0de03
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 33 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI Workflow

on:
pull_request:
branches: '**'
workflow_dispatch:

jobs:
init:
name: Initial common steps
runs-on: ubuntu-latest

steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: ⚙️ Setup PNPM
uses: pnpm/action-setup@v2.2.1
with:
version: 8

- name: 📝 Cache dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: node_modules
key: deps-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: 🔧 Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile

test:
name: Test Coverage
runs-on: ubuntu-latest
environment: Test
timeout-minutes: 10
needs: init

- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: ⚙️ Setup PNPM
uses: pnpm/action-setup@v2.2.1
with:
version: 8

- name: 📝 Cache dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: node_modules
key: deps-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: 🔧 Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile

- name: 🧪 Test Coverage
run: pnpm test:coverage

- name: 📈 Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
54 changes: 54 additions & 0 deletions .github/workflows/cleanup-cache-after-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Cleanup Branch Resource

permissions:
actions: write
contents: read

on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest

steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: 🗑️ Cleanup cache
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
echo "Cache keys for PR: $cacheKeysForPR"
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
echo "- ${cacheKey}"
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ github.token }}

- name: ⚰️ Delete artifacts
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
artifacts=$(gh api /repos/${{ github.repository }}/actions/artifacts --paginate)
for artifact in $(echo "$artifacts" | jq -r ".artifacts[] | select(.name | startswith(\"PR-$PR_NUMBER-\")) | .id"); do
echo "filtered artifact: $artifact"
gh api -X DELETE /repos/${{ github.repository }}/actions/artifacts/$artifact
done
env:
GH_TOKEN: ${{ github.token }}
85 changes: 85 additions & 0 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Vercel Preview Deployment

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

on:
push:
branches-ignore:
- main

jobs:
init:
name: Initial common steps
runs-on: ubuntu-latest

steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: ⚙️ Setup PNPM
uses: pnpm/action-setup@v2.2.1
with:
version: 8

- name: 📝 Cache dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: node_modules
key: deps-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: 🔧 Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile

test:
name: Test
runs-on: ubuntu-latest
needs: init

- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: ⚙️ Setup PNPM
uses: pnpm/action-setup@v2.2.1
with:
version: 8

- name: 📝 Cache dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: node_modules
key: deps-node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: 🔧 Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile

- name: 🧪 Test
run: pnpm test

preview:
name: Deploy preview
runs-on: ubuntu-latest
environment: Preview
timeout-minutes: 10
needs: test

steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: 🔧 Install Vercel CLI
run: npm install --global vercel@latest

- name: 👔 Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: 👷 Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

- name: 🚀 Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Vercel Production Deployment

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

on:
push:
branches:
- main

jobs:
production:
name: Deploy production
runs-on: ubuntu-latest
environment: Production
timeout-minutes: 10

steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3

- name: 🔧 Install Vercel CLI
run: npm install --global vercel@latest

- name: 👔 Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

- name: 👷 Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

- name: 🚀 Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
32 changes: 0 additions & 32 deletions .github/workflows/test-coverage.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest --watch",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"dependencies": {
Expand Down

0 comments on commit 3c0de03

Please sign in to comment.