-
Notifications
You must be signed in to change notification settings - Fork 951
138 lines (120 loc) · 4.45 KB
/
Copy pathbuild-tests.yml
File metadata and controls
138 lines (120 loc) · 4.45 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Build Tests
run-name: Build and compile all Office Add-in samples
on:
pull_request:
branches:
- main
paths:
- 'Samples/**'
- '!Samples/**/*.md'
- '.github/workflows/build-tests.yml'
- 'scripts/test-builds.sh'
- 'scripts/build-test-config.json'
workflow_dispatch:
jobs:
build-tests:
name: Test builds (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
node-version: ['22', '24']
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Update npm to consistent version
run: npm install -g npm@11
- name: Cache npm downloads
uses: actions/cache@v5
with:
path: ~/.npm
# Use weekly cache key instead of hashing all package-lock.json files (too slow)
# This caches npm's download tarballs, not node_modules, so sharing across samples is fine
key: npm-${{ runner.os }}-${{ matrix.node-version }}-${{ github.run_number }}
restore-keys: |
npm-${{ runner.os }}-${{ matrix.node-version }}-
npm-${{ runner.os }}-
- name: Make test script executable
run: chmod +x ./scripts/test-builds.sh
- name: Run build tests
id: build-tests
run: ./scripts/test-builds.sh
continue-on-error: true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: build-test-results-node-${{ matrix.node-version }}
path: |
build-test-results.json
build-test-summary.md
build-logs/
retention-days: 30
- name: Comment PR with results
if: always() && github.event_name == 'pull_request' && matrix.node-version == '24'
continue-on-error: true # Don't fail workflow if commenting fails (e.g., permission issues)
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read test results
let summary = 'Build test results not found';
try {
summary = fs.readFileSync('build-test-summary.md', 'utf8');
} catch (error) {
summary = '⚠️ Failed to read test results';
}
// Post comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
// Find existing bot comment
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Build Test Results')
);
const commentBody = `## Build Test Results (Node.js ${{ matrix.node-version }})\n\n${summary}`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Check test results
if: always()
run: |
# Exit with error if tests failed (after uploading artifacts and commenting)
if [ -f "build-test-results.json" ]; then
failed=$(jq -r '.failed' build-test-results.json)
unexpected_failures=$(jq -r '.unexpected_failures' build-test-results.json)
echo "Failed builds: $failed"
echo "Unexpected failures: $unexpected_failures"
if [ "$unexpected_failures" -gt 0 ]; then
echo "❌ $unexpected_failures unexpected build failure(s) detected"
exit 1
else
echo "✅ All builds passed or failed as expected"
exit 0
fi
else
echo "❌ Test results file not found"
exit 1
fi