Skip to content

Commit

Permalink
update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinwheeler committed Dec 29, 2024
1 parent 3813231 commit 6c6cef0
Showing 1 changed file with 123 additions and 4 deletions.
127 changes: 123 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,149 @@ on:
- main

jobs:
test:
setup:
runs-on: ubuntu-latest

outputs:
node_version: ${{ steps.nvmrc.outputs.NODE_VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Read Node.js version from .nvmrc
id: nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV && echo "::set-output name=NODE_VERSION::$(cat .nvmrc)"

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}

- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ steps.nvmrc.outputs.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.nvmrc.outputs.NODE_VERSION }}-
- name: Install dependencies
run: npm install

- name: Compress node_modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: tar -czf node_modules.tar.gz node_modules

- name: Save node_modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
uses: actions/upload-artifact@v3
with:
name: node-modules
path: node_modules.tar.gz

unit-tests:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Run unit tests
run: npm test

lint:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Lint code
run: npm run lint

build:
needs: [unit-tests, lint]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Build project
run: npm run build

- name: Save build output
uses: actions/upload-artifact@v3
with:
name: build-output
path: build

cypress-tests:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ needs.setup.outputs.node_version }}

- name: Download and decompress node_modules
uses: actions/download-artifact@v3
with:
name: node-modules
path: .
- run: tar -xzf node_modules.tar.gz

- name: Fetch Netlify preview URL
id: fetch_netlify_url
run: |
PREVIEW_URL=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/deployments \
| jq -r '.[0].statuses_url')
DEPLOY_URL=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
$PREVIEW_URL \
| jq -r '.[0].target_url')
echo "DEPLOY_URL=${DEPLOY_URL}" >> $GITHUB_ENV
- name: Run Cypress tests
run: npx cypress run --env baseUrl=${{ env.DEPLOY_URL }}
env:
CYPRESS_baseUrl: ${{ env.DEPLOY_URL }}

0 comments on commit 6c6cef0

Please sign in to comment.