• Stars
    star
    213
  • Rank 185,410 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate readme file from Go doc. Now available as a Github action!

goreadme

Build Status codecov GoDoc

Package goreadme generates readme markdown file from go doc.

The package can be used as a command line tool and as Github action, described below:

Github Action

Github actions can be configured to update the README file automatically every time it is needed. Below there is an example that on every time a new change is pushed to the main branch, the action is trigerred, generates a new README file, and if there is a change - commits and pushes it to the main branch. In pull requests that affect the README content, if the GITHUB_TOKEN is given, the action will post a comment on the pull request with changes that will be made to the README file.

To use this with Github actions, add the following content to .github/workflows/goreadme.yml. See ./action.yml for all available input options.

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
permissions:
  # Goreadme needs permissions to update pull requests comments and change contents.
  pull-requests: write
  contents: write
jobs:
    goreadme:
        runs-on: ubuntu-latest
        steps:
        - name: Check out repository
          uses: actions/checkout@v2
        - name: Update readme according to Go doc
          uses: posener/goreadme@v1
          with:
            badge-travisci: 'true'
            badge-codecov: 'true'
            badge-godoc: 'true'
            badge-goreadme: 'true'
            # Optional: Token allows goreadme to comment the PR with diff preview.
            GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

Use as a command line tool

$ GO111MODULE=on go get github.com/posener/goreadme/cmd/goreadme
$ goreadme -h

Why Should You Use It

Both Go doc and readme files are important. Go doc to be used by your user's library, and README file to welcome users to use your library. They share common content, which is usually duplicated from the doc to the readme or vice versa once the library is ready. The problem is that keeping documentation updated is important, and hard enough - keeping both updated is twice as hard.

Go Doc Instructions

The formatting of the README.md is done by the go doc parser. This makes the result README.md a bit more limited. Currently, goreadme supports the formatting as explained in godoc page, or here. Meaning:

  • A header is a single line that is separated from a paragraph above.

  • Code block is recognized by indentation as Go code.

func main() {
  ...
}

Additionally, the syntax was extended to include some more markdown features while keeping the Go doc readable:

  • Bulleted and numbered lists are possible when each bullet item is followed by an empty line.

  • Diff blocks are automatically detected when each line in a code block starts with a ' ', '-' or '+':

-removed line starts with '-'
 remained line starts with ' '
+added line starts with '+'
  • A repository file can be linked when providing a path that start with [./](./): ./goreadme.go.

  • A link can have a link text by prefixing it with parenthesised text: goreadme page.

  • A link to repository file and can have a link text: goreadme main file.

  • An image can be added by prefixing a link to an image with (image/<image title>):

title of image

Testing

The goreadme tests the test cases in the ./testdata directory. It generates readme files for all the packages in that directory and asserts that the result readme matches the existing one. When modifying goreadme behavior, there is no need to manually change these readme files. It is possible to run WRITE_READMES=1 go test ./... which regenerates them and check the changes match the expected (optionally using git diff).

Sub Packages

  • cmd/goreadme: Goreadme command line tool and Github action

Readme created from Go doc with goreadme

More Repositories

1

complete

bash completion written in go + bash completion for go command
Go
925
star
2

goaction

Write Github actions in Go
Go
210
star
3

h2conn

HTTP2 client-server full-duplex connection
Go
129
star
4

gitfs

A complete solution for static files in Go code
Go
127
star
5

wstest

go websocket client for unit testing of a websocket handler
Go
101
star
6

sharedsecret

Implementation of Shamir's Secret Sharing algorithm.
Go
69
star
7

tarfs

An implementation of the FileSystem interface for tar files.
Go
58
star
8

cmd

The standard library flag package with its missing features
Go
41
star
9

ctxutil

utils for Go context
Go
25
star
10

client-timing

An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers.
Go
24
star
11

order

More readable and easier ordering and comparison tasks
Go
21
star
12

mock-import

A helper mocking function to mask ImportErrors
Python
17
star
13

orm

Go Typed ORM
Go
16
star
14

context

A proof of concept implementation of scoped context
Go
16
star
15

h2demo

Code examples for blog post
Go
15
star
16

script

Easily write scripts with Go. Improvements for https://github.com/bitfield/script.
Go
14
star
17

fuzzing

Easy fuzzing with go-fuzz
Go
14
star
18

eztables

iptables in web browser
Go
11
star
19

fcontext

Go Context with (pseudo) constant access-time
Go
10
star
20

auth

Painless OAuth authentication middleware
Go
8
star
21

dont

A towel, is about the most massively useful thing an interstellar hitchhiker can have
Go
6
star
22

tiler

A Go port of https://github.com/nuno-faria/tiler.
Go
6
star
23

goaction-example

Simplest goaction example
Go
5
star
24

flag

Like the flag package, but with bash completion support!
Go
5
star
25

goreadme-server

Github App for goreadme package
Go
4
star
26

formatter

A library for formatting text - indenting and line wrapping
Go
3
star
27

wsbeam

WebSocket HTTP handler that can be used to beam (broadcast) data to all connections
Go
3
star
28

contexttest

Test package for context implementations
Go
3
star
29

chrome-github-godoc

Chrome extension that replaces Github view of git commit messages with useful godoc.org synopsis
JavaScript
3
star
30

tmplt

A small wrapper around Go templates for handling simple templates
Go
2
star
31

learn

Go
2
star
32

goaction-issues-example

Goaction example for using Github APIs
Go
2
star
33

meetups

An archive of my meetup lectures
Go
1
star
34

grpcgw

Convenience comes with grpc-ecosystem/grpc-gateway
Go
1
star
35

go

Go
1
star
36

fsutil

Go
1
star
37

state-logger

A logging tool to log on state changes
Go
1
star
38

ps1

A lightweight script that sets a nice shell prompt
Shell
1
star
39

githubapp

oauth2 Github app authentication client
Go
1
star
40

autogen

Automatically generate files
Go
1
star