Skip to content

Commit 314789d

Browse files
feat: updated Add Expense screen, add backend Dockerfile, and set up CI/CD workflows.
1 parent 7204fef commit 314789d

11 files changed

Lines changed: 177 additions & 201 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
name: CI
22

33
on:
4-
push:
5-
branches: [main]
64
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ci-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
715

816
jobs:
9-
typecheck:
17+
validate:
1018
runs-on: ubuntu-latest
19+
timeout-minutes: 30
20+
1121
steps:
1222
- name: Checkout
1323
uses: actions/checkout@v4
1424

1525
- name: Setup pnpm
1626
uses: pnpm/action-setup@v4
1727
with:
18-
version: 10
28+
version: 10.6.1
1929

2030
- name: Setup Node
2131
uses: actions/setup-node@v4
@@ -29,170 +39,32 @@ jobs:
2939
path: |
3040
.turbo
3141
node_modules/.cache/turbo
32-
key: turbo-${{ runner.os }}-${{ github.ref_name }}-${{ github.sha }}
42+
key: turbo-${{ runner.os }}-${{ github.ref_name }}-${{ hashFiles('pnpm-lock.yaml', 'turbo.json', 'apps/**/package.json', 'packages/**/package.json', 'infra/**/package.json') }}
3343
restore-keys: |
3444
turbo-${{ runner.os }}-${{ github.ref_name }}-
3545
turbo-${{ runner.os }}-
3646
3747
- name: Install dependencies
38-
run: pnpm install --frozen-lockfile=false
48+
run: pnpm install --frozen-lockfile
3949

40-
- name: Prisma Generate
50+
- name: Generate Prisma client
4151
run: pnpm --filter backend prisma:generate
4252

43-
- name: Typecheck
44-
run: pnpm lint
45-
46-
lint:
47-
runs-on: ubuntu-latest
48-
steps:
49-
- name: Checkout
50-
uses: actions/checkout@v4
51-
52-
- name: Setup pnpm
53-
uses: pnpm/action-setup@v4
54-
with:
55-
version: 10
56-
57-
- name: Setup Node
58-
uses: actions/setup-node@v4
59-
with:
60-
node-version: 20
61-
cache: pnpm
62-
63-
- name: Install dependencies
64-
run: pnpm install --frozen-lockfile=false
65-
6653
- name: Lint
6754
run: pnpm lint
6855

69-
test:
70-
runs-on: ubuntu-latest
71-
steps:
72-
- name: Checkout
73-
uses: actions/checkout@v4
74-
75-
- name: Setup pnpm
76-
uses: pnpm/action-setup@v4
77-
with:
78-
version: 10
79-
80-
- name: Setup Node
81-
uses: actions/setup-node@v4
82-
with:
83-
node-version: 20
84-
cache: pnpm
85-
86-
- name: Install dependencies
87-
run: pnpm install --frozen-lockfile=false
88-
89-
- name: Run Unit Tests
56+
- name: Test
9057
run: pnpm test
9158

92-
- name: Backend Coverage
93-
run: pnpm --filter backend test -- --coverage
59+
- name: Build
60+
run: pnpm build
9461

