Build and compile all Office Add-in samples #193
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |