Skip to content

Commit

Permalink
feat: transform code coverage jsons into cobertura reports
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Jan 10, 2025
1 parent 806b282 commit 7ceba8d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 18 deletions.
31 changes: 16 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ FROM python:3.12.8-alpine3.20
LABEL maintainer="Nicolas VUILLAMY <[email protected]>"

RUN apk add --update --no-cache \
coreutils \
git \
bash \
nodejs \
npm \
# Required for docker
docker \
openrc \
# Required for puppeteer
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont
coreutils \
git \
bash \
nodejs \
npm \
# Required for docker
docker \
openrc \
# Required for puppeteer
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont

# Start docker daemon in case mermaid-cli image is used
RUN rc-update add docker boot && (rc-service docker start || true)
Expand All @@ -44,6 +44,7 @@ RUN npm install --no-cache yarn -g && \
echo 'y' | sf plugins install sfdmu && \
echo 'y' | sf plugins install sfdx-git-delta && \
echo 'y' | sf plugins install texei-sfdx-plugin && \
echo 'y' | sf plugins install apex-code-coverage-transformer && \
sf version --verbose --json && \
rm -rf /root/.npm/_cacache

Expand Down
1 change: 1 addition & 0 deletions defaults/ci/.github/workflows/check-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
sf plugins install @salesforce/plugin-packaging
echo 'y' | sf plugins install sfdx-hardis
echo 'y' | sf plugins install sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
# Login & check deploy with test classes & code coverage
- name: Login & Simulate deployment
Expand Down
1 change: 1 addition & 0 deletions defaults/ci/.github/workflows/process-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
echo 'y' | sf plugins install sfdx-hardis
# echo 'y' | sf plugins install sfdmu # Disabled while it does not play well with @salesforce/cli
echo 'y' | sf plugins install sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
# Set env branch variable (github.ref_name seems to not work)
- name: Set env.BRANCH
Expand Down
1 change: 1 addition & 0 deletions defaults/ci/azure-pipelines-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
sf plugins install @salesforce/plugin-packaging
echo 'y' | sf plugins install sfdx-hardis
echo 'y' | sf plugins install sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
displayName: "Install SFDX & plugins"
Expand Down
1 change: 1 addition & 0 deletions defaults/ci/azure-pipelines-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
echo 'y' | sf plugins install sfdx-hardis
echo 'y' | sf plugins install sfdmu
echo 'y' | sf plugins install sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
displayName: "Install SFDX & plugins"
Expand Down
2 changes: 2 additions & 0 deletions defaults/ci/bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pipelines:
- sf plugins install @salesforce/plugin-packaging
- echo 'y' | sf plugins install sfdx-hardis
- echo 'y' | sf plugins install sfdx-git-delta
- echo 'y' | sf plugins install apex-code-coverage-transformer
- sf version --verbose --json
- export BRANCH_NAME=$(echo "$BITBUCKET_PR_DESTINATION_BRANCH" | sed 's/refs\/heads\///')
- export CI_COMMIT_REF_NAME=$BRANCH_NAME
Expand All @@ -45,6 +46,7 @@ pipelines:
- sf plugins install @salesforce/plugin-packaging
- echo 'y' | sf plugins install sfdx-hardis
- echo 'y' | sf plugins install sfdx-git-delta
- echo 'y' | sf plugins install apex-code-coverage-transformer
- sf version --verbose --json
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | sed 's/refs\/heads\///')
- export CI_COMMIT_REF_NAME=$BRANCH_NAME
Expand Down
3 changes: 3 additions & 0 deletions defaults/monitoring/.github/workflows/org-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
sf plugins install --force @salesforce/plugin-packaging
echo 'y' | sf plugins install --force sfdx-hardis
echo 'y' | sf plugins install --force sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
# Login & check deploy with test classes & code coverage
- name: Login & Retrieve Metadata
Expand Down Expand Up @@ -158,6 +159,7 @@ jobs:
sf plugins install --force @salesforce/plugin-packaging
echo 'y' | sf plugins install --force sfdx-hardis
echo 'y' | sf plugins install --force sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
# Login & check deploy with test classes & code coverage
- name: Login & Run apex tests
Expand Down Expand Up @@ -298,6 +300,7 @@ jobs:
sf plugins install --force @salesforce/plugin-packaging
echo 'y' | sf plugins install --force sfdx-hardis
echo 'y' | sf plugins install --force sfdx-git-delta
echo 'y' | sf plugins install apex-code-coverage-transformer
sf version --verbose --json
# Login & check deploy with test classes & code coverage
- name: Login & Run monitoring checks
Expand Down
3 changes: 3 additions & 0 deletions defaults/monitoring/bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pipelines:
- sf plugins install @salesforce/plugin-packaging
- echo 'y' | sf plugins install sfdx-hardis
- echo 'y' | sf plugins install sfdx-git-delta
- echo 'y' | sf plugins install apex-code-coverage-transformer
- sf version --verbose --json
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | sed 's/refs\/heads\///')
- export CI_COMMIT_REF_NAME=$BRANCH_NAME
Expand Down Expand Up @@ -54,6 +55,7 @@ pipelines:
- sf plugins install @salesforce/plugin-packaging
- echo 'y' | sf plugins install sfdx-hardis
- echo 'y' | sf plugins install sfdx-git-delta
- echo 'y' | sf plugins install apex-code-coverage-transformer
- sf version --verbose --json
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | sed 's/refs\/heads\///')
- export CI_COMMIT_REF_NAME=$BRANCH_NAME
Expand Down Expand Up @@ -93,6 +95,7 @@ pipelines:
- sf plugins install @salesforce/plugin-packaging
- echo 'y' | sf plugins install sfdx-hardis
- echo 'y' | sf plugins install sfdx-git-delta
- echo 'y' | sf plugins install apex-code-coverage-transformer
- sf version --verbose --json
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | sed 's/refs\/heads\///')
- export CI_COMMIT_REF_NAME=$BRANCH_NAME
Expand Down
15 changes: 12 additions & 3 deletions src/common/utils/deployUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
execSfdxJson,
findJsonInString,
getCurrentGitBranch,
getGitRepoRoot,
git,
gitHasLocalUpdates,
isCI,
Expand Down Expand Up @@ -1327,7 +1328,7 @@ export async function generateApexCoverageOutputFile(commandOutput: string | any
typeof commandOutput === 'object' && commandOutput.stderr ? commandOutput.stderr :
JSON.stringify(commandOutput);
const reportDir = await getReportDirectory();
const coverageFileName = path.join(reportDir, "apex-coverage-results.json");
const jsonCoverageFileName = path.join(reportDir, "apex-coverage-results.json");
let coverageObject: any = null;
const jsonLog = findJsonInString(outputString);
// Output from sf project deploy start or similar: extract from JSON
Expand All @@ -1339,8 +1340,16 @@ export async function generateApexCoverageOutputFile(commandOutput: string | any
coverageObject = JSON.parse(fs.readFileSync(path.join(reportDir, "test-result-codecoverage.json"), 'utf8'));
}
if (coverageObject !== null) {
await fs.writeFile(coverageFileName, JSON.stringify(coverageObject, null, 2), 'utf8');
uxLog(this, c.cyan(`Written Apex coverage results in file ${coverageFileName}`));
await fs.writeFile(jsonCoverageFileName, JSON.stringify(coverageObject, null, 2), 'utf8');
const outputCoverageFileName = path.join(reportDir, "apex-coverage-results.xml");
const accTransformerCommand = `sf acc-transformer transform -j "${jsonCoverageFileName}" -r "${outputCoverageFileName}" -f "cobertura"`;
await execSfdxJson(accTransformerCommand, this, {
output: true,
fail: false,
debug: false,
cwd: await getGitRepoRoot(),
});
uxLog(this, c.cyan(`Written Apex coverage results in file ${outputCoverageFileName}`));
}
} catch (e: any) {
uxLog(this, c.red(`Error while generating Apex coverage output file: ${e.message}`));
Expand Down

0 comments on commit 7ceba8d

Please sign in to comment.