GitHub Action - Code sample checker ️

This GitHub action scans a folder (recursively if desired) for a set of code samples, evaluates them to ensure that they compile and run properly. This action is a wrapper around the codechecker-mkdocs python script, and is heavily inspired by:

How to use

  1. Create a new file in your repository .github/workflows/action.yml.

  2. Copy-paste the following workflow in your action.yml file:

    name: Check code samples
    
    on: push
    
    jobs:
      code-sample-check:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@master
        - uses: byrnereese/github-action-code-sample-check@v1

Real-life usage samples

Following is a list of some of the repositories which are using GitHub Action - Markdown link check.

  1. RingCentral API documentation

(Edit this file and add your name here)

Configuration

Custom variables

You customize the action by using the following variables:

Variable Description Default value
excludes One or more patterns to identify links that can be excluded or skipped in your tests. None
folder-path By default the github-action-mkdocs-link-check action checks for all markdown files in your repository, which typically are located in the docs directory for mkdocs projects. Use this option to limit checks to only specific folders. docs/
syntax-only Process code samples for syntax validity only. false
languages A comma-delimited list of languages to check. all
recurse Recurse through the entire directory tree below the specified path. true
verbose-mode Specify yes to show detailed HTTP status for checked links. no

Sample workflow with variables

name: Check code samples

on: push

jobs:
  code-sample-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: byrnereese/github-action-code-sample-check@v1
      with:
        use-verbose-mode: 'yes'
        folder-path: 'code-samples/'

Scheduled runs

In addition to checking code samples on every push, or pull request, it is also a good hygine practice to check code samples regularly as well in case errors have been introduced by newer SDKs or software libaries. See Workflow syntax for GitHub Actions - on.schedule for more details.

Sample workflow with scheduled job

name: Check Markdown links

on: 
  push:
    branches:
    - master
  schedule:
  # Run everyday at 9:00 AM (See https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07)
  - cron: "0 9 * * *"

jobs:
  code-sample-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: byrnereese/github-action-code-sample-check@v1
      with:
        use-verbose-mode: 'yes'
        folder-path: 'code-samples/'

Versioning

GitHub Action - Markdown link check follows the GitHub recommended versioning strategy.

  1. To use a specific released version of the action (Releases):
    - uses: byrnereese/github-action-code-sample-check@1.0.1
  2. To use a major version of the action:
    - uses: byrnereese/github-action-code-sample-check@v1
  3. You can also specify a specific commit SHA as an action version:
    - uses: byrnereese/github-action-code-sample-check@44a942b2f7ed0dc101d556f281e906fb79f1f478