diff --git a/.github/workflow-scripts/collectNightlyOutcomes.js b/.github/workflow-scripts/collectNightlyOutcomes.js new file mode 100644 index 00000000000..b735de59241 --- /dev/null +++ b/.github/workflow-scripts/collectNightlyOutcomes.js @@ -0,0 +1,74 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +const fs = require('fs'); +const path = require('path'); + +function readOutcomes() { + const baseDir = '/tmp'; + let outcomes = {}; + fs.readdirSync(baseDir).forEach(file => { + const fullPath = path.join(baseDir, file); + if (fullPath.endsWith('outcome') && fs.statSync(fullPath).isDirectory) { + fs.readdirSync(fullPath).forEach(subFile => { + const subFullPath = path.join(fullPath, subFile); + if (subFullPath.endsWith('outcome')) { + const [library, status] = String(fs.readFileSync(subFullPath, 'utf8')) + .trim() + .split(':'); + const platform = subFile.includes('android') ? 'Android' : 'iOS'; + console.log( + `[${platform}] ${library} completed with status ${status}`, + ); + outcomes[library.trim()] = { + platform, + status: status.trim(), + }; + } + }); + } else if (fullPath.endsWith('outcome')) { + const [library, status] = String(fs.readFileSync(fullPath, 'utf8')) + .trim() + .split(':'); + const platform = file.includes('android') ? 'Android' : 'iOS'; + console.log(`[${platform}] ${library} completed with status ${status}`); + outcomes[library.trim()] = { + platform, + status: status.trim(), + }; + } + }); + return outcomes; +} + +function printFailures(outcomes) { + console.log('Printing failures...'); + let failures = 0; + Object.entries(outcomes).forEach(([library, value]) => { + if (value.status !== 'success') { + console.log( + `❌ [${value.platform}] ${library} failed with status ${value.status}`, + ); + failures++; + } + }); + return failures > 0; +} + +function collectResults() { + const outcomes = readOutcomes(); + const failures = printFailures(outcomes); + if (failures) { + process.exit(1); + } + console.log('✅ All tests passed!'); +} +module.exports = { + collectResults, +}; diff --git a/.github/workflows/test-libraries-on-nightlies.yml b/.github/workflows/test-libraries-on-nightlies.yml index 3e50db00f65..319b8ae2d84 100644 --- a/.github/workflows/test-libraries-on-nightlies.yml +++ b/.github/workflows/test-libraries-on-nightlies.yml @@ -48,11 +48,22 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Test ${{ inputs.library-name }} + - name: Test ${{ matrix.library }} + id: run-test uses: ./.github/actions/test-library-on-nightly with: library-npm-package: ${{ matrix.library }} platform: android + - name: Save outcome + if: always() + run: | + echo "${{matrix.library}}: ${{steps.run-test.outcome}}" >> "/tmp/${{matrix.library}}-android-outcome" + - name: Upload Artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.library }}-android-outcome + path: /tmp/${{ matrix.library }}-android-outcome test-library-on-nightly-ios: name: "[iOS] ${{ matrix.library }}" @@ -95,8 +106,38 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Test ${{ inputs.library-name }} + - name: Test ${{ matrix.library }} + id: run-test uses: ./.github/actions/test-library-on-nightly with: library-npm-package: ${{ matrix.library }} platform: ios + - name: Save outcome + if: always() + run: | + echo "${{matrix.library}}: ${{steps.run-test.outcome}}" > "/tmp/${{matrix.library}}-ios-outcome" + - name: Upload Artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.library }}-ios-outcome + path: /tmp/${{ matrix.library }}-ios-outcome + + + collect-results: + runs-on: ubuntu-latest + needs: [test-library-on-nightly-android, test-library-on-nightly-ios] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore outcomes + uses: actions/download-artifact@v4 + with: + pattern: '*-outcome' + path: /tmp + - name: Collect failures + uses: actions/github-script@v6 + with: + script: | + const {collectResults} = require('./.github/workflow-scripts/collectNightlyOutcomes.js'); + collectResults();