From 6558de141f6de84319678a60fe09efc776907887 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Sat, 18 May 2024 19:52:34 -0400 Subject: [PATCH] start --- .github/workflows/make.yaml | 37 +++++++++ .github/workflows/markdown-lint.yml | 31 +++++++ .github/workflows/shellcheck.yml | 36 +++++++++ .gitignore | 1 + .rultor.yml | 33 ++++++++ Dockerfile | 37 +++++++++ LICENSE.txt | 21 +++++ Makefile | 47 +++++++++++ README.md | 21 +++++ action.yml | 39 +++++++++ entry.sh | 64 +++++++++++++++ renovate.json | 6 ++ tests/simple.xml | 17 ++++ xsl/awards.xsl | 95 ++++++++++++++++++++++ xsl/index.xsl | 121 ++++++++++++++++++++++++++++ 15 files changed, 606 insertions(+) create mode 100644 .github/workflows/make.yaml create mode 100644 .github/workflows/markdown-lint.yml create mode 100644 .github/workflows/shellcheck.yml create mode 100644 .gitignore create mode 100644 .rultor.yml create mode 100644 Dockerfile create mode 100644 LICENSE.txt create mode 100644 Makefile create mode 100644 README.md create mode 100644 action.yml create mode 100755 entry.sh create mode 100644 renovate.json create mode 100644 tests/simple.xml create mode 100644 xsl/awards.xsl create mode 100644 xsl/index.xsl diff --git a/.github/workflows/make.yaml b/.github/workflows/make.yaml new file mode 100644 index 0000000..d859d99 --- /dev/null +++ b/.github/workflows/make.yaml @@ -0,0 +1,37 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +name: make +'on': + push: + pull_request: +jobs: + make: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - run: sudo wget --no-verbose -O /usr/local/opt/Saxon.jar https://repo.maven.apache.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-5/Saxon-HE-9.8.0-5.jar + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + - run: gem install judges + - run: make \ No newline at end of file diff --git a/.github/workflows/markdown-lint.yml b/.github/workflows/markdown-lint.yml new file mode 100644 index 0000000..4eef45d --- /dev/null +++ b/.github/workflows/markdown-lint.yml @@ -0,0 +1,31 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +name: markdown-lint +on: + push: +jobs: + markdown-lint: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: articulate/actions-markdownlint@v1 diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..a4b345b --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,36 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +name: shellcheck +'on': + push: + branches: + - master + pull_request: + branches: + - master +jobs: + shellcheck: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: ludeeus/action-shellcheck@master diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/.rultor.yml b/.rultor.yml new file mode 100644 index 0000000..2a59151 --- /dev/null +++ b/.rultor.yml @@ -0,0 +1,33 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +docker: + image: yegor256/rultor-image:1.23.1 +merge: + script: |- + sudo docker build "$(pwd)" +release: + pre: false + script: |- + [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1 + sed -i -e "s/^0.0.0/${tag}/" Dockerfile + sudo docker build "$(pwd)" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca17ae5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +FROM ruby:3.3 + +LABEL "repository"="https://github.com/zerocracy/pages-action" +LABEL "maintainer"="Yegor Bugayenko" + +RUN gem install judges + +RUN wget --no-verbose -O /usr/local/opt/Saxon.jar \ + https://repo.maven.apache.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-5/Saxon-HE-9.8.0-5.jar + +WORKDIR /home +COPY entry.sh /home +COPY xsl /home + +ENTRYPOINT ["/home/entry.sh"] diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..707a338 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Zerocracy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1315b19 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +.SHELLFLAGS: -c +.ONESHELL: +.PHONY: clean entry test +SAXON=/usr/local/opt/Saxon.jar + +entry: target/foo.fb test + export GITHUB_WORKSPACE=. + export INPUT_FACTBASE=target/foo.fb + export INPUT_PAGES=target/pages + ./entry.sh + +target/foo.fb: Makefile + mkdir -p target/judges/foo + echo '$$fb.insert.foo = 42' > target/judges/foo/foo.rb + judges update --max-cycles 5 target/judges $@ + +test: + mkdir -p target/html + for i in $$(ls tests/*.xml); do + name=$$(basename "$${i%.*}") + java -jar "$(SAXON)" "-s:$${i}" -xsl:xsl/index.xsl "-o:target/html/$${name}.html" + done + +clean: + rm -rf target diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab96ccf --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Pages Zerocracy Action + +[![test](https://github.com/zerocracy/pages-action/actions/workflows/test.yml/badge.svg)](https://github.com/zerocracy/pages-action/actions/workflows/test.yml) +[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/zerocracy/pages-action/blob/master/LICENSE.txt) + +Add it together with judges-action. + +## How to Contribute + +In order to test this action, just run (provided, you have +[GNU make](https://www.gnu.org/software/make/) installed): + +```bash +make +``` + +This should build a new Docker image named `pages-action` +and then run the entire cycle +inside a new Docker container. Obviously, you need to have +[Docker](https://docs.docker.com/get-docker/) installed. The Docker image +will be deleted by the end of Make build. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..e33935d --- /dev/null +++ b/action.yml @@ -0,0 +1,39 @@ +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +name: 'pages-action' +description: 'Build static pages from a Factbase' +runs: + using: 'docker' + image: Dockerfile +inputs: + verbose: + description: 'Log as much debug information as possible' + required: false + dir: + description: 'Directory path with YAML, XML, JSON and other files generated' + required: false + default: 'pages' + factbase: + description: 'Path of the factbase file' + required: true + default: 'recent.fb' diff --git a/entry.sh b/entry.sh new file mode 100755 index 0000000..05d291e --- /dev/null +++ b/entry.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# MIT License +# +# Copyright (c) 2024 Zerocracy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +set -e +set -x +set -o pipefail + +SAXON=/usr/local/opt/Saxon.jar + +export GLI_DEBUG=true + +# Convert the factbase to a few human-readable formats +if [ -z "${GITHUB_WORKSPACE}" ]; then + echo 'Probably you are running this script not from GitHub Actions.' + echo "Use 'make' instead: it configures all environment variables correctly." + exit 1 +fi +cd "${GITHUB_WORKSPACE}" + +declare -a gopts=() +if [ -n "${INPUT_VERBOSE}" ]; then + gopts+=("--verbose") +fi + +# Convert the factbase to a few human-readable formats +if [ -z "${INPUT_PAGES}" ]; then + echo "It is mandatory to specify the 'pages' argument, which is the name" + echo "of a directory where YAML, JSON, and other human-readable files" + echo "are going to be generated by the plugin" + exit 1 +fi +mkdir -p "${INPUT_PAGES}" + +for f in yaml xml json; do + target="${INPUT_FACTBASE%.*}.${f}" + judges "${gopts[@]}" print --format "${f}" "${INPUT_FACTBASE}" "${target}" + mv "${target}" "${INPUT_PAGES}" +done + +# Build a summary HTML. +index="${INPUT_FACTBASE%.*}.${f}" +judges "${gopts[@]}" print --format xml "${INPUT_FACTBASE}" "${index}" +java -jar ${SAXON} "-s:${index}" -xsl:xsl/index.xsl "-o:${INPUT_FACTBASE%.*}.html" + diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..39a2b6e --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} diff --git a/tests/simple.xml b/tests/simple.xml new file mode 100644 index 0000000..7e36af1 --- /dev/null +++ b/tests/simple.xml @@ -0,0 +1,17 @@ + + + 15 + yegor256 + for being a good boy + + + -25 + yegor256 + for being a bad boy + + + 30 + linus + for a new release + + \ No newline at end of file diff --git a/xsl/awards.xsl b/xsl/awards.xsl new file mode 100644 index 0000000..bb52471 --- /dev/null +++ b/xsl/awards.xsl @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + +
+ + + + + Programmer + + Score +
+
+ + + + + + + + + + + + + + # + + + + + + + + + https://github.com/ + + + @ + + + + + + + + + + + + + + + + + + +
diff --git a/xsl/index.xsl b/xsl/index.xsl new file mode 100644 index 0000000..65324d5 --- /dev/null +++ b/xsl/index.xsl @@ -0,0 +1,121 @@ + + + + + + + + + + + zerocracy + + + + + + + + + + + +
+
+

+ + + +

+
+
+ +
+
+

+ The page was generated by the + + pages-action + + + + plugin at + + , factbase version is +
+ The numbers you see reflect the activity of the last + + + days + + . +
+ The XML with the data + + is here + + . +

+
+
+ + +
+ + + + + +