diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..4c7851b1 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/.github/workflows/cleanup-cache-after-merge.yaml b/.github/workflows/cleanup-cache-after-merge.yaml new file mode 100644 index 00000000..29fc5512 --- /dev/null +++ b/.github/workflows/cleanup-cache-after-merge.yaml @@ -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 }} diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml new file mode 100644 index 00000000..b99cd6f8 --- /dev/null +++ b/.github/workflows/preview.yaml @@ -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 }} diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml new file mode 100644 index 00000000..0627a98a --- /dev/null +++ b/.github/workflows/production.yaml @@ -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 }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml deleted file mode 100644 index a5261cc6..00000000 --- a/.github/workflows/test-coverage.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: Test Coverage - -env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - -on: push - -jobs: - build: - 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: ๐Ÿ”ง Install dependencies - 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 diff --git a/package.json b/package.json index ccef02e3..4d21ccc0 100644 --- a/package.json +++ b/package.json @@ -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": {