uptime-kuma/.github/workflows/auto-test.yml
Zaid-maker 76ee06a2b3 test
2024-11-21 15:36:29 +05:00

180 lines
5.9 KiB
YAML

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Auto Test
on:
push:
branches: [ master, 1.23.X ]
paths-ignore:
- '*.md'
pull_request:
branches: [ master, 1.23.X ]
paths-ignore:
- '*.md'
jobs:
unit-test:
needs: [ check-linters ]
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest, ARM64]
node: [ 18, 20 ]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run build
- run: npm run test-backend
env:
HEADLESS_TEST: 1
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
# As a lot of dev dependencies are not supported on ARMv7, we have to test it separately and just test if `npm ci --production` works
armv7-simple-test:
needs: [ ]
runs-on: ${{ matrix.os }}
timeout-minutes: 15
if: ${{ github.repository == 'louislam/uptime-kuma' }}
strategy:
matrix:
os: [ ARMv7 ]
node: [ 18, 20 ]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci --production
check-linters:
runs-on: ubuntu-latest
steps:
- run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- run: npm run lint:prod
e2e-test:
needs: [ ]
runs-on: ARM64
steps:
- run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- run: npx playwright install
- run: npm run build
- run: npm run test-e2e
post-test:
needs: [unit-test, e2e-test]
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Download test results
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Process test results
id: test-results
run: |
echo "::set-output name=unit_test::$([ "${{ needs.unit-test.result }}" = "success" ] && echo "✅" || echo "❌")"
echo "::set-output name=e2e_test::$([ "${{ needs.e2e-test.result }}" = "success" ] && echo "✅" || echo "❌")"
# Get coverage info if available
COVERAGE=""
if [ -f "artifacts/test-results-ubuntu-latest-node-20/coverage/coverage-summary.json" ]; then
COVERAGE=$(cat artifacts/test-results-ubuntu-latest-node-20/coverage/coverage-summary.json | jq -r '.total.lines.pct')
fi
echo "::set-output name=coverage::$COVERAGE"
- name: Create comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const unitTest = "${{ steps.test-results.outputs.unit_test }}";
const e2eTest = "${{ steps.test-results.outputs.e2e_test }}";
const coverage = "${{ steps.test-results.outputs.coverage }}";
const comment = `## Test Results
| Test Type | Status |
|-----------|--------|
| Unit Tests | ${unitTest} |
| E2E Tests | ${e2eTest} |
${coverage ? `| Coverage | ${coverage}% |` : ''}
${unitTest === '❌' || e2eTest === '❌' ? `
### Failed Tests
Please check the [Actions tab](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for detailed logs.
` : ''}
### Artifacts
- [Test Results](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})
- [Playwright Report](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})
`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Test Results ')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
- name: Check test results
if: always()
run: |
if [ "${{ needs.unit-test.result }}" != "success" ] || [ "${{ needs.e2e-test.result }}" != "success" ]; then
echo "Tests failed!"
exit 1
fi