Skip to content

Commit 9dde3a5

Browse files
authored
Merge pull request #2 from mimi030/dev
Add Development CI Pipeline with Linting and Automated Testing
2 parents 0d4e02e + 54a6e91 commit 9dde3a5

File tree

25 files changed

+504
-77
lines changed

25 files changed

+504
-77
lines changed

.github/workflows/dev.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
pull_request:
8+
branches:
9+
- dev
10+
11+
jobs:
12+
backend:
13+
14+
runs-on: ubuntu-latest
15+
strategy:
16+
max-parallel: 4
17+
matrix:
18+
python-version: [3.11]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install Backend Dependencies
28+
working-directory: task_management_system
29+
run: |
30+
python -m venv venv
31+
source venv/bin/activate
32+
python -m pip install --upgrade pip
33+
pip install -r requirements.txt
34+
pip install flake8 # Install Flake8 for linting
35+
36+
- name: Set Backend Environment Variables
37+
run: |
38+
echo "SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }}" >> $GITHUB_ENV
39+
echo "DEBUG=True" >> $GITHUB_ENV
40+
echo "ALLOWED_HOSTS=${{ secrets.DJANGO_ALLOWED_HOSTS }}" >> $GITHUB_ENV
41+
42+
- name: Run Tests
43+
working-directory: task_management_system
44+
run: |
45+
source venv/bin/activate
46+
python manage.py test
47+
48+
frontend:
49+
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
56+
- name: Setup Node.js environment
57+
uses: actions/setup-node@v4.0.4
58+
with:
59+
node-version: '18' # optional
60+
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
61+
62+
- name: Install Frontend Dependencies
63+
working-directory: frontend
64+
run: npm install
65+
66+
- name: Set Frontend Envioronment Variables
67+
run: |
68+
echo "NEXT_PUBLIC_API_BASE_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> $GITHUB_ENV
69+
70+
- name: Build Frontend
71+
working-directory: frontend
72+
run: npm run build
73+
74+
playwright-tests:
75+
76+
timeout-minutes: 60
77+
78+
runs-on: ubuntu-latest
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
shardIndex: [1, 2, 3, 4]
83+
shardTotal: [4]
84+
85+
steps:
86+
- uses: actions/checkout@v4
87+
- uses: actions/setup-node@v4
88+
with:
89+
node-version: lts/*
90+
91+
- name: Install Frontend Dependencies
92+
working-directory: frontend
93+
run: npm install
94+
95+
- name: Install Playwright Browsers
96+
run: |
97+
npx playwright install --with-deps
98+
99+
- name: Start Frontend Server
100+
working-directory: frontend
101+
run: |
102+
npm run dev &
103+
echo $! > frontend_pid.txt
104+
105+
- name: Run Playwright Tests
106+
working-directory: frontend
107+
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
108+
109+
- name: Upload Playwright Test Reports
110+
if: ${{ !cancelled() }}
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: blob-report-${{ matrix.shardIndex }}
114+
path: frontend/blob-report
115+
retention-days: 1
116+
117+
merge-reports:
118+
# Merge reports after playwright-tests, even if some shards have failed
119+
if: ${{ !cancelled() }}
120+
needs: [playwright-tests]
121+
122+
runs-on: ubuntu-latest
123+
124+
steps:
125+
- uses: actions/checkout@v4
126+
- uses: actions/setup-node@v4
127+
with:
128+
node-version: lts/*
129+
- name: Install dependencies
130+
working-directory: frontend
131+
run: npm ci
132+
133+
- name: Download blob reports from GitHub Actions Artifacts
134+
uses: actions/download-artifact@v4
135+
with:
136+
path: frontend/all-blob-reports
137+
pattern: blob-report-*
138+
merge-multiple: true
139+
140+
- name: Merge into HTML Report
141+
working-directory: frontend
142+
run: npx playwright merge-reports --reporter html ./all-blob-reports
143+
144+
- name: Upload HTML report
145+
uses: actions/upload-artifact@v4
146+
with:
147+
name: html-report--attempt-${{ github.run_attempt }}
148+
path: frontend/playwright-report
149+
retention-days: 14

.github/workflows/lint.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Lint Code
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- main
8+
pull_request:
9+
branches:
10+
- dev
11+
- main
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
python-version: [3.11]
20+
node-version: [18]
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
# Set up Python for Flake8
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v3
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Install Python Dependencies
32+
run: |
33+
cd task_management_system
34+
python -m pip install --upgrade pip
35+
pip install flake8
36+
37+
- name: Run Flake8
38+
run: |
39+
cd task_management_system
40+
flake8 .
41+
42+
# Set up Node.js for ESLint
43+
- name: Set up Node.js ${{ matrix.node-version }}
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: ${{ matrix.node-version }}
47+
48+
- name: Install Frontend Dependencies
49+
run: |
50+
cd frontend
51+
npm install
52+
53+
- name: Run ESLint
54+
run: |
55+
cd frontend
56+
npx eslint . --ext .ts,.tsx

frontend/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
node_modules/
38+
/test-results/
39+
/playwright-report/
40+
/blob-report/
41+
/playwright/.cache/

frontend/package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"swr": "^2.2.5"
2424
},
2525
"devDependencies": {
26+
"@playwright/test": "^1.48.0",
2627
"@types/js-cookie": "^3.0.6",
2728
"@types/node": "^20",
2829
"@types/react": "^18",

frontend/playwright.config.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
/* Run tests in files in parallel */
17+
fullyParallel: true,
18+
/* Fail the build on CI if you accidentally left test.only in the source code. */
19+
forbidOnly: !!process.env.CI,
20+
/* Retry on CI only */
21+
retries: process.env.CI ? 2 : 0,
22+
/* Opt out of parallel tests on CI. */
23+
workers: process.env.CI ? 1 : undefined,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: process.env.CI ? 'blob' : 'html',
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('/')`. */
29+
// baseURL: 'http://127.0.0.1:3000',
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: 'on-first-retry',
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: 'chromium',
39+
use: { ...devices['Desktop Chrome'] },
40+
},
41+
42+
{
43+
name: 'firefox',
44+
use: { ...devices['Desktop Firefox'] },
45+
},
46+
47+
{
48+
name: 'webkit',
49+
use: { ...devices['Desktop Safari'] },
50+
},
51+
52+
/* Test against mobile viewports. */
53+
// {
54+
// name: 'Mobile Chrome',
55+
// use: { ...devices['Pixel 5'] },
56+
// },
57+
// {
58+
// name: 'Mobile Safari',
59+
// use: { ...devices['iPhone 12'] },
60+
// },
61+
62+
/* Test against branded browsers. */
63+
// {
64+
// name: 'Microsoft Edge',
65+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
66+
// },
67+
// {
68+
// name: 'Google Chrome',
69+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
70+
// },
71+
],
72+
73+
/* Run your local dev server before starting the tests */
74+
// webServer: {
75+
// command: 'npm run start',
76+
// url: 'http://127.0.0.1:3000',
77+
// reuseExistingServer: !process.env.CI,
78+
// },
79+
});

0 commit comments

Comments
 (0)