home / tils / til

Menu
  • GraphQL API

til: github-actions_grep-tests.md

Export data

til

This row where path = "github-actions_grep-tests.md"

TSV
Tab-separated values, for pasting into Excel or Google Sheets
CSV
Comma-separated values, for spreadsheets and other tools
  • JSON
    The row inside an object, with extra details
    View Download

path
github-actions_grep-tests.md
topic
github-actions
title
Using grep to write tests in CI
url
https://github.com/simonw/til/blob/main/github-actions/grep-tests.md
body
GitHub Actions workflows fail if any of the steps executes something that returns a non-zero exit code. Today I learned that `grep` returns a non-zero exit code if it fails to find any matches. This means that piping to grep is a really quick way to write a test as part of an Actions workflow. I wrote a quick soundness check today using the new `datasette --get /path` option, which runs a fake HTTP request for that path through Datasette and returns the response to standard out. Here's an example: ```yaml - name: Build database run: scripts/build.sh - name: Run tests run: | datasette . --get /us/pillar-point | grep 'Rocky Beaches' - name: Deploy to Vercel ``` I like this pattern a lot: build a database for a custom Datasette deloyment in CI, run one or more quick soundness checks using grep, then deploy if those checks pass.
html
<p>GitHub Actions workflows fail if any of the steps executes something that returns a non-zero exit code.</p> <p>Today I learned that <code>grep</code> returns a non-zero exit code if it fails to find any matches.</p> <p>This means that piping to grep is a really quick way to write a test as part of an Actions workflow.</p> <p>I wrote a quick soundness check today using the new <code>datasette --get /path</code> option, which runs a fake HTTP request for that path through Datasette and returns the response to standard out. Here's an example:</p> <div class="highlight highlight-source-yaml"><pre> - <span class="pl-ent">name</span>: <span class="pl-s">Build database</span> <span class="pl-ent">run</span>: <span class="pl-s">scripts/build.sh</span> - <span class="pl-ent">name</span>: <span class="pl-s">Run tests</span> <span class="pl-ent">run</span>: <span class="pl-s">|</span> <span class="pl-s"> datasette . --get /us/pillar-point | grep 'Rocky Beaches'</span> <span class="pl-s"></span> - <span class="pl-ent">name</span>: <span class="pl-s">Deploy to Vercel</span></pre></div> <p>I like this pattern a lot: build a database for a custom Datasette deloyment in CI, run one or more quick soundness checks using grep, then deploy if those checks pass.</p>
shot
<Binary: 65,103 bytes>
created
2020-08-19T21:26:05-07:00
created_utc
2020-08-20T04:26:05+00:00
updated
2020-08-22T21:18:06-07:00
updated_utc
2020-08-23T04:18:06+00:00
shot_hash
3e71efb58ec2d72ce37d6c93d7ace74e
slug
grep-tests
Powered by Datasette · How this site works · Code of conduct