95-
- name: Upload Coverage Artifacts
62+
- name: Upload coverage
63+
if: always()
9664
uses: actions/upload-artifact@v4
9765
with:
9866
name: coverage
67+
if-no-files-found: ignore
9968
path: |
10069
apps/backend/coverage
10170
apps/mobile/coverage
102-
103-
build:
104-
runs-on: ubuntu-latest
105-
needs: [typecheck, lint, test]
106-
steps:
107-
- name: Checkout
108-
uses: actions/checkout@v4
109-
110-
- name: Setup pnpm
111-
uses: pnpm/action-setup@v4
112-
with:
113-
version: 10
114-
115-
- name: Setup Node
116-
uses: actions/setup-node@v4
117-
with:
118-
node-version: 20
119-
cache: pnpm
120-
121-
- name: Install dependencies
122-
run: pnpm install --frozen-lockfile=false
123-
124-
- name: Prisma Generate
125-
run: pnpm --filter backend prisma:generate
126-
127-
- name: Build backend
128-
run: pnpm --filter backend build
129-
130-
- name: Build mobile
131-
run: pnpm --filter mobile build
132-
133-
- name: Build web
134-
run: pnpm --filter web build
135-
136-
security-audit:
137-
runs-on: ubuntu-latest
138-
steps:
139-
- name: Checkout
140-
uses: actions/checkout@v4
141-
142-
- name: Setup pnpm
143-
uses: pnpm/action-setup@v4
144-
with:
145-
version: 10
146-
147-
- name: Setup Node
148-
uses: actions/setup-node@v4
149-
with:
150-
node-version: 20
151-
cache: pnpm
152-
153-
- name: Install dependencies
154-
run: pnpm install --frozen-lockfile=false
155-
156-
- name: Security audit
157-
run: pnpm audit --prod
158-
159-
dependency-review:
160-
if: github.event_name == 'pull_request'
161-
runs-on: ubuntu-latest
162-
permissions:
163-
contents: read
164-
pull-requests: write
165-
steps:
166-
- name: Checkout
167-
uses: actions/checkout@v4
168-
- name: Dependency review
169-
uses: actions/dependency-review-action@v4
170-
171-
e2e:
172-
runs-on: ubuntu-latest
173-
needs: [build]
174-
steps:
175-
- name: Checkout
176-
uses: actions/checkout@v4
177-
178-
- name: Setup pnpm
179-
uses: pnpm/action-setup@v4
180-
with:
181-
version: 10
182-
183-
- name: Setup Node
184-
uses: actions/setup-node@v4
185-
with:
186-
node-version: 20
187-
cache: pnpm
188-
189-
- name: Install dependencies
190-
run: pnpm install --frozen-lockfile=false
191-
192-
- name: Install Playwright Browsers
193-
run: pnpm exec playwright install --with-deps chromium
194-
195-
- name: Run E2E tests
196-
env:
197-
RUN_E2E: 'false'
198-
run: pnpm e2e

.github/workflows/deploy.yml

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
name: Deploy
1+
name: Deploy Main
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_run:
5+
workflows:
6+
- CI
7+
types:
8+
- completed
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
concurrency:
16+
group: deploy-main
17+
cancel-in-progress: true
718

819
env:
920
AWS_REGION: ap-south-1
@@ -14,19 +25,28 @@ env:
1425

1526
jobs:
1627
deploy:
28+
if: >-
29+
github.event_name == 'workflow_dispatch' ||
30+
(github.event.workflow_run.conclusion == 'success' &&
31+
github.event.workflow_run.head_branch == 'main')
1732
runs-on: ubuntu-latest
18-
permissions:
19-
id-token: write
20-
contents: read
33+
timeout-minutes: 45
2134

2235
steps:
23-
- name: Checkout
36+
- name: Checkout workflow_run commit
37+
if: github.event_name == 'workflow_run'
38+
uses: actions/checkout@v4
39+
with:
40+
ref: ${{ github.event.workflow_run.head_sha }}
41+
42+
- name: Checkout manual dispatch commit
43+
if: github.event_name == 'workflow_dispatch'
2444
uses: actions/checkout@v4
2545

2646
- name: Setup pnpm
2747
uses: pnpm/action-setup@v4
2848
with:
29-
version: 10
49+
version: 10.6.1
3050

3151
- name: Setup Node
3252
uses: actions/setup-node@v4
@@ -35,40 +55,58 @@ jobs:
3555
cache: pnpm
3656

3757
- name: Install dependencies
38-
run: pnpm install --frozen-lockfile=false
58+
run: pnpm install --frozen-lockfile
59+
60+
- name: Generate Prisma client
61+
run: pnpm --filter backend prisma:generate
3962

40-
- name: Test
41-
run: pnpm test
63+
- name: Verify backend tests
64+
run: pnpm --filter backend test -- --runInBand --passWithNoTests
4265

43-
- name: Build
44-
run: pnpm build
66+
- name: Verify backend build
67+
run: pnpm --filter backend build
4568

46-
- name: Configure AWS credentials
69+
- name: Configure AWS credentials with OIDC
70+
if: ${{ secrets.AWS_ROLE_TO_ASSUME != '' }}
71+
uses: aws-actions/configure-aws-credentials@v4
72+
with:
73+
aws-region: ${{ env.AWS_REGION }}
74+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
75+
76+
- name: Configure AWS credentials with access keys
77+
if: ${{ secrets.AWS_ROLE_TO_ASSUME == '' }}
4778
uses: aws-actions/configure-aws-credentials@v4
4879
with:
4980
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
5081
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5182
aws-region: ${{ env.AWS_REGION }}
5283

