home / tils / til

Menu
  • GraphQL API

til: github-actions_grep-tests.md

This data as json

path topic title url body html shot created created_utc updated updated_utc shot_hash slug
github-actions_grep-tests.md github-actions Using grep to write tests in CI https://github.com/simonw/til/blob/main/github-actions/grep-tests.md 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. <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> <Binary: 65,103 bytes> 2020-08-19T21:26:05-07:00 2020-08-20T04:26:05+00:00 2020-08-22T21:18:06-07:00 2020-08-23T04:18:06+00:00 3e71efb58ec2d72ce37d6c93d7ace74e grep-tests
Powered by Datasette · How this site works · Code of conduct