Skip to content

Commit

Permalink
Merge pull request #137 from codecov/refactor-src
Browse files Browse the repository at this point in the history
chore: refactor source with new commands subfolder
  • Loading branch information
thomasrockhu-codecov committed Jun 17, 2022
2 parents 3bf44d6 + 1ebdd04 commit 54eb81c
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 108 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
101 changes: 0 additions & 101 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
version: 2.1

description: >
Expand All @@ -11,103 +10,3 @@ description: >
display:
source_url: https://github.com/codecov/codecov-circleci-orb
home_url: https://codecov.io/

commands:
upload:
parameters:
file:
description: Path to the code coverage data file to upload.
type: string
default: ""
flags:
description: Flag the upload to group coverage metrics (e.g. unittests
| integration | ui,chrome)
type: string
default: ""
token:
description: Set the private repository token as the value of the
variable CODECOV_TOKEN using CircleCI Environment Variables.
type: env_var_name
default: CODECOV_TOKEN
upload_name:
description: Custom defined name of the upload. Visible in Codecov UI
type: string
default: ${CIRCLE_BUILD_NUM}
validate:
description: Validate the uploader before uploading the codecov result.
type: boolean
default: true
when:
description: When should this step run?
type: string
default: "always"
xtra_args:
description: Any extra flags as provided by the bash uploader
(e.g. `-v -Z`).
type: string
default: ""
version:
description: Which version of the Codecov Uploader to use (defaults to
'latest')
type: string
default: "latest"
steps:
- run:
name: Download Codecov Uploader
command: |
family=$(uname -s | tr '[:upper:]' '[:lower:]')
os="windows"
[[ $family == "darwin" ]] && os="macos"
[[ $family == "linux" ]] && os="linux"
[[ $os == "linux" ]] && \
osID=$(grep -e "^ID=" /etc/os-release | cut -c4-)
[[ $osID == "alpine" ]] && os="alpine"
echo "Detected ${os}"
echo "export os=${os}" >> $BASH_ENV
filename="codecov"
[[ $os == "windows" ]] && filename+=".exe"
echo "export filename=${filename}" >> $BASH_ENV
[[ $os == "macos" ]] && \
HOMEBREW_NO_AUTO_UPDATE=1 brew install gpg
codecov_url="https://uploader.codecov.io"
codecov_url="$codecov_url/<< parameters.version >>"
codecov_url="$codecov_url/${os}/${filename}"
curl -Os $codecov_url
when: << parameters.when >>
- when:
condition: << parameters.validate >>
steps:
- run:
name: Validate Codecov Uploader
command: |
source $BASH_ENV
curl https://keybase.io/codecovsecurity/pgp_keys.asc | \
gpg --no-default-keyring --keyring trustedkeys.gpg --import
# One-time step
sha_url="https://uploader.codecov.io"
sha_url="$sha_url/<< parameters.version>>/${os}"
sha_url="$sha_url/${filename}.SHA256SUM"
curl -Os $sha_url
curl -Os $sha_url".sig"
gpgv $filename.SHA256SUM.sig $filename.SHA256SUM
shasum -a 256 -c $filename.SHA256SUM || \
sha256sum -c $filename.SHA256SUM
- run:
name: Upload Coverage Results
command: |
unset NODE_OPTIONS
# See https://github.com/codecov/uploader/issues/475
source $BASH_ENV
chmod +x $filename
[ -n "<< parameters.file >>" ] && \
set - "${@}" "-f" "<< parameters.file >>"
[ -n "<< parameters.xtra_args >>" ] && \
set - "${@}" "<< parameters.xtra_args >>"
./$filename \
-Q "codecov-circleci-orb-3.2.3" \
-t "${<< parameters.token >>}" \
-n "<< parameters.upload_name >>" \
-F "<< parameters.flags >>" \
${@}
68 changes: 68 additions & 0 deletions src/commands/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
description: |
Upload your coverage reports to Codecov without dealing with complex
configurations. This orb helps you get coverage results quickly so that you
can breathe easier and commit your code with confidence.
If running on `alpine` builds, the orb will need `coreutils`, `curl`, and
`gnupg` in order to validate.
parameters:
file:
description: Path to the code coverage data file to upload.
type: string
default: ""
flags:
description: Flag the upload to group coverage metrics (e.g. unittests
| integration | ui,chrome)
type: string
default: ""
token:
description: Set the private repository token as the value of the
variable CODECOV_TOKEN using CircleCI Environment Variables.
type: env_var_name
default: CODECOV_TOKEN
upload_name:
description: Custom defined name of the upload. Visible in Codecov UI
type: string
default: ${CIRCLE_BUILD_NUM}
validate:
description: Validate the uploader before uploading the codecov result.
type: boolean
default: true
when:
description: When should this step run?
type: string
default: "always"
xtra_args:
description: Any extra flags as provided by the bash uploader
(e.g. `-v -Z`).
type: string
default: ""
version:
description: Which version of the Codecov Uploader to use (defaults to
'latest')
type: string
default: "latest"

