-
Notifications
You must be signed in to change notification settings - Fork 39
103 lines (92 loc) · 3.76 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Run Tests
on:
push:
branches: ['**']
pull_request:
branches: ['**']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
env:
OSM_URI: ${{ secrets.OSM_URI }}
JWT_SECRET: test123
steps:
- uses: actions/checkout@v3
- name: Setup JS Runtime environment
uses: ./.github/actions/setup-js-runtime
- name: Find or create comment
uses: actions/github-script@v6
id: find_or_create_comment
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commentIdentifier = '<!-- test_results -->';
const commentBody = `${commentIdentifier}\n🚀 Running tests... Please wait for the results! 🕐`;
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingComment = comments.data.find(comment => comment.body.startsWith(commentIdentifier));
if (existingComment) {
core.setOutput('comment_id', existingComment.id);
} else {
const { data: { id: commentId } } = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
core.setOutput('comment_id', commentId);
}
- name: Install dependencies
uses: ./.github/actions/install-deps
- name: Setup API
run: cp -n server/wrangler.toml.example server/wrangler.toml
- name: Run tests
id: run_tests
run: yarn test
continue-on-error: true
- name: Update comment with test results
uses: actions/github-script@v6
if: always() && github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commentIdentifier = '<!-- test_results -->';
const commentId = process.env.COMMENT_ID;
const testLogs = `${{ steps.run_tests.outputs.stdout }}\n${{ steps.run_tests.outputs.stderr }}`;
const testStatus = `${{ steps.run_tests.outcome }}`;
const workflowUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const includeTestLogs = false; // Set this to true when you want to include the test logs
let commentBody = `${commentIdentifier}\n`;
let emoji = '';
if (testStatus === 'success') {
commentBody += '✅ Tests passed successfully! 🎉\n\n';
emoji = '💚';
} else {
commentBody += '❌ Tests failed for this pull request. 😞\n\n';
emoji = '❤️';
}
commentBody += `[View Test Workflow](${workflowUrl})\n\n`;
if (includeTestLogs) {
commentBody += `<details><summary>Test Logs</summary>\n\n\`\`\`\n${testLogs}\n\`\`\`\n</details>`;
}
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: commentBody
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [`tests-${testStatus}${emoji}`]
});
env:
COMMENT_ID: ${{ steps.find_or_create_comment.outputs.comment_id }}