|
| 1 | +--- |
| 2 | +title: Argus Screenshot bot |
| 3 | +description: A bot that monitors test workflows and posts visual diffs (screenshot comparisons) as comments on pull requests. |
| 4 | +slug: screenshot-report-bot |
| 5 | +screenshots: |
| 6 | + - https://raw.githubusercontent.com/taiga-family/argus/refs/heads/main/.demo/error-report.png |
| 7 | + - https://raw.githubusercontent.com/taiga-family/argus/refs/heads/main/.demo/loading.png |
| 8 | + - https://raw.githubusercontent.com/taiga-family/argus/refs/heads/main/.demo/pr-closed.png |
| 9 | +authors: |
| 10 | + - nsbarsukov |
| 11 | +repository: taiga-family/argus |
| 12 | +host: https://screenshot-report-bot.vercel.app |
| 13 | +--- |
| 14 | + |
| 15 | +**Argus screenshot bot** is a GitHub App built with [Probot](https://github.com/probot/probot) that helps teams catch unintended visual changes by posting screenshot comparisons as comments on pull requests. |
| 16 | +It monitors test workflows that generate screenshot artifacts, downloads visual diffs, and attaches them in a comment on the pull request. |
| 17 | + |
| 18 | +> **Why "Argus"?** Argus is a many-eyed "all-seeing" giant in Greek mythology. |
| 19 | +> This character is known for having generated the saying "the eyes of Argus" |
| 20 | +> (being subject to strict scrutiny in one's actions to an invasive, distressing degree). |
| 21 | +> [(c) Wikipedia](https://en.wikipedia.org/wiki/Argus_Panoptes) |
| 22 | +
|
| 23 | +Read more about this tool in the article:<br/> |
| 24 | +[«Bots should work, developers should think»: Writing Github App with Node.js](https://medium.com/its-tinkoff/bots-should-work-developers-should-think-writing-github-app-with-node-js-2e8eb049d7e4). |
| 25 | + |
| 26 | +## Setup :rocket: |
| 27 | + |
| 28 | +Deployment of the bot using GitHub actions is the preferred approach.<br /> |
| 29 | +Deployment as a GitHub app is supported as well. |
| 30 | + |
| 31 | +### As GitHub Action |
| 32 | + |
| 33 | +```yml |
| 34 | +# .github/workflows/screenshot-bot.yml |
| 35 | +on: |
| 36 | + workflow_run: |
| 37 | + workflows: [E2E Results] # <-- Choose any workflows to be watched by bot |
| 38 | + types: [requested, completed] |
| 39 | + branches-ignore: |
| 40 | + - 'main' |
| 41 | + - 'release/**' |
| 42 | + pull_request: |
| 43 | + types: [closed] |
| 44 | + |
| 45 | +jobs: |
| 46 | + awake-screenshot-bot: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + permissions: |
| 49 | + actions: read |
| 50 | + contents: write |
| 51 | + pull-requests: write |
| 52 | + steps: |
| 53 | + - uses: taiga-family/argus@main |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | +``` |
| 57 | +
|
| 58 | +### As GitHub App |
| 59 | +
|
| 60 | +You can deploy your own Github App using this code and recipes from the [Probot documentation](https://probot.github.io/docs/deployment) |
| 61 | +or use an already hosted **[screenshot‑report‑bot](https://github.com/apps/screenshot-report-bot/installations/new)** |
| 62 | +
|
| 63 | +## Bot configurations :gear: |
| 64 | +
|
| 65 | +The bot has configurable parameters which can be unique for every GitHub repository.<br> |
| 66 | +Every parameter is optional, and you can skip this section if the default configuration satisfies your needs. |
| 67 | +
|
| 68 | +In order to pass custom parameters to the bot, you should create a `screenshot-bot.config.yml` file inside the `.github` directory of your repository. |
| 69 | + |
| 70 | +**Example of a `screenshot-bot.config.yml` file's contents** (you can paste it as it is) with **default values** for each param: |
| 71 | + |
| 72 | +```yaml |
| 73 | +# array of RegExp strings to match images inside artifacts (by their path or file name) |
| 74 | +# which shows difference between two screenshot and which will be added to bot report comment |
| 75 | +diff-paths: [ |
| 76 | + # it is default Cypress folder name into which snapshot diffs are put |
| 77 | + '.*__diff_output__.*', |
| 78 | + ] |
| 79 | +
|
| 80 | +# array of attributes (key="value") for html-tag <img /> (screenshots) |
| 81 | +# e.g. ['width="200px"', 'height="300px"'] |
| 82 | +img-attrs: [] |
| 83 | +
|
| 84 | +# Text which is placed at the beginning of section "Failed tests" |
| 85 | +failed-report-description: '' |
| 86 | +
|
| 87 | +# Regular expression string to match images inside artifacts (by their path or file name) |
| 88 | +# which are created by new screenshot tests. |
| 89 | +new-screenshot-mark: '.*==new==.*' |
| 90 | +
|
| 91 | +################################## |
| 92 | +# Not relevant for GitHub Action # |
| 93 | +################################## |
| 94 | +
|
| 95 | +# array of regular expression strings to match workflow names |
| 96 | +# which should be watched by bot |
| 97 | +workflows: [ |
| 98 | + # all workflows with sub-string "screenshot" in their names |
| 99 | + '.*screenshot.*', |
| 100 | + ] |
| 101 | +
|
| 102 | +# array of RegExp strings to match branch names which should be skipped by bot |
| 103 | +branches-ignore: [] |
| 104 | +``` |
| 105 | + |
| 106 | +## What can the bot do? :bulb: |
| 107 | + |
| 108 | +- Posts an initial comment in the PR and updates it as workflows are run. |
| 109 | + No endless stream of comments from the bot! |
| 110 | +- Sets loading state in a comment when the PR is opened or when new commits are pushed. |
| 111 | +  |
| 112 | +- Downloads artifacts from workflows with tests, finds screenshots diffs images, and pins them to the tests failure report. |
| 113 | +  |
| 114 | +- Removes all uploaded images (for the current PR) after closing the pull request. |
| 115 | +  |
| 116 | + |
| 117 | +## About Permissions :closed_lock_with_key: |
| 118 | + |
| 119 | +If you use the bot as a GitHub Action, it is required to provide the `permissions` property in your `yml` file.<br> |
| 120 | +If you use the bot as a GitHub App, it will ask for some permissions at the beginning of the bot's installation.<br> |
| 121 | +All requested permissions are necessary, and we do not ask for more permissions than needed. |
| 122 | + |
| 123 | +#### Permissions |
| 124 | + |
| 125 | +Bot requires the following repository's **permissions**: |
| 126 | + |
| 127 | +- `actions: read` - to get the list of workflow run artifacts and download those artifacts. |
| 128 | +- `contents: write` - to create a new branch for the storage of screenshot diffs images |
| 129 | + and to have the ability to upload/delete these screenshot diffs images. |
| 130 | +- `metadata: read` - mandatory for Github App. |
| 131 | +- `pull_requests: write` - to create/edit PR's comment with bot's tests reports. |
| 132 | + |
| 133 | +#### Events |
| 134 | + |
| 135 | +The bot listens to the following repository **events**: |
| 136 | + |
| 137 | +- `pull_request` — bot listens to the `pull request.closed` event in order to delete all saved screenshots for the closed PR. |
| 138 | +- `workflow_run` — bot listens to the `workflow_run.completed` event in order to download artifacts and send tests report as PR comment. |
0 commit comments