Lint, Tests #60
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: Lint, Tests | |
| on: | |
| pull_request: | |
| workflow_run: | |
| workflows: | |
| - Up version | |
| types: | |
| - completed | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.actor }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| run: | |
| name: lint-tests | |
| runs-on: ubuntu-latest | |
| if: ${{ github.actor == 'robot-charts' || github.event_name == 'pull_request' }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| - run: npm ci | |
| - run: npm run test:prepare | |
| - run: npm run test | |
| - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| if: github.event_name == 'pull_request' | |
| id: upload-artifact-report | |
| with: | |
| name: playwright-report | |
| path: ./test-artifacts/ | |
| retention-days: 7 | |
| - uses: daun/playwright-report-summary@1229105480a2a4bdd91598d8a146fbab41343fce # v3.11.0 | |
| if: github.event_name == 'pull_request' | |
| id: report-md | |
| with: | |
| report-file: ./test-artifacts/report.json | |
| create-comment: false | |
| - name: create or update pr comment | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const issueNumber = context.issue.number; | |
| const repo = context.repo; | |
| const commentIdentifier = "<!-- tests-report -->"; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| ...repo, | |
| issue_number: issueNumber, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.body.includes(commentIdentifier) && | |
| comment.user.login === 'github-actions[bot]' | |
| ); | |
| const timestamp = new Date(Date.now() + 3 * 60 * 60 * 1000).toISOString().replace('T', ' ').slice(0, 19) + ' MSK'; | |
| let commentBody = ` | |
| ## 🧪 Tests | |
| ${{ steps.report-md.outputs.summary }} | |
| --- | |
| 👉 Link with detailed report: [playwright-report.zip](${process.env.REPORT_LINK}) | |
| Last updated: ${timestamp} | |
| ${commentIdentifier} | |
| `; | |
| commentBody = commentBody.replace(/@screenshot/g, '`@screenshot`'); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| ...repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| console.log('updated existing comment on PR #' + issueNumber); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| ...repo, | |
| issue_number: issueNumber, | |
| body: commentBody | |
| }); | |
| console.log('added new comment to PR #' + issueNumber); | |
| } | |
| env: | |
| REPORT_LINK: ${{ steps.upload-artifact-report.outputs.artifact-url }} |