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

Update generate & Add template for GitHub container action #26

Merged
merged 12 commits into from
May 1, 2020
Merged
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ configuration and boilerplate files in the
[AAC Tactics](https://github.com/coq-community/aac-tactics)
project are generated as follows:
```shell
mustache meta.yml ../templates/default.nix.mustache > default.nix
mustache meta.yml ../templates/README.md.mustache > README.md
mustache meta.yml ../templates/.travis.yml.mustache > .travis.yml
mustache meta.yml ../templates/coq.opam.mustache > coq-aac-tactics.opam
mustache meta.yml ../templates/default.nix.mustache > default.nix
mustache meta.yml ../templates/.travis.yml.mustache > .travis.yml
```
Other projects using the templates in a similar way include
[Chapar](https://github.com/coq-community/chapar) and
Expand All @@ -52,6 +52,14 @@ cd -
../templates/generate.sh
git add <the_generated_files>
```
Regarding continuous integration, the `generate.sh` script will create:
* a [Travis CI](https://docs.travis-ci.com/) configuration
[(based on opam + Nix)](./.travis.yml.mustache),
* or a [GitHub Action](https://help.github.com/en/actions) workflow
[(based on opam)](./coq-action.yml.mustache),

depending on whether `meta.yml` contains `travis: true` or `action: true`.

Keeping generated files under version control is not ideal, but `README.md` has to exist,
and generally this is a common practice when using build systems such as Autotools.
To get a `mustache` tool in, e.g., NixOS, you can run `nix-env -i mustache-go`.
Expand Down
7 changes: 7 additions & 0 deletions README.md.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{{# travis }}
[![Travis][travis-shield]][travis-link]
{{/ travis }}
{{# action }}
[![CI][action-shield]][action-link]
{{/ action }}
{{# circleci }}
[![CircleCI][circleci-shield]][circleci-link]
{{/ circleci }}
Expand All @@ -22,6 +25,10 @@
[travis-shield]: https://travis-ci.com/{{ organization }}/{{ shortname }}.svg?branch=master
[travis-link]: https://travis-ci.com/{{ organization }}/{{ shortname }}/builds
{{/ travis }}
{{# action }}
[action-shield]: https://github.com/{{ organization }}/{{ shortname }}/workflows/CI/badge.svg?branch=master
[action-link]: https://github.com/{{ organization }}/{{ shortname }}/actions?query=workflow%3ACI
{{/ action }}
{{# circleci }}
[circleci-shield]: https://circleci.com/gh/{{ organization }}/{{ shortname }}.svg?style=svg
[circleci-link]: https://circleci.com/gh/{{ organization }}/{{ shortname }}
Expand Down
35 changes: 35 additions & 0 deletions coq-action.yml.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
# the OS must be GNU/Linux to be able to use the docker-coq-action
runs-on: ubuntu-latest
strategy:
matrix:
coq_version:
{{# tested_coq_opam_versions }}
- {{ version }}
{{/ tested_coq_opam_versions }}
ocaml_version: ['minimal']
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: coq-community/docker-coq-action@v1
with:
opam_file: 'coq-{{ shortname }}.opam'
{{! Change delimiters to avoid the next two lines being parsed as mustache syntax. }}
{{=<% %>=}}
erikmd marked this conversation as resolved.
Show resolved Hide resolved
coq_version: ${{ matrix.coq_version }}
ocaml_version: ${{ matrix.ocaml_version }}

# See also:
# https://github.com/coq-community/docker-coq-action#readme
# https://github.com/erikmd/docker-coq-github-action-demo
62 changes: 60 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,65 @@

srcdir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )

get_yaml() {
# Arg 1: the meta.yml path
# STDIN: the mustache code
local meta="$1" temp
temp=$(mktemp --tmpdir --suffix .yml template-XXX)
cat > "$temp"
mustache "$meta" "$temp"
rm -f -- "$temp"
}

for f in "$srcdir"/{,.}*.mustache; do
echo "Generating $(basename "$f" .mustache)..."
mustache meta.yml "$f" > "$(basename "$f" .mustache)"
target=$(basename "$f" .mustache)
case "$target" in
coq.opam)
mustache='{{ shortname }}'
shortname=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$shortname" ]; then
target=${target/coq/coq-$shortname}
else
continue
fi
;;
extracted.opam)
mustache='{{# extracted }}{{ extracted_shortname }}{{/ extracted }}'
extracted_shortname=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$extracted_shortname" ]; then
target=${target/extracted/$extracted_shortname}
else
continue
fi
;;
coq-action.yml)
mustache='{{ action }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
mkdir -p -v .github/workflows && target=".github/workflows/$target"
else
continue
fi
;;
.travis.yml)
mustache='{{ travis }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
: noop
else
continue
fi
;;
default.nix)
mustache='{{ tested_coq_nix_versions }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
: noop
else
continue
fi
;;
esac
echo "Generating $target..."
mustache meta.yml "$f" > "$target"
done