53-
- name: Login to ECR
84+
- name: Login to Amazon ECR
5485
id: ecr
5586
uses: aws-actions/amazon-ecr-login@v2
5687

5788
- name: Build and push backend image
5889
id: image
5990
env:
6091
ECR_REGISTRY: ${{ steps.ecr.outputs.registry }}
61-
IMAGE_TAG: ${{ github.sha }}
92+
IMAGE_TAG: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
93+
run: |
94+
docker build -f apps/backend/Dockerfile -t "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" .
95+
docker tag "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" "$ECR_REGISTRY/$ECR_REPOSITORY:latest"
96+
docker push "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
97+
docker push "$ECR_REGISTRY/$ECR_REPOSITORY:latest"
98+
echo "image_uri=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT"
99+
100+
- name: Render next ECS task definition
101+
env:
102+
IMAGE_URI: ${{ steps.image.outputs.image_uri }}
62103
run: |
63-
docker build -f apps/backend/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
64-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
65-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
66-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
67-
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
104+
TASK_DEF_ARN="$(aws ecs describe-services --cluster "$ECS_CLUSTER" --services "$ECS_SERVICE" --query 'services[0].taskDefinition' --output text)"
105+
aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --query 'taskDefinition' > task-definition.json
106+
jq 'del(.taskDefinitionArn,.revision,.status,.requiresAttributes,.compatibilities,.registeredAt,.registeredBy) | .containerDefinitions |= map(if .name == env.CONTAINER_NAME then .image = env.IMAGE_URI else . end)' task-definition.json > task-definition.rendered.json
68107
69-
- name: Force ECS service deployment
108+
- name: Register task definition and deploy
70109
run: |
71-
aws ecs update-service \
72-
--cluster $ECS_CLUSTER \
73-
--service $ECS_SERVICE \
74-
--force-new-deployment
110+
TASK_DEF_ARN="$(aws ecs register-task-definition --cli-input-json file://task-definition.rendered.json --query 'taskDefinition.taskDefinitionArn' --output text)"
111+
aws ecs update-service --cluster "$ECS_CLUSTER" --service "$ECS_SERVICE" --task-definition "$TASK_DEF_ARN" --force-new-deployment
112+
aws ecs wait services-stable --cluster "$ECS_CLUSTER" --services "$ECS_SERVICE"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist
77
coverage
88
.agents
99
.agent
10+
.turbo

apps/backend/.turbo/turbo-test.log

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22
> backend@1.0.0 test D:\ak\project\FairShare\apps\backend
33
> jest --runInBand --passWithNoTests
44

5-
PASS src/expenses/expenses.integration.spec.ts (13.138 s)
6-
PASS src/settlements/settlements.integration.spec.ts
7-
PASS src/simplify/simplify.service.spec.ts
8-
PASS src/expenses/expense-calculator.spec.ts
9-
PASS src/settlements/settlements.service.spec.ts
10-
(node:16276) NOTE: The AWS SDK for JavaScript (v2) has reached end-of-support.
5+
PASS src/settlements/settlements.integration.spec.ts (30.803 s)
6+
(node:22644) NOTE: The AWS SDK for JavaScript (v2) has reached end-of-support.
117
It will no longer receive updates or releases.
128

139
Please migrate your code to use AWS SDK for JavaScript (v3).
1410
For more information, check the blog post at https://a.co/cUPnyil
1511
(Use `node --trace-warnings ...` to show where the warning was created)
1612
PASS src/receipts/receipts.service.spec.ts
13+
PASS src/expenses/expenses.integration.spec.ts
1714
PASS src/expenses/expenses.service.spec.ts
18-
PASS src/balances/balances.service.spec.ts
15+
PASS src/settlements/settlements.service.spec.ts
1916
PASS src/groups/groups.service.spec.ts
17+
PASS src/notifications/notifications.service.spec.ts
18+
PASS src/balances/balances.service.spec.ts
2019
PASS src/users/users.service.spec.ts
20+
PASS src/simplify/simplify.service.spec.ts
21+
PASS src/activity/activity.service.spec.ts
22+
PASS src/expenses/expense-calculator.spec.ts
2123

22-
Test Suites: 10 passed, 10 total
23-
Tests: 10 passed, 10 total
24+
Test Suites: 12 passed, 12 total
25+
Tests: 16 passed, 16 total
2426
Snapshots: 0 total
25-
Time: 18.024 s
27+
Time: 38.565 s
2628
Ran all test suites.

0 commit comments

Comments
 (0)