Giter Site home page Giter Site logo

ikstewa / readme-code-testing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tokusumi/readme-code-testing

0.0 1.0 0.0 22 KB

Helping test "any" code in readme with GitHub Action. All you need is unit testing synchronized external files in the ordinary way.

License: MIT License

Python 91.26% Shell 8.74%

readme-code-testing's Introduction

Readme code testing example

Test code and embed into README

This repo demonstrates Markdown Embed Code From File (GitHub Action).

This would helps testing for your code within readme (actually for markdown).

You could put code in external file and test them, as same as ordinary testing your code. You don't need copy & paste code and feel anxisous about compatibility anymore.

Mark your code for embedding

This action could inspect your code, if you add a file path in code block as "```lang:external/file/path.py```".

The following code block has a file path src/helloworld.py:

def hello():
    return "v1.0.0 world"

See src/helloworld.py as:

  • Synchronized code.
  • Highlighting code in readme.
  • Not affected code rendering.

And notice that there are nothing to do re-embedding new/modified code. This action overrides code automatically if you change code in external file and commit it.

Try it

Let's try demonstration in your repository as follows:

  1. fork this repository.
  2. edit src/helloworld.py, create a new branch and start a pull request.
  3. go to PR to check action result.
  4. you can see auto updated readme at new branch you created above. (see if above code block is modified)
  5. you can try again, if you edit it and commit again.

More features

Embedding specific lines

You might add specific lines from one file (ex. src/mul.py).

This action supports this with the syntax as "```lang:external/file/path.py [start:end]```" for it:

def multiple(x):
    return pow(x, 2)

Multiple use

You might add one file path (ex. src/mul.py) for multiple code blocks:

from math import pow

def multiple(x):
    return pow(x, 2)

It works!:

from math import pow

def multiple(x):
    return pow(x, 2)

However, the other is not available.

Non-existent file

Notice that this action goes to "fail" if a file you add does not exist.

Multilingual

This action could work for any programming "language".

Ideally you could write as "```lang:external/file/path.py```", but actually this action does not inspect "lang", just read path and copy&paste strings into target code block in markdown.

So, missing "lang" is available:

#!/bin/bash

echo "hello"

Formatting

Notice that this action uses markdown parser/formatter, so, if you don't update any code, readme may be updated if formatter works.

readme-code-testing's People

Contributors

tokusumi avatar actions-user avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.