Skip to content

Commit

Permalink
chore: CI/CD pipeline for TM grammar coverage badge
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-semenov committed May 1, 2024
1 parent 6b2cf88 commit 13ad886
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 24 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/coverage-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: "TextMate Grammar Coverage Badge"

on:
push:
branches: [ main ]
paths: [ "src/**", "tests/**" ]
pull_request:
branches: [ main ]
paths: [ "src/**", "tests/**" ]

jobs:
Compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Import GPG key
id: import-gpg
uses: crazy-max/[email protected]
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: Get SVG
run: make -B $(pwd)/images/coverage-badge.svg

- name: GPG user
run: |
echo "fingerprint: ${{ steps.import-gpg.outputs.fingerprint }}"
echo "username: ${{ steps.import-gpg.outputs.name }}"
echo "email: ${{ steps.import-gpg.outputs.email }}"
- name: Auto-commit changes
id: auto-commit-action
uses: stefanzweifel/[email protected]
with:
commit_message: auto-commit of updated coverage badge
branch: main
commit_options: '--no-verify --signoff -S'
file_pattern: 'images/*'
commit_user_name: "${{ steps.import-gpg.outputs.name }}"
commit_user_email: "${{ steps.import-gpg.outputs.email }}"

- name: Run if changes have been detected
if: steps.auto-commit-action.outputs.changes_detected == 'true'
run: echo "New code coverage was published"
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "Pre-commit"
name: "Pre-Commit"

on:
push:
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,18 @@ $(BUILD_DIR)gp_builtins.json: $(foreach item,$(GP_ITEMS),$(BUILD_DIR)gp_$(item).
$(BUILD_DIR)parigp.sublime-tooltip: $(BUILD_DIR)gp_commands.tsv
@cat $< |\
jq -R '[inputs | split("\t") | {(.[0]): {name: .[0], descr: .[2]}}] | add' > $@

$(ROOT_DIR)images/coverage-badge.svg:
$(eval REFS := $(shell yq \
'[.. | select(has("name") and .name != "PARI/GP") | .name] | @tsv' \
$(ROOT_DIR)src/*.YAML-tmLanguage* |\
xargs -n1 | sort | uniq))
$(eval SCOPES_UNDER_TEST := $(shell tail -n+2 $(ROOT_DIR)tests/*.test.gp |\
grep -o 'source.parigp.*$$' |\
xargs -n1 | sort | uniq))
$(eval DIFF := $(shell echo $(REFS) $(SCOPES_UNDER_TEST) | tr ' ' '\n' | sort | uniq -u | xargs -n1))
$(eval COVERAGE := $(shell echo "scale=4 ; 100.0 * (1.0 - $(shell echo $(DIFF) | wc -w) / $(shell echo $(REFS) | wc -w))" | bc))
@xsltproc --param coverage $(COVERAGE) \
--output $@ \
$(ROOT_DIR)/scripts/coverage-badge.xsl \
$(ROOT_DIR)/scripts/coverage-badge.xsl
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PARI/GP Programming Language

A Textmate language grammar for programming language of PARI/GP computer algebra system.

![Grammar Coverage](https://github.com/piotr-semenov/parigp-lang/blob/main/images/coverage-badge.svg)
49 changes: 26 additions & 23 deletions images/coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions scripts/coverage-badge.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg">

<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:param name="coverage" select="50" as="xsl:integer" />

<xsl:template match="/">
<svg xmlns="http://www.w3.org/2000/svg" width="140px" height="20px" role="img">
<title>TextMate Grammar Coverage</title>
<linearGradient id="a" x2="0" y2="100%">
<stop offset="0" stop-opacity=".1" stop-color="#EEE"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="m"><rect width="100%" height="100%" rx="3" fill="#FFF"/></mask>
<g mask="url(#m)">
<rect x="0" y="0" width="69" height="20" fill="#444"/>
<svg x="69" y="0" width="71" height="20">
<rect width="100%" height="100%" fill="#888888"/>
<rect width="0%" height="100%" fill="#33CC11" transform="">
<animate attributeName="width" begin="0.5s" dur="600ms" from="0%" to="{$coverage}%" repeatCount="1" fill="freeze" calcMode="spline" keyTimes="0; 1" keySplines="0.3, 0.61, 0.355, 1"/>
</rect>
</svg>
<rect width="140" height="20" fill="url(#a)"/>
</g>
<g aria-hidden="true" font-size="11" font-family="Verdana, DejaVu Sans, sans-serif" fill="#FFFFFF">
<text x="6" y="15" fill="#000" opacity="0.25">Coverage</text>
<text x="5" y="14">Coverage</text>
<text x="135" y="15" fill="#000" opacity="0.25" text-anchor="end"><xsl:value-of select="$coverage" />%</text>
<text x="134" y="14" text-anchor="end"><xsl:value-of select="$coverage" />%</text>
</g>
</svg>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 13ad886

Please sign in to comment.