mongodb-university / Bluehawk

A markup language and tool for extracting code examples, checkpointing tutorials, and dynamically transforming text
https://mongodb-university.github.io/Bluehawk/
Other
29 stars 17 forks source link

Publish a GHA that ensures `bluehawk snip` was run #142

Open nlarew opened 1 year ago

nlarew commented 1 year ago

The goal here is to ensure that the snippets generated from a given file/directory are up-to-date with the source files they're generated from via CI/CD in a reusable way.

The action should accept the path for a file or directory and run bluehawk snip on it.

Then, it should compare the output of the snippets it created with those in the PR branch (e.g. with git diff or md5 hashing if we have to).

If the snippets are identical, the action succeeds.

Otherwise, the action fails and reports out-of-date snippets & source files in the GHA stdout.

name: Ensure Node.js Bluehawk Snippets Are Up To Date

on:
  pull_request:
    paths:
      - "examples/node/**"

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: mongodb-university/bluehawk/github-actions/check-snip@main
        with:
          source: examples/node/Examples
          output: source/examples/generated/node

Example failure output:

Found 2 out-of-date snippets:

  { "source": "examples/node/Examples/mongodb.js", "snippet": "source/examples/generated/node/mongodb.snippet.find-a-single-document.js" }
  { "source": "examples/node/Examples/mongodb.js", "snippet": "source/examples/generated/node/mongodb.snippet.find-multiple-documents.js" }

To fix this, run:
   npx bluehawk snip examples/node/Examples -o source/examples/generated/node
ragudigispoc commented 10 months ago

bgg