steps:
- run:
name: Download Codecov Uploader
command: <<include(scripts/download.sh)>>
when: << parameters.when >>
environment:
PARAM_VERSION: << parameters.version >>
- when:
condition: << parameters.validate >>
steps:
- run:
name: Validate Codecov Uploader
command: <<include(scripts/validate.sh)>>
- run:
name: Upload Coverage Results
command: <<include(scripts/upload.sh)>>
environment:
PARAM_FILE: << parameters.file >>
PARAM_FLAGS: << parameters.flags >>
PARAM_TOKEN: << parameters.token >>
PARAM_UPLOAD_NAME: << parameters.upload_name >>
PARAM_XTRA_ARGS: << parameters.xtra_args >>
2 changes: 1 addition & 1 deletion src/examples/basic_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
usage:
version: 2.1
orbs:
codecov: codecov/codecov@3.1.1
codecov: codecov/codecov@3.2.3
workflows:
upload-to-codecov:
jobs:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/node_test_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ usage:
version: 2.1
orbs:
node: circleci/node@4.7.0
codecov: codecov/codecov@3.1.1
codecov: codecov/codecov@3.2.3
workflows:
upload-to-codecov:
jobs:
Expand Down
22 changes: 22 additions & 0 deletions src/scripts/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
family=$(uname -s | tr '[:upper:]' '[:lower:]')
os="windows"
[[ $family == "darwin" ]] && os="macos"

[[ $family == "linux" ]] && os="linux"
[[ $os == "linux" ]] && \
osID=$(grep -e "^ID=" /etc/os-release | cut -c4-)
[[ $osID == "alpine" ]] && os="alpine"
echo "Detected ${os}"
echo "export os=${os}" >> $BASH_ENV
echo "export version=${PARAM_VERSION}" >> $BASH_ENV

filename="codecov"
[[ $os == "windows" ]] && filename+=".exe"
echo "export filename=${filename}" >> $BASH_ENV
[[ $os == "macos" ]] && \
HOMEBREW_NO_AUTO_UPDATE=1 brew install gpg
codecov_url="https://uploader.codecov.io"
codecov_url="$codecov_url/${PARAM_VERSION}"
codecov_url="$codecov_url/${os}/${filename}"
echo "Downloading ${codecov_url}"
curl -Os $codecov_url -v
15 changes: 15 additions & 0 deletions src/scripts/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
unset NODE_OPTIONS
# See https://github.com/codecov/uploader/issues/475
source $BASH_ENV
chmod +x $filename
[ -n "${PARAM_FILE}" ] && \
set - "${@}" "-f" "${PARAM_FILE}"
[ -n "${PARAM_XTRA_ARGS}" ] && \
set - "${@}" "${PARAM_XTRA_ARGS}"
# alpine doesn't allow for indirect expansion
./"$filename" \
-Q "codecov-circleci-orb-3.2.3" \
-t "$(eval echo \$$PARAM_TOKEN)" \
-n "${PARAM_UPLOAD_NAME}" \
-F "${PARAM_FLAGS}" \
${@}
13 changes: 13 additions & 0 deletions src/scripts/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
source $BASH_ENV
curl https://keybase.io/codecovsecurity/pgp_keys.asc | \
gpg --no-default-keyring --keyring trustedkeys.gpg --import
# One-time step
sha_url="https://uploader.codecov.io"
sha_url="$sha_url/${version}/${os}"
sha_url="$sha_url/${filename}.SHA256SUM"
echo "Downloading ${sha_url}"
curl -Os $sha_url
curl -Os $sha_url".sig"
gpgv $filename.SHA256SUM.sig $filename.SHA256SUM
shasum -a 256 -c $filename.SHA256SUM || \
sha256sum -c $filename.SHA256SUM
4 changes: 2 additions & 2 deletions test/calc.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/calc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Calculator from '../src/calculator/calc'
import Calculator from '../app/calculator/calc'
import { expect } from 'chai'

describe('Calculator', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/adder/test_adder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from src.adder.adder import Adder
from app.adder.adder import Adder


class TestAdderMethods(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/unit/subtractor/test_subtractor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from src.subtractor.subtractor import Subtractor
from app.subtractor.subtractor import Subtractor


class TestSubtractorMethods(unittest.TestCase):
Expand Down

0 comments on commit 54eb81c

Please sign in to comment.