From e3f21afa451f8c8cb5743cd08fe3c3450ff5a75b Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Thu, 7 Oct 2021 16:47:35 +0000 Subject: Use *.tmpl file extension over *.template --- example_reports/blank.template | 0 example_reports/blank.tmpl | 0 example_reports/ex.template | 1 - example_reports/ex.tmpl | 1 + public/templates/index.html.template | 38 --------------- public/templates/index.html.tmpl | 38 +++++++++++++++ public/templates/sh.template | 90 ------------------------------------ public/templates/sh.tmpl | 90 ++++++++++++++++++++++++++++++++++++ src/routes.test.ts | 10 +--- src/templates.test.ts | 4 +- src/util/config.ts | 4 +- 11 files changed, 135 insertions(+), 141 deletions(-) delete mode 100644 example_reports/blank.template create mode 100644 example_reports/blank.tmpl delete mode 100644 example_reports/ex.template create mode 100644 example_reports/ex.tmpl delete mode 100644 public/templates/index.html.template create mode 100644 public/templates/index.html.tmpl delete mode 100644 public/templates/sh.template create mode 100644 public/templates/sh.tmpl diff --git a/example_reports/blank.template b/example_reports/blank.template deleted file mode 100644 index e69de29..0000000 diff --git a/example_reports/blank.tmpl b/example_reports/blank.tmpl new file mode 100644 index 0000000..e69de29 diff --git a/example_reports/ex.template b/example_reports/ex.template deleted file mode 100644 index b55937a..0000000 --- a/example_reports/ex.template +++ /dev/null @@ -1 +0,0 @@ -But what is {{that}} other than {{potential}}? \ No newline at end of file diff --git a/example_reports/ex.tmpl b/example_reports/ex.tmpl new file mode 100644 index 0000000..b55937a --- /dev/null +++ b/example_reports/ex.tmpl @@ -0,0 +1 @@ +But what is {{that}} other than {{potential}}? \ No newline at end of file diff --git a/public/templates/index.html.template b/public/templates/index.html.template deleted file mode 100644 index f800a29..0000000 --- a/public/templates/index.html.template +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - AO Coverage: Simple code coverage tracking - - - - -
-
- -

Simple Code Coverage Tracking

-
-
-
-
-
-

AO Coverage is a simple code coverage tracking tool that stores your reports for public visibility and - provides a coverage badge for your projects. That’s all there is to it.

-

If you have a coverage token, uploading a report is as easy as adding this line to your CI pipeline:

-
-
- curl {{CURL_HTTPS}}-sSf {{TARGET_URL}}/sh | sh -
-
-

Visit the AO Coverage - documentation to learn more about uploading reports and discover more information about how AO Coverage - works.

-
-
-
- - - \ No newline at end of file diff --git a/public/templates/index.html.tmpl b/public/templates/index.html.tmpl new file mode 100644 index 0000000..f800a29 --- /dev/null +++ b/public/templates/index.html.tmpl @@ -0,0 +1,38 @@ + + + + + + + + AO Coverage: Simple code coverage tracking + + + + +
+
+ +

Simple Code Coverage Tracking

+
+
+
+
+
+

AO Coverage is a simple code coverage tracking tool that stores your reports for public visibility and + provides a coverage badge for your projects. That’s all there is to it.

+

If you have a coverage token, uploading a report is as easy as adding this line to your CI pipeline:

+
+
+ curl {{CURL_HTTPS}}-sSf {{TARGET_URL}}/sh | sh +
+
+

Visit the AO Coverage + documentation to learn more about uploading reports and discover more information about how AO Coverage + works.

