From 308952bae0564cc70e64be59371d61d4cba75eb4 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 15:56:40 -0800 Subject: [PATCH 01/19] Adding codecov CI workflow. --- .github/workflows/codecov.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 000000000..0a58c0569 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,28 @@ + +name: Codecov + +on: + pull_request: + push: + branches: [main] + +jobs: + codecov: + container: + image: swift:5.3.2-bionic + runs-on: ubuntu-latest + steps: + - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 + - uses: actions/checkout@v2 + - run: LLVM_PROFILE_FILE='.build/codecov/default%m.profraw' swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests + - run: swift test --enable-test-discovery --enable-code-coverage + - uses: mattpolzin/swift-codecov-action@0.6.0 + with: + MINIMUM_COVERAGE: 98 + - name: comment PR + uses: unsplash/comment-on-pr@master + env: + GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + with: + msg: "Check out this message!" + check_for_duplicate_msg: false From 1a8b43bfc072a657c8e6e197d67041048825b502 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 16:01:29 -0800 Subject: [PATCH 02/19] doh. forgot to skip build. --- .github/workflows/codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 0a58c0569..fc23546c1 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -15,7 +15,7 @@ jobs: - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 - uses: actions/checkout@v2 - run: LLVM_PROFILE_FILE='.build/codecov/default%m.profraw' swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - - run: swift test --enable-test-discovery --enable-code-coverage + - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - uses: mattpolzin/swift-codecov-action@0.6.0 with: MINIMUM_COVERAGE: 98 From 59a8f438977c920d7f7a25dc0bd400d0219b9f77 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 16:10:18 -0800 Subject: [PATCH 03/19] drop unneeded llvm env var from build invocation. make comment always run. --- .github/workflows/codecov.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index fc23546c1..6a229becf 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -14,15 +14,16 @@ jobs: steps: - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 - uses: actions/checkout@v2 - - run: LLVM_PROFILE_FILE='.build/codecov/default%m.profraw' swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests + - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - uses: mattpolzin/swift-codecov-action@0.6.0 with: MINIMUM_COVERAGE: 98 - name: comment PR + if: ${{ always() }} uses: unsplash/comment-on-pr@master env: GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} with: - msg: "Check out this message!" + msg: "Your current code coverage percentage is ${{ env.CODECOV }} (minimum allowed: ${{ env.MINIMUM_COVERAGE }})." check_for_duplicate_msg: false From baa5be7db6f7a1817fa0ed53fa19f265c5d1d59a Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 16:53:08 -0800 Subject: [PATCH 04/19] try a way to update a previous comment --- .github/workflows/codecov.yml | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 6a229becf..04b22673a 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -16,14 +16,30 @@ jobs: - uses: actions/checkout@v2 - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - - uses: mattpolzin/swift-codecov-action@0.6.0 + - name: Coverage Report + uses: mattpolzin/swift-codecov-action@0.6.0 + id: cov with: MINIMUM_COVERAGE: 98 - - name: comment PR - if: ${{ always() }} - uses: unsplash/comment-on-pr@master - env: - GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + - name: Find Comment + uses: peter-evans/find-comment@v1 + id: fc with: - msg: "Your current code coverage percentage is ${{ env.CODECOV }} (minimum allowed: ${{ env.MINIMUM_COVERAGE }})." - check_for_duplicate_msg: false + body-includes: The current coverage percentage is + - name: Create comment + if: ${{ steps.fc.outputs.comment-id == 0 }} + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: | + The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.output.minimum_coverage }}%). + - name: Update comment + if: ${{ steps.fc.outputs.comment-id != 0 }} + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + comment-id: ${{ steps.fc.outputs.comment-id }} + body: | + The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.output.minimum_coverage }}%). + From af81de563d226bf48b62cc5640330757f51a06eb Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 17:00:46 -0800 Subject: [PATCH 05/19] try to get comments to run on failure. --- .github/workflows/codecov.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 04b22673a..1385134b3 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -22,12 +22,13 @@ jobs: with: MINIMUM_COVERAGE: 98 - name: Find Comment + if: ${{ always() }} uses: peter-evans/find-comment@v1 id: fc with: body-includes: The current coverage percentage is - name: Create comment - if: ${{ steps.fc.outputs.comment-id == 0 }} + if: ${{ always() && steps.fc.outputs.comment-id == 0 }} uses: peter-evans/create-or-update-comment@v1 with: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} @@ -35,7 +36,7 @@ jobs: body: | The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.output.minimum_coverage }}%). - name: Update comment - if: ${{ steps.fc.outputs.comment-id != 0 }} + if: ${{ always() && steps.fc.outputs.comment-id != 0 }} uses: peter-evans/create-or-update-comment@v1 with: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} From fd153d8d44e9d71cf0251decf7375d15ec82b879 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 17:13:43 -0800 Subject: [PATCH 06/19] use bug fix to codecov action. --- .github/workflows/codecov.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 1385134b3..7dbf7c114 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -17,15 +17,17 @@ jobs: - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - name: Coverage Report - uses: mattpolzin/swift-codecov-action@0.6.0 + uses: mattpolzin/swift-codecov-action@0.6.1 id: cov with: MINIMUM_COVERAGE: 98 - name: Find Comment if: ${{ always() }} - uses: peter-evans/find-comment@v1 + uses: peter-evans/find-comment@v1.1.1 id: fc with: + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} body-includes: The current coverage percentage is - name: Create comment if: ${{ always() && steps.fc.outputs.comment-id == 0 }} @@ -34,7 +36,7 @@ jobs: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} issue-number: ${{ github.event.pull_request.number }} body: | - The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.output.minimum_coverage }}%). + The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). - name: Update comment if: ${{ always() && steps.fc.outputs.comment-id != 0 }} uses: peter-evans/create-or-update-comment@v1 @@ -42,5 +44,5 @@ jobs: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} comment-id: ${{ steps.fc.outputs.comment-id }} body: | - The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.output.minimum_coverage }}%). + The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). From ac2487bf049c339d141a50ec12e40e8877f2dced Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 17:36:03 -0800 Subject: [PATCH 07/19] fix comment search string and drop min coverage --- .github/workflows/codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 7dbf7c114..7d23ff5c5 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -20,7 +20,7 @@ jobs: uses: mattpolzin/swift-codecov-action@0.6.1 id: cov with: - MINIMUM_COVERAGE: 98 + MINIMUM_COVERAGE: 20 - name: Find Comment if: ${{ always() }} uses: peter-evans/find-comment@v1.1.1 @@ -28,7 +28,7 @@ jobs: with: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} issue-number: ${{ github.event.pull_request.number }} - body-includes: The current coverage percentage is + body-includes: 'The current code coverage percentage is' - name: Create comment if: ${{ always() && steps.fc.outputs.comment-id == 0 }} uses: peter-evans/create-or-update-comment@v1 From 629613150411e7d6a104875c375ffbef75982143 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 18 Jan 2021 17:44:22 -0800 Subject: [PATCH 08/19] use replace on comment updates --- .github/workflows/codecov.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 7d23ff5c5..d77985546 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -31,7 +31,7 @@ jobs: body-includes: 'The current code coverage percentage is' - name: Create comment if: ${{ always() && steps.fc.outputs.comment-id == 0 }} - uses: peter-evans/create-or-update-comment@v1 + uses: peter-evans/create-or-update-comment@v1.4.4 with: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} issue-number: ${{ github.event.pull_request.number }} @@ -39,10 +39,11 @@ jobs: The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). - name: Update comment if: ${{ always() && steps.fc.outputs.comment-id != 0 }} - uses: peter-evans/create-or-update-comment@v1 + uses: peter-evans/create-or-update-comment@v1.4.4 with: token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace body: | The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). From f123034ef49dfeef44dcc9aa18c410e8afd44691 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 19 Jan 2021 08:48:33 -0800 Subject: [PATCH 09/19] attempt at diffing coverage from main branch --- .github/workflows/codecov.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index d77985546..166f7ede4 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -13,7 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 - - uses: actions/checkout@v2 + - name: Checkout Branch + uses: actions/checkout@v2 - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - name: Coverage Report @@ -21,6 +22,22 @@ jobs: id: cov with: MINIMUM_COVERAGE: 20 + - run: cp ./codecov.txt ./codecov-b.txt + if: ${{ always() }} + - name: Checkout Main + if: ${{ always() }} + uses: actions/checkout@v2 + with: + ref: main + - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests + if: ${{ always() }} + - run: swift test --enable-test-discovery --enable-code-coverage --skip-build + if: ${{ always() }} + - name: Main Branch Coverage + if: ${{ always() }} + uses: mattpolzin/swift-codecov-action@0.6.1 + - run: echo "COVDIFF='$(git diff ./coverage.txt ./coverage-b.txt)'" >> $GITHUB_ENV + if: ${{ always() }} - name: Find Comment if: ${{ always() }} uses: peter-evans/find-comment@v1.1.1 @@ -37,6 +54,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). + ${{ env.COVDIFF }} - name: Update comment if: ${{ always() && steps.fc.outputs.comment-id != 0 }} uses: peter-evans/create-or-update-comment@v1.4.4 @@ -46,4 +64,5 @@ jobs: edit-mode: replace body: | The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). + ${{ env.COVDIFF }} From de0dac9d77356a2c787df216766648f5e479ffe7 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 19 Jan 2021 21:15:10 -0800 Subject: [PATCH 10/19] comment out tests to affect test coverage --- .github/workflows/codecov.yml | 12 ++-- Tests/TokamakTests/ColorTests.swift | 100 ++++++++++++++-------------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 166f7ede4..1b642d999 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -22,7 +22,7 @@ jobs: id: cov with: MINIMUM_COVERAGE: 20 - - run: cp ./codecov.txt ./codecov-b.txt + - run: cp ./codecov.txt ../codecov-b.txt if: ${{ always() }} - name: Checkout Main if: ${{ always() }} @@ -36,7 +36,11 @@ jobs: - name: Main Branch Coverage if: ${{ always() }} uses: mattpolzin/swift-codecov-action@0.6.1 - - run: echo "COVDIFF='$(git diff ./coverage.txt ./coverage-b.txt)'" >> $GITHUB_ENV + - run: echo "$(diff ./codecov.txt ../codecov-b.txt)" + if: ${{ always() }} + - run: | + echo "::set-output name=covdiff::$(diff ./codecov.txt ../codecov-b.txt)" + id: covdiff if: ${{ always() }} - name: Find Comment if: ${{ always() }} @@ -54,7 +58,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). - ${{ env.COVDIFF }} + ${{ steps.covdiff.outputs.covdiff }} - name: Update comment if: ${{ always() && steps.fc.outputs.comment-id != 0 }} uses: peter-evans/create-or-update-comment@v1.4.4 @@ -64,5 +68,5 @@ jobs: edit-mode: replace body: | The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). - ${{ env.COVDIFF }} + ${{ steps.covdiff.outputs.covdiff }} diff --git a/Tests/TokamakTests/ColorTests.swift b/Tests/TokamakTests/ColorTests.swift index 56cf629e0..64245c23a 100644 --- a/Tests/TokamakTests/ColorTests.swift +++ b/Tests/TokamakTests/ColorTests.swift @@ -16,54 +16,54 @@ import XCTest final class ColorTests: XCTestCase { - func testHexColors() { - let env = EnvironmentValues() - guard let color = Color(hex: "#FF00FF")?.provider.resolve(in: env) else { - XCTFail("Hexadecimal decoding failed") - return - } - - XCTAssertEqual(color.red, 1) - XCTAssertEqual(color.green, 0) - XCTAssertEqual(color.blue, 1) - - XCTAssertEqual( - color, - Color(hex: "FF00FF")?.provider.resolve(in: env), - "The '#' before a hex code produced a different output than without it" - ) - - guard let red = Color(hex: "#FF0000")?.provider.resolve(in: env) else { - XCTFail("Hexadecimal decoding failed") - return - } - - XCTAssertEqual(red.red, 1) - XCTAssertEqual(red.green, 0) - XCTAssertEqual(red.blue, 0) - - guard let green = Color(hex: "#00FF00")?.provider.resolve(in: env) else { - XCTFail("Hexadecimal decoding failed") - return - } - - XCTAssertEqual(green.red, 0) - XCTAssertEqual(green.green, 1) - XCTAssertEqual(green.blue, 0) - - guard let blue = Color(hex: "#0000FF")?.provider.resolve(in: env) else { - XCTFail("Hexadecimal decoding failed") - return - } - - XCTAssertEqual(blue.red, 0) - XCTAssertEqual(blue.green, 0) - XCTAssertEqual(blue.blue, 1) - - let broken = Color(hex: "#P000FF") - XCTAssertEqual(broken, nil) - - let short = Color(hex: "F01") - XCTAssertEqual(short, nil) - } +// func testHexColors() { +// let env = EnvironmentValues() +// guard let color = Color(hex: "#FF00FF")?.provider.resolve(in: env) else { +// XCTFail("Hexadecimal decoding failed") +// return +// } +// +// XCTAssertEqual(color.red, 1) +// XCTAssertEqual(color.green, 0) +// XCTAssertEqual(color.blue, 1) +// +// XCTAssertEqual( +// color, +// Color(hex: "FF00FF")?.provider.resolve(in: env), +// "The '#' before a hex code produced a different output than without it" +// ) +// +// guard let red = Color(hex: "#FF0000")?.provider.resolve(in: env) else { +// XCTFail("Hexadecimal decoding failed") +// return +// } +// +// XCTAssertEqual(red.red, 1) +// XCTAssertEqual(red.green, 0) +// XCTAssertEqual(red.blue, 0) +// +// guard let green = Color(hex: "#00FF00")?.provider.resolve(in: env) else { +// XCTFail("Hexadecimal decoding failed") +// return +// } +// +// XCTAssertEqual(green.red, 0) +// XCTAssertEqual(green.green, 1) +// XCTAssertEqual(green.blue, 0) +// +// guard let blue = Color(hex: "#0000FF")?.provider.resolve(in: env) else { +// XCTFail("Hexadecimal decoding failed") +// return +// } +// +// XCTAssertEqual(blue.red, 0) +// XCTAssertEqual(blue.green, 0) +// XCTAssertEqual(blue.blue, 1) +// +// let broken = Color(hex: "#P000FF") +// XCTAssertEqual(broken, nil) +// +// let short = Color(hex: "F01") +// XCTAssertEqual(short, nil) +// } } From ad5fb72dc6020624a86ccfdbd3388ed82f67d9f7 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 31 Jan 2021 14:29:05 -0800 Subject: [PATCH 11/19] try method for multiline outputs --- .github/workflows/codecov.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 1b642d999..53a3eadbd 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -15,31 +15,35 @@ jobs: - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 - name: Checkout Branch uses: actions/checkout@v2 - - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - - name: Coverage Report + - name: Build Test Target + run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests + - name: Run Tests + run: swift test --enable-test-discovery --enable-code-coverage --skip-build + - name: Generate Branch Coverage Report uses: mattpolzin/swift-codecov-action@0.6.1 id: cov with: MINIMUM_COVERAGE: 20 - - run: cp ./codecov.txt ../codecov-b.txt + - name: Store Branch Report + run: cp ./codecov.txt ../codecov-b.txt if: ${{ always() }} - name: Checkout Main if: ${{ always() }} uses: actions/checkout@v2 with: ref: main - - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests + - name: Build Test Target + run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests if: ${{ always() }} - - run: swift test --enable-test-discovery --enable-code-coverage --skip-build + - name: Run Tests + run: swift test --enable-test-discovery --enable-code-coverage --skip-build if: ${{ always() }} - - name: Main Branch Coverage + - name: Generate Main Coverage Report if: ${{ always() }} uses: mattpolzin/swift-codecov-action@0.6.1 - - run: echo "$(diff ./codecov.txt ../codecov-b.txt)" - if: ${{ always() }} - - run: | - echo "::set-output name=covdiff::$(diff ./codecov.txt ../codecov-b.txt)" + - name: Diff Test Coverage + shell: bash + run: diff_cov_output="$(diff ./codecov.txt ../codecov-b.txt)" id: covdiff if: ${{ always() }} - name: Find Comment From 180ff3f795c578dc22ae1ade3615f91f2d3a1eb0 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 31 Jan 2021 16:05:52 -0800 Subject: [PATCH 12/19] do i need to put it in its own script file --- .github/workflows/codecov.yml | 2 +- cov_diff.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 cov_diff.sh diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 53a3eadbd..ee4ede451 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -43,7 +43,7 @@ jobs: uses: mattpolzin/swift-codecov-action@0.6.1 - name: Diff Test Coverage shell: bash - run: diff_cov_output="$(diff ./codecov.txt ../codecov-b.txt)" + run: pwd id: covdiff if: ${{ always() }} - name: Find Comment diff --git a/cov_diff.sh b/cov_diff.sh new file mode 100755 index 000000000..08b62206f --- /dev/null +++ b/cov_diff.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +diff_cov_output="$(diff ./codecov.txt ../codecov-b.txt)" +diff_cov_output="${diff_cov_output//'%'/'%25'}" +diff_cov_output="${diff_cov_output//$'\n'/'%0A'}" +diff_cov_output="${diff_cov_output//$'\r'/'%0D'}" + +echo "::set-output name=covdiff::$diff_cov_output" From c18cbb3f4150f8edb0f9e81cc3ac5990fdf95c21 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 31 Jan 2021 16:27:22 -0800 Subject: [PATCH 13/19] right, switch coverage gen order to have branch checked out second. --- .github/workflows/codecov.yml | 30 +++++++++++++++--------------- cov_diff.sh | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index ee4ede451..223c1246f 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -13,20 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 - - name: Checkout Branch - uses: actions/checkout@v2 - - name: Build Test Target - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - - name: Run Tests - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - - name: Generate Branch Coverage Report - uses: mattpolzin/swift-codecov-action@0.6.1 - id: cov - with: - MINIMUM_COVERAGE: 20 - - name: Store Branch Report - run: cp ./codecov.txt ../codecov-b.txt - if: ${{ always() }} - name: Checkout Main if: ${{ always() }} uses: actions/checkout@v2 @@ -41,9 +27,23 @@ jobs: - name: Generate Main Coverage Report if: ${{ always() }} uses: mattpolzin/swift-codecov-action@0.6.1 + - name: Store Main Report + run: cp ./codecov.txt ../codecov-main.txt + if: ${{ always() }} + - name: Checkout Branch + uses: actions/checkout@v2 + - name: Build Test Target + run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests + - name: Run Tests + run: swift test --enable-test-discovery --enable-code-coverage --skip-build + - name: Generate Branch Coverage Report + uses: mattpolzin/swift-codecov-action@0.6.1 + id: cov + with: + MINIMUM_COVERAGE: 20 - name: Diff Test Coverage shell: bash - run: pwd + run: ./cov_diff.sh id: covdiff if: ${{ always() }} - name: Find Comment diff --git a/cov_diff.sh b/cov_diff.sh index 08b62206f..9e6b148a4 100755 --- a/cov_diff.sh +++ b/cov_diff.sh @@ -1,6 +1,6 @@ #!/bin/bash -diff_cov_output="$(diff ./codecov.txt ../codecov-b.txt)" +diff_cov_output="$(diff ../codecov-main.txt ./codecov.txt)" diff_cov_output="${diff_cov_output//'%'/'%25'}" diff_cov_output="${diff_cov_output//$'\n'/'%0A'}" diff_cov_output="${diff_cov_output//$'\r'/'%0D'}" From 82c1d67ba3f0759505fbc66852e475bf79f748e3 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 31 Jan 2021 16:39:38 -0800 Subject: [PATCH 14/19] attempt to get code quotation around diff output. --- cov_diff.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cov_diff.sh b/cov_diff.sh index 9e6b148a4..68d4cd38e 100755 --- a/cov_diff.sh +++ b/cov_diff.sh @@ -1,6 +1,7 @@ #!/bin/bash -diff_cov_output="$(diff ../codecov-main.txt ./codecov.txt)" +diff_cov_output="$(diff ../codecov-main.txt ./codecov.txt | sed -n '/^[-=][^-=]/p' )" +diff_cov_output="\`\`\`diff $diff_cov_output \`\`\`" diff_cov_output="${diff_cov_output//'%'/'%25'}" diff_cov_output="${diff_cov_output//$'\n'/'%0A'}" diff_cov_output="${diff_cov_output//$'\r'/'%0D'}" From c7712358aa77dc1c6456f55955e7b698848dd14b Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 31 Jan 2021 16:49:25 -0800 Subject: [PATCH 15/19] switch to git diff --- cov_diff.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cov_diff.sh b/cov_diff.sh index 68d4cd38e..161210fbf 100755 --- a/cov_diff.sh +++ b/cov_diff.sh @@ -1,6 +1,6 @@ #!/bin/bash -diff_cov_output="$(diff ../codecov-main.txt ./codecov.txt | sed -n '/^[-=][^-=]/p' )" +diff_cov_output="$(git diff ../codecov-main.txt ./codecov.txt | sed -E -n '/^(---|\+\+\+|@@)/!p' | tail -n +3)" diff_cov_output="\`\`\`diff $diff_cov_output \`\`\`" diff_cov_output="${diff_cov_output//'%'/'%25'}" diff_cov_output="${diff_cov_output//$'\n'/'%0A'}" From de5f2d1c5b72b37f8320d807ce76f3c76234f318 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 31 Jan 2021 17:49:24 -0800 Subject: [PATCH 16/19] add note about the new script. --- cov_diff.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cov_diff.sh b/cov_diff.sh index 161210fbf..e2f735cff 100755 --- a/cov_diff.sh +++ b/cov_diff.sh @@ -1,5 +1,10 @@ #!/bin/bash +# responsible for apply diff to the results of test coverage +# from main and the current branch. +# This script only exists because you cannot count on local variable +# usage within scripts embedded in the GitHub Action workflow directly. + diff_cov_output="$(git diff ../codecov-main.txt ./codecov.txt | sed -E -n '/^(---|\+\+\+|@@)/!p' | tail -n +3)" diff_cov_output="\`\`\`diff $diff_cov_output \`\`\`" diff_cov_output="${diff_cov_output//'%'/'%25'}" From e98d646665647cb89c2f98287c61b944ba03d501 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Mon, 1 Feb 2021 17:32:18 -0800 Subject: [PATCH 17/19] try echoing a warning. --- .github/workflows/codecov.yml | 51 +++-------------------------------- cov_diff.sh | 14 ---------- 2 files changed, 3 insertions(+), 62 deletions(-) delete mode 100755 cov_diff.sh diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 223c1246f..aed94e1d4 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -13,23 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - run: apt-get update && apt-get install -y gtk+-3.0 libgtk+-3.0 - - name: Checkout Main - if: ${{ always() }} - uses: actions/checkout@v2 - with: - ref: main - - name: Build Test Target - run: swift build --enable-test-discovery -Xswiftc -profile-coverage-mapping -Xswiftc -profile-generate --product TokamakPackageTests - if: ${{ always() }} - - name: Run Tests - run: swift test --enable-test-discovery --enable-code-coverage --skip-build - if: ${{ always() }} - - name: Generate Main Coverage Report - if: ${{ always() }} - uses: mattpolzin/swift-codecov-action@0.6.1 - - name: Store Main Report - run: cp ./codecov.txt ../codecov-main.txt - if: ${{ always() }} - name: Checkout Branch uses: actions/checkout@v2 - name: Build Test Target @@ -41,36 +24,8 @@ jobs: id: cov with: MINIMUM_COVERAGE: 20 - - name: Diff Test Coverage - shell: bash - run: ./cov_diff.sh - id: covdiff + - name: Post Results if: ${{ always() }} - - name: Find Comment - if: ${{ always() }} - uses: peter-evans/find-comment@v1.1.1 - id: fc - with: - token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - issue-number: ${{ github.event.pull_request.number }} - body-includes: 'The current code coverage percentage is' - - name: Create comment - if: ${{ always() && steps.fc.outputs.comment-id == 0 }} - uses: peter-evans/create-or-update-comment@v1.4.4 - with: - token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - issue-number: ${{ github.event.pull_request.number }} - body: | - The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). - ${{ steps.covdiff.outputs.covdiff }} - - name: Update comment - if: ${{ always() && steps.fc.outputs.comment-id != 0 }} - uses: peter-evans/create-or-update-comment@v1.4.4 - with: - token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | - The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%). - ${{ steps.covdiff.outputs.covdiff }} + run: | + echo "::warning file=Package.swift,line=1,col=1::The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%)." diff --git a/cov_diff.sh b/cov_diff.sh deleted file mode 100755 index e2f735cff..000000000 --- a/cov_diff.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# responsible for apply diff to the results of test coverage -# from main and the current branch. -# This script only exists because you cannot count on local variable -# usage within scripts embedded in the GitHub Action workflow directly. - -diff_cov_output="$(git diff ../codecov-main.txt ./codecov.txt | sed -E -n '/^(---|\+\+\+|@@)/!p' | tail -n +3)" -diff_cov_output="\`\`\`diff $diff_cov_output \`\`\`" -diff_cov_output="${diff_cov_output//'%'/'%25'}" -diff_cov_output="${diff_cov_output//$'\n'/'%0A'}" -diff_cov_output="${diff_cov_output//$'\r'/'%0D'}" - -echo "::set-output name=covdiff::$diff_cov_output" From 769e62b5c71e1d2d2b881f78d3332ec860451841 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 2 Feb 2021 18:35:42 -0800 Subject: [PATCH 18/19] post warning on success and error on failure. --- .github/workflows/codecov.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index aed94e1d4..fac556b44 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -24,8 +24,12 @@ jobs: id: cov with: MINIMUM_COVERAGE: 20 - - name: Post Results - if: ${{ always() }} + - name: Post Positive Results + if: ${{ success() }} run: | - echo "::warning file=Package.swift,line=1,col=1::The current code coverage percentage is ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%)." + echo "::warning file=Package.swift,line=1,col=1::The current code coverage percentage is passing with ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%)." + - name: Post Negative Results + if: ${{ failure() }} + run: | + echo "::error file=Package.swift,line=1,col=1::The current code coverage percentage is failing with ${{ steps.cov.outputs.codecov }} (minimum allowed: ${{ steps.cov.outputs.minimum_coverage }}%)." From 80662774f309b87307b9afa563dd72ccad10bc02 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Wed, 3 Feb 2021 22:18:47 -0800 Subject: [PATCH 19/19] uncomment tests --- Tests/TokamakTests/ColorTests.swift | 100 ++++++++++++++-------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/Tests/TokamakTests/ColorTests.swift b/Tests/TokamakTests/ColorTests.swift index 64245c23a..56cf629e0 100644 --- a/Tests/TokamakTests/ColorTests.swift +++ b/Tests/TokamakTests/ColorTests.swift @@ -16,54 +16,54 @@ import XCTest final class ColorTests: XCTestCase { -// func testHexColors() { -// let env = EnvironmentValues() -// guard let color = Color(hex: "#FF00FF")?.provider.resolve(in: env) else { -// XCTFail("Hexadecimal decoding failed") -// return -// } -// -// XCTAssertEqual(color.red, 1) -// XCTAssertEqual(color.green, 0) -// XCTAssertEqual(color.blue, 1) -// -// XCTAssertEqual( -// color, -// Color(hex: "FF00FF")?.provider.resolve(in: env), -// "The '#' before a hex code produced a different output than without it" -// ) -// -// guard let red = Color(hex: "#FF0000")?.provider.resolve(in: env) else { -// XCTFail("Hexadecimal decoding failed") -// return -// } -// -// XCTAssertEqual(red.red, 1) -// XCTAssertEqual(red.green, 0) -// XCTAssertEqual(red.blue, 0) -// -// guard let green = Color(hex: "#00FF00")?.provider.resolve(in: env) else { -// XCTFail("Hexadecimal decoding failed") -// return -// } -// -// XCTAssertEqual(green.red, 0) -// XCTAssertEqual(green.green, 1) -// XCTAssertEqual(green.blue, 0) -// -// guard let blue = Color(hex: "#0000FF")?.provider.resolve(in: env) else { -// XCTFail("Hexadecimal decoding failed") -// return -// } -// -// XCTAssertEqual(blue.red, 0) -// XCTAssertEqual(blue.green, 0) -// XCTAssertEqual(blue.blue, 1) -// -// let broken = Color(hex: "#P000FF") -// XCTAssertEqual(broken, nil) -// -// let short = Color(hex: "F01") -// XCTAssertEqual(short, nil) -// } + func testHexColors() { + let env = EnvironmentValues() + guard let color = Color(hex: "#FF00FF")?.provider.resolve(in: env) else { + XCTFail("Hexadecimal decoding failed") + return + } + + XCTAssertEqual(color.red, 1) + XCTAssertEqual(color.green, 0) + XCTAssertEqual(color.blue, 1) + + XCTAssertEqual( + color, + Color(hex: "FF00FF")?.provider.resolve(in: env), + "The '#' before a hex code produced a different output than without it" + ) + + guard let red = Color(hex: "#FF0000")?.provider.resolve(in: env) else { + XCTFail("Hexadecimal decoding failed") + return + } + + XCTAssertEqual(red.red, 1) + XCTAssertEqual(red.green, 0) + XCTAssertEqual(red.blue, 0) + + guard let green = Color(hex: "#00FF00")?.provider.resolve(in: env) else { + XCTFail("Hexadecimal decoding failed") + return + } + + XCTAssertEqual(green.red, 0) + XCTAssertEqual(green.green, 1) + XCTAssertEqual(green.blue, 0) + + guard let blue = Color(hex: "#0000FF")?.provider.resolve(in: env) else { + XCTFail("Hexadecimal decoding failed") + return + } + + XCTAssertEqual(blue.red, 0) + XCTAssertEqual(blue.green, 0) + XCTAssertEqual(blue.blue, 1) + + let broken = Color(hex: "#P000FF") + XCTAssertEqual(broken, nil) + + let short = Color(hex: "F01") + XCTAssertEqual(short, nil) + } }