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 29, 2023
1 parent 9e5a9f1 commit cc2fdba
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 33 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI Workflow

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
pull_request:
branches-ignore:
- 'main'
paths:
- 'src/**'
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

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

- 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 }}
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 cc2fdba

Please sign in to comment.