Move chromatic into a reusable workflow #50
Workflow file for this run
This file contains 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
# To save £££, we only run the Chromatic tests once the `run_chromatic` label is | |
# applied. This workflow reminds people to add the label because it isn't always | |
# obvious. | |
name: Chromatic Label Helper | |
on: | |
pull_request: | |
types: [opened] | |
jobs: | |
write_comment: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const labels = await github.rest.issues | |
.listLabelsOnIssue({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}) | |
.then(({ data }) => data); | |
const hasChromaticLabel = labels.some( | |
(label) => label.name === 'run-chromatic', | |
); | |
if (!hasChromaticLabel) { | |
const commentLines = [ | |
"> [!TIP]", | |
"> Once this PR is ready to go, add the `run_chromatic` label to run the Chromatic tests.", | |
">", | |
"> This saves us a lot of money by not running the tests before we need them.", | |
]; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: commentLines.join('\n'), | |
}); | |
} |