Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Go package self-test failure, introduced by a9145135 #30

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ name: Test

on:
push:
branches: [main]
branches:
pull_request:
branches: [main]

jobs:
build:
strategy:
matrix:
go-version: '1.20'
os: [ubuntu-latest, windows-latest]
go-version: [1.20.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Test

- name: Check Out Code
uses: actions/checkout@v4

- name: Test Library API For Regressions
run: go test -race -v .
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
<!-- XX Move this file down to .github/, because its contents are GitHub-specific. -->

# GoAT: Go ASCII Tool

<!-- Github-specific status icons-->
![](https://github.com/github/docs/actions/workflows/test.yml/badge.svg)
<!-- Github-specific status icon

Github requires explicitly binding a repository owner's username in the text of a README,
implying that a badge in README.md cannot both reflect the status of a test Action after a
contributor pushes to his pull request branch, and
the run of that same test Action after the upstream owner merges the pull request
into his 'main' branch. See:

https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge

GitHub Community forum shows numerous similar issues with badges:
https://github.com/orgs/community/discussions/categories/actions?discussions_q=is%3Aopen+category%3AActions++badge.svg

=> CONCLUSION: Don't use badges. Instead, pay attention to Action result status.
-->
<!-- ![](https://github.com/blampe/goat/actions/workflows/test.yml/badge.svg) -->

## What **GoAT** Can Do For You

Expand Down Expand Up @@ -71,7 +87,7 @@ GoAT's [README.md](README.md), then finally rendered to HTML ```<img>``` element


```
![](./examples/trees.svg)
![](//examples/trees.svg)

### Trees -- mid-range color value
Setting a foreground color in the middle of the possible range of value or luminance
Expand All @@ -83,7 +99,7 @@ CSS property by
from within an enclosing `<img>` element such as are generated by Markdown.


![](./trees.mid-blue.svg)
![](//trees.mid-blue.svg)

### Overlaps
```
Expand All @@ -97,7 +113,7 @@ from within an enclosing `<img>` element such as are generated by Markdown.
'-' '-' '-' '-' '-' '-'

```
![](./examples/overlaps.svg)
![](//examples/overlaps.svg)

### Line Decorations
```
Expand All @@ -110,7 +126,7 @@ from within an enclosing `<img>` element such as are generated by Markdown.
/\ *---------------'

```
![](./examples/line-decorations.svg)
![](//examples/line-decorations.svg)

### Line Ends
```
Expand All @@ -127,7 +143,7 @@ from within an enclosing `<img>` element such as are generated by Markdown.


```
![](./examples/line-ends.svg)
![](//examples/line-ends.svg)

### Dot Grids
```
Expand All @@ -141,7 +157,7 @@ from within an enclosing `<img>` element such as are generated by Markdown.

```
Note that '·' above is not ASCII, but rather Unicode, the MIDDLE DOT character, encoded with UTF-8.
![](./examples/dot-grids.svg)
![](//examples/dot-grids.svg)

### Large Nodes
```
Expand All @@ -156,7 +172,7 @@ Note that '·' above is not ASCII, but rather Unicode, the MIDDLE DOT character,
'-' '---' '-' '---' '-' '-' '---'

```
![](./examples/large-nodes.svg)
![](//examples/large-nodes.svg)

### Small Grids
```
Expand All @@ -170,7 +186,7 @@ Note that '·' above is not ASCII, but rather Unicode, the MIDDLE DOT character,


```
![](./examples/small-grids.svg)
![](//examples/small-grids.svg)

### Big Grids
```
Expand All @@ -188,7 +204,7 @@ Note that '·' above is not ASCII, but rather Unicode, the MIDDLE DOT character,


```
![](./examples/big-grids.svg)
![](//examples/big-grids.svg)

### Complicated
```
Expand Down Expand Up @@ -218,7 +234,7 @@ Note that '·' above is not ASCII, but rather Unicode, the MIDDLE DOT character,
'-' '---------+--' / Nor/is this. ---

```
![](./examples/complicated.svg)
![](//examples/complicated.svg)

### More examples are [here](examples)

Expand All @@ -236,7 +252,7 @@ A nicely formatted reference may be found at [pkg.go.dev](https://pkg.go.dev/git
$ go get -u github.com/blampe/goat/
```
### Library Data Flow
![](./goat.svg)
![](//goat.svg)

The diagram above was derived by [./make.sh](./make.sh) from ASCII-art in the Go
source file [./goat.go](./goat.go).
Expand Down
30 changes: 23 additions & 7 deletions README.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
<!-- XX Move this file down to .github/, because its contents are GitHub-specific. -->

# GoAT: Go ASCII Tool

<!-- Github-specific status icons-->
![](https://github.com/github/docs/actions/workflows/test.yml/badge.svg)
<!-- Github-specific status icon

Github requires explicitly binding a repository owner's username in the text of a README,
implying that a badge in README.md cannot both reflect the status of a test Action after a
contributor pushes to his pull request branch, and
the run of that same test Action after the upstream owner merges the pull request
into his 'main' branch. See:

https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge

GitHub Community forum shows numerous similar issues with badges:
https://github.com/orgs/community/discussions/categories/actions?discussions_q=is%3Aopen+category%3AActions++badge.svg

=> CONCLUSION: Don't use badges. Instead, pay attention to Action result status.
-->
<!-- ![](https://github.com/{{.Github_Repository_Owner}}/goat/actions/workflows/test.yml/badge.svg) -->

## What **GoAT** Can Do For You

Expand Down Expand Up @@ -42,7 +58,7 @@ with rows above and below.

## Installation
```
$ go install github.com/{{.GithubUser}}/goat/cmd/goat@latest
$ go install github.com/{{.Github_Repository_Owner}}/goat/cmd/goat@latest
```
<!-- https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/organizing-information-with-collapsed-sections#creating-a-collapsed-section -->

Expand Down Expand Up @@ -133,12 +149,12 @@ The core engine of ```goat``` is accessible as a Go library package, for inclusi
code of your own.
The code implements a subset, and some extensions, of the ASCII diagram generation function of the browser-side Javascript in [Markdeep](http://casual-effects.com/markdeep/).

A nicely formatted reference may be found at [pkg.go.dev](https://pkg.go.dev/github.com/{{.GithubUser}}/goat).
A nicely formatted reference may be found at [pkg.go.dev](https://pkg.go.dev/github.com/{{.Github_Repository_Owner}}/goat).

### Installation

```
$ go get -u github.com/{{.GithubUser}}/goat/
$ go get -u github.com/{{.Github_Repository_Owner}}/goat/
```
### Library Data Flow
![]({{.Root}}/goat.svg)
Expand All @@ -150,13 +166,13 @@ source file [./goat.go](./goat.go).

<!--
XX XX May need a Github Action to do this substitution at "push" time.
[![resource non-responsive](https://pkg.go.dev/badge/github.com/{{.GithubUser}}/goat)](https://pkg.go.dev/github.com/{{.GithubUser}}/goat)
[![resource non-responsive](https://pkg.go.dev/badge/github.com/{{.Github_Repository_Owner}}/goat)](https://pkg.go.dev/github.com/{{.Github_Repository_Owner}}/goat)
-->

<!--
The scraping of GitHub by godocs.io (see https://sr.ht) does NOT include README.md;
whereas Google's pkg.go.dev does do so, and apparently runs its own variant of GFM processing :-/
[![resource non-responsive](https://godocs.io/github.com/{{.GithubUser}}/goat?status.svg)](https://godocs.io/github.com/{{.GithubUser}}/goat)
[![resource non-responsive](https://godocs.io/github.com/{{.Github_Repository_Owner}}/goat?status.svg)](https://godocs.io/github.com/{{.Github_Repository_Owner}}/goat)
-->

### Project Tenets
Expand Down
5 changes: 5 additions & 0 deletions local-markdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/sh

# Render to HTML, for local inspection.
./markdown_to_html.sh README.md >README.html
./markdown_to_html.sh CHANGELOG.md >CHANGELOG.html
75 changes: 38 additions & 37 deletions make.sh → pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,47 @@
# Run all tests, and all pre-compilation build steps.
# Certain output files should be committed to the SCM archive.
#
# Recall that an end-user eventually installing with 'go get ...'
# will trigger a compilation from source within the local environment.
# XX Give this file a more descriptive name.
# Recall that an end-user eventually installing with 'go get ...' will
# trigger a compilation from source within the local environment,
# without help from this file.

set -e
set -x
usage () {
set +x
printf "%s\n\n" "$*"
printf "usage: %s [-g GitHub_Username] [-w]\n" ${0##*/}
printf "usage: %s [-w]\n" ${0##*/}
printf "\t%s\t%s\n" ""
printf "\t%s\t%s\n" "$*"
exit 1
}

# Define colors for SVG ~foreground~ seen on Github front page.
svg_color_dark_scheme="#EEF"
svg_color_light_scheme="#011"
github_blue_color="#2F81F7"

# GOMOD=$(go env GOMOD)
# from_username=${GOMOD##*github.com/}
# githubuser=${from_username%%/*}
#
# X Is it acceptable to push to a PR branch files that refer to the owner's main branch?
githubuser=blampe

TEST_ARGS=

while getopts hg:iw flag
do
case $flag in
h) usage "";;
g) githubuser=${OPTARG};; # Override guess based on GOMOD
w) TEST_ARGS=${TEST_ARGS}" -write";;
\?) usage "unrecognized option flag";;
esac
done

PACKAGE_PATH=$(go list .)
UPSTREAM_OWNER=${PACKAGE_PATH#*/}
UPSTREAM_OWNER=${UPSTREAM_OWNER%/*}

GITHUB_REPOSITORY_OWNER=$USER
CURRENT_BRANCH_NAME=$(git-branch --show-current)
# If the current branch name contains the GitHub username of the owner of the upstream repo,
# assume the intention is to prepare and push a pull request.
if [ $(expr $CURRENT_BRANCH_NAME : ".*$UPSTREAM_OWNER") != 0 ]
then
GITHUB_REPOSITORY_OWNER=$UPSTREAM_OWNER
fi

tmpl_expand () {
go run ./cmd/tmpl-expand Root="." GithubUser=${githubuser} "$@"
# XX Root="/" resolves to root of the repo -- consider dropping the variable.
go run ./cmd/tmpl-expand Root="/" Github_Repository_Owner=${GITHUB_REPOSITORY_OWNER} "$@"
}

#tmpl_expand <go.tmpl.mod >go.mod
Expand All @@ -51,27 +52,18 @@ tmpl_expand () {
# SVG examples/ regeneration.
#
# If the command fails due to expected changes in SVG output, rerun
# this script with "TEST_ARGS=-write" first on the command line.
# this script with "TEST_ARGS=-write".
# X Results are used as "golden" standard for GitHub-side regression tests --
# so arguments here must not conflict with those in "test.yml".
# XX How to share a single arg list shared between the two i.e. "DRY"?
go test -run . -v \
${TEST_ARGS}

# Illustrate a workaround for lack of support in certain browsers e.g. Safari for
# inheritance of CSS property 'color-scheme' from <img> elements downward to nested
# <svg> elements.
# - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
go run ./cmd/goat <examples/trees.txt \
-svg-color-dark-scheme ${github_blue_color} \
-svg-color-light-scheme ${github_blue_color} \
>trees.mid-blue.svg

# build README.md
tmpl_expand <README.md.tmpl >README.md \
$(bash -c 'echo ./examples/{trees,overlaps,line-decorations,line-ends,dot-grids,large-nodes,small-grids,big-grids,complicated}.{txt,svg}')

# '-d' writes ./awkvars.out
# Build other SVG files; linked to by README.md but not used for regression test.
# Define colors for SVG ~foreground~ seen on Github front page.
svg_color_dark_scheme="#EEF"
svg_color_light_scheme="#011"
github_blue_color="#2F81F7"
cat *.go |
awk '
/[<]goat[>]/ {p = 1; next}
Expand All @@ -82,7 +74,16 @@ cat *.go |
-svg-color-dark-scheme ${svg_color_dark_scheme} \
-svg-color-light-scheme ${svg_color_light_scheme} \
>goat.svg
# Illustrate a workaround for lack of support in certain browsers e.g. Safari for
# inheritance of CSS property 'color-scheme' from <img> elements downward to nested
# <svg> elements.
# - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
go run ./cmd/goat <examples/trees.txt \
-svg-color-dark-scheme ${github_blue_color} \
-svg-color-light-scheme ${github_blue_color} \
>trees.mid-blue.svg

# Render to HTML, for local inspection.
./markdown_to_html.sh README.md >README.html
./markdown_to_html.sh CHANGELOG.md >CHANGELOG.html
# build README.md
# X `tac` is a slightly sleazy way to get the .txt/.svg pairs listed in the
# source/dest order as required by tmpl_expand.
tmpl_expand <README.md.tmpl >README.md $(git-ls-files examples | tac)
Loading