From cca92e4ba601b4a738807224b4abe53228bab1a0 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Fri, 17 Sep 2021 12:25:32 -0400 Subject: #14 Changed /bash file to /sh --- CHANGELOG.md | 4 ++ public/templates/bash.template | 90 ------------------------------------ public/templates/index.html.template | 2 +- public/templates/sh.template | 90 ++++++++++++++++++++++++++++++++++++ src/routes.test.ts | 14 +++--- src/routes.ts | 4 +- 6 files changed, 105 insertions(+), 99 deletions(-) delete mode 100644 public/templates/bash.template create mode 100644 public/templates/sh.template diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc01e3..dfefc27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Increased script file compatibility and moved to `/sh` + ## [0.5.0] ### Added diff --git a/public/templates/bash.template b/public/templates/bash.template deleted file mode 100644 index 375143e..0000000 --- a/public/templates/bash.template +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash - -# 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="tarpaulin" -report="" -token="$COV_TOKEN" -curl_verbosity="" -content_type="text/html" -extension="html" - -function verbose_say() { - if [ -z "$SILENT" ] && [ "$VERBOSE" == "true" ]; then - echo "$1" - fi -} - -function say() { - if [ -z "$SILENT" ]; then - echo "$1" - fi -} - -say "===========================" -say " ao-coverage " -say "===========================" -say - -verbose_say "Gathering report information . . ." - -if [ "$CI" == "drone" ]; 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 [ ! -z "$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 \ No newline at end of file diff --git a/public/templates/index.html.template b/public/templates/index.html.template index 4fb8930..2494e59 100644 --- a/public/templates/index.html.template +++ b/public/templates/index.html.template @@ -24,7 +24,7 @@

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

- bash <(curl -s {{TARGET_URL}}/bash) + curl --proto '=https' --tlsv1.2 -sSf {{TARGET_URL}}/sh | sh

Visit the AO Coverage diff --git a/public/templates/sh.template b/public/templates/sh.template new file mode 100644 index 0000000..0e8e34c --- /dev/null +++ b/public/templates/sh.template @@ -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="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" = "drone" ]; 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 5ffd289..d761602 100644 --- a/src/routes.test.ts +++ b/src/routes.test.ts @@ -88,21 +88,21 @@ const HOST_DIR = configOrError("HOST_DIR"); const TARGET_URL = process.env.TARGET_URL ?? "http://localhost:3000"; describe("templates", () => { - describe("GET /bash", () => { - it("should return the bash file containing the curl command", async () => { + describe("GET /sh", () => { + it("should return the sh file containing the curl command", async () => { await persistTemplate({ inputFile: path.join( __dirname, "..", "public", "templates", - "bash.template" + "sh.template" ), - outputFile: path.join(HOST_DIR, "bash"), + outputFile: path.join(HOST_DIR, "sh"), context: { TARGET_URL } } as Template); - const res = await (await request()).get("/bash").expect(200); + const res = await (await request()).get("/sh").expect(200); expect(exit).not.toHaveBeenCalled(); expect(res.text).toMatch("curl -X POST"); expect(res.text).toMatch(`url="${TARGET_URL}"`); @@ -128,7 +128,9 @@ describe("templates", () => { .expect("Content-Type", /html/) .expect(200); expect(exit).not.toHaveBeenCalled(); - expect(res.text).toMatch(`bash <(curl -s ${TARGET_URL}/bash)`); + expect(res.text).toMatch( + `curl --proto '=https' --tlsv1.2 -sSf ${TARGET_URL}/sh | sh` + ); }); }); }); diff --git a/src/routes.ts b/src/routes.ts index d242902..3ab55ae 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -60,8 +60,8 @@ export default (metadata: Metadata): Router => { // serve script for posting coverage report router.use( - "/bash", - express.static(path.join(metadata.getHostDir(), "bash"), { + "/sh", + express.static(path.join(metadata.getHostDir(), "sh"), { setHeaders: res => res.contentType("text/plain") }) ); -- cgit