Skip to content

Commit b9e06c0

Browse files
committed
fixe front/back test ci
1 parent 61e6b14 commit b9e06c0

2 files changed

Lines changed: 127 additions & 170 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ jobs:
219219
key: ${{ steps.npm-cache.outputs.cache-key }}
220220
restore-keys: |
221221
npm-
222-
222+
223223
- name: Setup Node.js
224224
uses: actions/setup-node@v4
225225
with:
@@ -229,7 +229,7 @@ jobs:
229229

230230
- name: Install dependencies
231231
working-directory: frontend
232-
run: npm ci --prefer-offline --no-audit
232+
run: npm install && npm ci --prefer-offline --no-audit
233233

234234
- name: Run ESLint
235235
working-directory: frontend
@@ -326,7 +326,7 @@ jobs:
326326
name: Build Backend Image
327327
runs-on: ubuntu-latest
328328
needs: [backend, terraform-validate]
329-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/staging')
329+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/test' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/staging')
330330
permissions:
331331
contents: read
332332
packages: write
@@ -367,7 +367,7 @@ jobs:
367367
name: Build Frontend Image
368368
runs-on: ubuntu-latest
369369
needs: [frontend, terraform-validate]
370-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/staging')
370+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/test' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/staging')
371371
permissions:
372372
contents: read
373373
packages: write
Lines changed: 123 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,130 @@
11
name: Dependabot Auto-Merge
22

3-
# ═════════════════════════════════════════════════════════════════════════════
4-
# PURPOSE:
5-
# Automatically merge Dependabot PRs after CI passes
6-
# - Reduces manual dependency update burden
7-
# - Keeps dependencies current without overhead
8-
# - Maintains clean git history (squash merge)
9-
# - Only merges after all security checks pass
10-
#
11-
# TRIGGER:
12-
# - On pull requests from dependabot[bot]
13-
# - Only if actor is the Dependabot bot
14-
# - Only after CI workflow completes
15-
#
16-
# STRATEGY:
17-
# 1. Wait for CI checks to complete
18-
# 2. Verify all checks passed
19-
# 3. Enable auto-merge (squash strategy)
20-
# 4. GitHub auto-merges when ready
21-
#
22-
# SECURITY:
23-
# - No credentials used (bot has repo write access)
24-
# - CI/CD validates all changes before merge
25-
# - Security scans prevent malicious updates
26-
# - Audit trail in git history
27-
#
28-
# ═════════════════════════════════════════════════════════════════════════════
29-
303
on:
31-
pull_request:
32-
types: [opened, synchronize, reopened]
4+
pull_request:
5+
types: [opened, synchronize, reopened]
336

347
permissions:
35-
contents: write
36-
pull-requests: write
8+
contents: write
9+
pull-requests: write
3710