+
+
+
+ + + \ No newline at end of file diff --git a/public/templates/sh.template b/public/templates/sh.template deleted file mode 100644 index 049b0b2..0000000 --- a/public/templates/sh.template +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env sh - -# Licensed under Parity Public License 7.0.0 -# The full version of this license can be found here: -# https://git.submelon.dev/kjhoerr/ao-coverage/raw/branch/trunk/LICENSE.md - -url="{{TARGET_URL}}" -commit="" -branch="" -repo="" -format="${FORMAT:-tarpaulin}" -report="" -token="$COV_TOKEN" -curl_verbosity="" -content_type="text/html" -extension="html" - -verbose_say() { - if [ -z "$SILENT" ] && [ "$VERBOSE" = "true" ]; then - echo "$1" - fi -} - -say() { - if [ -z "$SILENT" ]; then - echo "$1" - fi -} - -say "===========================" -say " ao-coverage " -say "===========================" -say - -verbose_say "Gathering report information . . ." - -if [ "$CI" = "true" ] && [ "$DRONE" = "true" ] ; then - verbose_say "Drone CI discovered - using Drone report info" - commit="$DRONE_COMMIT" - branch="$DRONE_BRANCH" - repo="$DRONE_REPO" -else - verbose_say "Using environment variables for report info" - commit="$VCS_COMMIT" - branch="$VCS_BRANCH" - repo="$VCS_REPO" -fi - -verbose_say "Using commit #: $commit" -verbose_say "Using branch: $branch" -verbose_say "Using repo: $repo" -verbose_say - -if [ "$format" = "tarpaulin" ]; then - report="${REPORT_FILE:-tarpaulin-report.html}" -elif [ "$format" = "cobertura" ]; then - report="${REPORT_FILE:-cobertura.xml}" - content_type="application/xml" - extension="xml" -fi - -if [ ! -f "$report" ]; then - say "Report file could not be found." - exit 1 -fi - -if [ "$VERBOSE" != "true" ]; then - curl_verbosity="-s" -fi - -say "Uploading $report . . ." - -response=$(curl -X POST --data-binary "@$report" \ - -H "Content-Type: $content_type" \ - $curl_verbosity \ - "$url/v1/$repo/$branch/$commit.$extension?token=$token&format=$format") - -if [ -n "$response" ]; then - say "Error uploading report: $response" - exit 1 -else - say "Successfully uploaded report!" - say - say "View uploaded report at: $url/v1/$repo/$branch/$commit.$extension" - say "View coverage badge at: $url/v1/$repo/$branch/$commit.svg" - say - say "Shorthand links are also available, as the latest commit of this branch." - say "View latest report for branch $branch: $url/v1/$repo/$branch.$extension" - say "View latest badge for branch $branch: $url/v1/$repo/$branch.svg" -fi diff --git a/public/templates/sh.tmpl b/public/templates/sh.tmpl new file mode 100644 index 0000000..049b0b2 --- /dev/null +++ b/public/templates/sh.tmpl @@ -0,0 +1,90 @@ +#!/usr/bin/env sh + +# Licensed under Parity Public License 7.0.0 +# The full version of this license can be found here: +# https://git.submelon.dev/kjhoerr/ao-coverage/raw/branch/trunk/LICENSE.md + +url="{{TARGET_URL}}" +commit="" +branch="" +repo="" +format="${FORMAT:-tarpaulin}" +report="" +token="$COV_TOKEN" +curl_verbosity="" +content_type="text/html" +extension="html" + +verbose_say() { + if [ -z "$SILENT" ] && [ "$VERBOSE" = "true" ]; then + echo "$1" + fi +} + +say() { + if [ -z "$SILENT" ]; then + echo "$1" + fi +} + +say "===========================" +say " ao-coverage " +say "===========================" +say + +verbose_say "Gathering report information . . ." + +if [ "$CI" = "true" ] && [ "$DRONE" = "true" ] ; then + verbose_say "Drone CI discovered - using Drone report info" + commit="$DRONE_COMMIT" + branch="$DRONE_BRANCH" + repo="$DRONE_REPO" +else + verbose_say "Using environment variables for report info" + commit="$VCS_COMMIT" + branch="$VCS_BRANCH" + repo="$VCS_REPO" +fi + +verbose_say "Using commit #: $commit" +verbose_say "Using branch: $branch" +verbose_say "Using repo: $repo" +verbose_say + +if [ "$format" = "tarpaulin" ]; then + report="${REPORT_FILE:-tarpaulin-report.html}" +elif [ "$format" = "cobertura" ]; then + report="${REPORT_FILE:-cobertura.xml}" + content_type="application/xml" + extension="xml" +fi + +if [ ! -f "$report" ]; then + say "Report file could not be found." + exit 1 +fi + +if [ "$VERBOSE" != "true" ]; then + curl_verbosity="-s" +fi + +say "Uploading $report . . ." + +response=$(curl -X POST --data-binary "@$report" \ + -H "Content-Type: $content_type" \ + $curl_verbosity \ + "$url/v1/$repo/$branch/$commit.$extension?token=$token&format=$format") + +if [ -n "$response" ]; then + say "Error uploading report: $response" + exit 1 +else + say "Successfully uploaded report!" + say + say "View uploaded report at: $url/v1/$repo/$branch/$commit.$extension" + say "View coverage badge at: $url/v1/$repo/$branch/$commit.svg" + say + say "Shorthand links are also available, as the latest commit of this branch." + say "View latest report for branch $branch: $url/v1/$repo/$branch.$extension" + say "View latest badge for branch $branch: $url/v1/$repo/$branch.svg" +fi diff --git a/src/routes.test.ts b/src/routes.test.ts index 151bf90..12210bf 100644 --- a/src/routes.test.ts +++ b/src/routes.test.ts @@ -116,13 +116,7 @@ describe("templates", () => { describe("GET /sh", () => { it("should return the sh file containing the curl command", async () => { await persistTemplate({ - inputFile: path.join( - __dirname, - "..", - "public", - "templates", - "sh.template" - ), + inputFile: path.join(__dirname, "..", "public", "templates", "sh.tmpl"), outputFile: path.join(HOST_DIR, "sh"), context: { TARGET_URL }, } as Template); @@ -142,7 +136,7 @@ describe("templates", () => { "..", "public", "templates", - "index.html.template" + "index.html.tmpl" ), outputFile: path.join(HOST_DIR, "index.html"), context: { TARGET_URL, CURL_HTTPS: "--https " }, diff --git a/src/templates.test.ts b/src/templates.test.ts index e434ce4..8fbf7e4 100644 --- a/src/templates.test.ts +++ b/src/templates.test.ts @@ -21,7 +21,7 @@ describe("processTemplate", () => { it("should process the template file with the given context", async () => { // Arrange - const template = genTemplate("ex.template"); + const template = genTemplate("ex.tmpl"); // Act const result = await processTemplate(template); @@ -34,7 +34,7 @@ describe("processTemplate", () => { it("should process the blank file", async () => { // Arrange - const template = genTemplate("blank.template"); + const template = genTemplate("blank.tmpl"); // Act const result = await processTemplate(template); diff --git a/src/util/config.ts b/src/util/config.ts index b98444c..c8639fb 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -79,12 +79,12 @@ export const handleStartup = async ( ); await persistTemplate({ - inputFile: path.join(publicDir, "templates", "sh.template"), + inputFile: path.join(publicDir, "templates", "sh.tmpl"), outputFile: path.join(hostDir, "sh"), context: { TARGET_URL: targetUrl }, } as Template); await persistTemplate({ - inputFile: path.join(publicDir, "templates", "index.html.template"), + inputFile: path.join(publicDir, "templates", "index.html.tmpl"), outputFile: path.join(hostDir, "index.html"), context: { TARGET_URL: targetUrl, -- cgit