3811
jobs:
39-
auto-merge:
40-
name: Auto-Merge Dependabot PR
41-
runs-on: ubuntu-latest
42-
# Only run if pull request is from dependabot[bot]
43-
if: github.actor == 'dependabot[bot]'
44-
45-
steps:
46-
- name: Checkout code
47-
uses: actions/checkout@v4
48-
49-
- name: Wait for CI checks
50-
uses: actions/github-script@v7
51-
with:
52-
script: |
53-
const { owner, repo, number } = context.issue;
54-
55-
// Maximum wait time: 30 minutes
56-
const maxWaitTime = 30 * 60 * 1000;
57-
const startTime = Date.now();
58-
const pollInterval = 30 * 1000; // 30 seconds
59-
60-
while (Date.now() - startTime < maxWaitTime) {
61-
const { data: checkRuns } = await github.rest.checks.listForRef({
62-
owner,
63-
repo,
64-
ref: context.payload.pull_request.head.sha,
65-
});
66-
67-
const { data: statusCheck } = await github.rest.repos.getCombinedStatusForRef({
68-
owner,
69-
repo,
70-
ref: context.payload.pull_request.head.sha,
71-
});
72-
73-
console.log(`Check runs status: ${statusCheck.state}`);
74-
console.log(`Total checks: ${checkRuns.total_count}`);
75-
76-
checkRuns.check_runs.forEach(run => {
77-
console.log(` - ${run.name}: ${run.status} (${run.conclusion})`);
78-
});
79-
80-
// Check if all required checks completed
81-
const allCompleted = checkRuns.check_runs.every(
82-
run => run.status === 'completed'
83-
);
84-
85-
if (allCompleted) {
86-
// Check if all passed
87-
const allPassed = checkRuns.check_runs.every(
88-
run => run.conclusion === 'success'
89-
);
90-
91-
if (allPassed && statusCheck.state === 'success') {
92-
console.log('✅ All checks passed! Ready to merge.');
93-
return { success: true, state: statusCheck.state };
94-
} else if (!allPassed) {
95-
console.log('❌ Some checks failed. Will not auto-merge.');
96-
throw new Error('CI checks failed - auto-merge aborted');
97-
}
98-
}
99-
100-
console.log(`⏳ Waiting for checks to complete...`);
101-
await new Promise(resolve => setTimeout(resolve, pollInterval));
102-
}
103-
104-
throw new Error('Timeout waiting for CI checks (30 min)');
105-
106-
- name: Enable auto-merge (Squash)
107-
uses: actions/github-script@v7
108-
with:
109-
script: |
110-
const { owner, repo, number } = context.issue;
111-
112-
try {
113-
// Enable auto-merge with squash strategy
114-
const response = await github.rest.pulls.enableAutoMerge({
115-
owner,
116-
repo,
117-
pull_number: number,
118-
merge_method: 'squash',
119-
commit_title: 'Auto-merge Dependabot PR',
120-
commit_message: 'This PR was automatically merged by Dependabot auto-merge workflow after all CI checks passed.',
121-
});
122-
123-
console.log('✅ Auto-merge enabled (squash strategy)');
124-
console.log(` PR will merge when ready`);
125-
console.log(` Merge method: ${response.data.auto_merge.merge_method}`);
126-
} catch (error) {
127-
// Already merged or auto-merge already enabled
128-
if (error.message.includes('already merged') ||
129-
error.message.includes('already enabled')) {
130-
console.log('ℹ️ PR already merged or auto-merge already enabled');
131-
} else {
132-
throw error;
133-
}
134-
}
135-
136-
- name: Comment on PR
137-
uses: actions/github-script@v7
138-
with:
139-
script: |
140-
const { owner, repo, number } = context.issue;
141-
142-
try {
143-
await github.rest.issues.createComment({
144-
owner,
145-
repo,
146-
issue_number: number,
147-
body: `🤖 **Dependabot Auto-Merge**\n\n✅ All CI checks passed!\n\n**Auto-merge enabled** with squash strategy.\nThis PR will merge automatically when ready.\n\n**Merge details:**\n- Strategy: Squash merge\n- Branch: Will be deleted after merge\n- Git history: Clean linear history\n\n---\n*This comment was generated by the Dependabot auto-merge workflow.*`,
148-
});
149-
} catch (error) {
150-
// Comment might fail if PR already merged
151-
console.log('Could not post comment (PR may have been merged)');
152-
}
153-
154-
# Fallback notification if auto-merge fails
155-
notify-failure:
156-
name: Notify Auto-Merge Failure
157-
runs-on: ubuntu-latest
158-
needs: auto-merge
159-
if: failure() && github.actor == 'dependabot[bot]'
160-
161-
steps:
162-
- name: Post failure comment
163-
uses: actions/github-script@v7
164-
with:
165-
script: |
166-
const { owner, repo, number } = context.issue;
167-
168-
await github.rest.issues.createComment({
169-
owner,
170-
repo,
171-
issue_number: number,
172-
body: `⚠️ **Dependabot Auto-Merge Failed**\n\nThe auto-merge workflow encountered an issue:\n\n\`\`\`\n${{ failure() }}\n\`\`\`\n\n**Possible reasons:**\n- CI checks did not pass\n- Merge conflicts detected\n- Auto-merge not available on this branch\n- Timeout waiting for CI checks\n\n**Action required:** Please review CI logs and merge manually if appropriate.\n\n---\n*This comment was generated by the Dependabot auto-merge workflow.*`,
173-
});
12+
auto-merge:
13+
name: Auto-Merge Dependabot PR
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 40
16+
if: github.actor == 'dependabot[bot]'
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Wait for CI checks
25+
uses: actions/github-script@v7
26+
with:
27+
script: |
28+
const { owner, repo, number } = context.issue;
29+
const maxWaitTime = 30 * 60 * 1000; // 30 minutes
30+
const pollInterval = 30 * 1000; // 30 seconds
31+
const startTime = Date.now();
32+
33+
while (Date.now() - startTime < maxWaitTime) {
34+
const { data: checkRuns } = await github.rest.checks.listForRef({
35+
owner,
36+
repo,
37+
ref: context.payload.pull_request.head.sha,
38+
});
39+
40+
const { data: statusCheck } = await github.rest.repos.getCombinedStatusForRef({
41+
owner,
42+
repo,
43+
ref: context.payload.pull_request.head.sha,
44+
});
45+
46+
console.log(`Check runs status: ${statusCheck.state}`);
47+
checkRuns.check_runs.forEach(run => {
48+
console.log(` - ${run.name}: ${run.status} (${run.conclusion})`);
49+
});
50+
51+
const allCompleted = checkRuns.check_runs.every(
52+
run => run.status === 'completed'
53+
);
54+
55+
if (allCompleted) {
56+
const allPassed = checkRuns.check_runs.every(
57+
run => run.conclusion === 'success'
58+
);
59+
60+
if (allPassed && statusCheck.state === 'success') {
61+
console.log('✅ All checks passed! Ready to merge.');
62+
return;
63+
} else if (!allPassed) {
64+
throw new Error('❌ Some checks failed. Auto-merge aborted.');
65+
}
66+
}
67+
68+
console.log(`⏳ Waiting for checks to complete...`);
69+
await new Promise(resolve => setTimeout(resolve, pollInterval));
70+
}
71+
72+
throw new Error('⏰ Timeout waiting for CI checks (30 min)');
73+
74+
- name: Enable auto-merge (Squash)
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const { owner, repo, number } = context.issue;
79+
80+
try {
81+
await github.rest.pulls.enableAutoMerge({
82+
owner,
83+
repo,
84+
pull_number: number,
85+
merge_method: 'squash',
86+
commit_title: 'Auto-merge Dependabot PR',
87+
commit_message: 'This PR was automatically merged by Dependabot auto-merge workflow after all CI checks passed.',
88+
});
89+
console.log('✅ Auto-merge enabled (squash strategy)');
90+
} catch (error) {
91+
if (error.message.includes('already merged') || error.message.includes('already enabled')) {
92+
console.log('ℹ️ PR already merged or auto-merge already enabled');
93+
} else {
94+
throw error;
95+
}
96+
}
97+
98+
- name: Comment on PR
99+
uses: actions/github-script@v7
100+
with:
101+
script: |
102+
const { owner, repo, number } = context.issue;
103+
try {
104+
await github.rest.issues.createComment({
105+
owner,
106+
repo,
107+
issue_number: number,
108+
body: `🤖 **Dependabot Auto-Merge**\n\n✅ All CI checks passed!\n**Auto-merge enabled** (squash strategy).\nThis PR will merge automatically when ready.\n\n---\n*This comment was generated by Dependabot auto-merge workflow.*`,
109+
});
110+
} catch (error) {
111+
console.log('Could not post comment (PR may already be merged).');
112+
}
113+
114+
notify-failure:
115+
name: Notify Auto-Merge Failure
116+
runs-on: ubuntu-latest
117+
needs: auto-merge
118+
if: needs.auto-merge.result == 'failure' && github.actor == 'dependabot[bot]'
119+
steps:
120+
- name: Post failure comment
121+
uses: actions/github-script@v7
122+
with:
123+
script: |
124+
const { owner, repo, number } = context.issue;
125+
await github.rest.issues.createComment({
126+
owner,
127+
repo,
128+
issue_number: number,
129+
body: `⚠️ **Dependabot Auto-Merge Failed**\n\nThe auto-merge workflow encountered an issue.\n\n**Possible reasons:**\n- CI checks did not pass\n- Merge conflicts detected\n- Auto-merge not available on this branch\n- Timeout waiting for CI checks\n\n**Action required:** Please review CI logs and merge manually if appropriate.\n\n---\n*This comment was generated by Dependabot auto-merge workflow.*`,
130+
});

0 commit comments

Comments
 (0)