Update propagate.yml to point to main branch only #487
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
workflow_call: | |
inputs: | |
r-version: | |
description: 'The version of R to use' | |
default: '4.1' | |
required: false | |
type: string | |
skip-coverage-badges: | |
description: 'Skip code coverage badge creation' | |
default: false | |
required: false | |
type: boolean | |
push: | |
branches: | |
- main | |
- devel | |
- pre-release | |
pull_request: | |
branches: | |
- main | |
- devel | |
- pre-release | |
name: Code Coverage | |
concurrency: | |
group: coverage-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
get_r_version: | |
name: Get R version | |
runs-on: ubuntu-latest | |
if: > | |
!contains(github.event.commits[0].message, '[skip coverage]') | |
outputs: | |
r-version: ${{ steps.normalizer.outputs.R_VERSION }} | |
steps: | |
- name: Normalize inputs | |
id: normalizer | |
run: | | |
R_VERSION="${{ inputs.r-version }}" | |
if [ "$R_VERSION" == "" ] | |
then { | |
R_VERSION="4.1" | |
} | |
fi | |
echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT | |
shell: bash | |
coverage: | |
name: Test Coverage | |
runs-on: ubuntu-latest | |
container: | |
image: "ghcr.io/pharmaverse/admiralci-${{needs.get_r_version.outputs.r-version}}:latest" | |
if: > | |
!contains(github.event.commits[0].message, '[skip coverage]') | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
coverage-percent: ${{ steps.set-coverage-percentage.outputs.coverage-percentage }} | |
needs: get_r_version | |
steps: | |
##################### BEGIN boilerplate steps ##################### | |
- name: Get branch names | |
id: branch-name | |
uses: tj-actions/[email protected] | |
- name: Checkout repo (PR) 🛎 | |
uses: actions/checkout@v3 | |
if: github.event_name == 'pull_request' | |
with: | |
ref: ${{ steps.branch-name.outputs.head_ref_branch }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
ref: ${{ steps.branch-name.outputs.head_ref_branch }} | |
- name: Normalize inputs | |
id: normalizer | |
run: | | |
R_VERSION="${{ inputs.r-version }}" | |
if [ "$R_VERSION" == "" ] | |
then { | |
R_VERSION="4.1" | |
} | |
fi | |
echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Restore cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.staged.dependencies | |
key: staged-deps | |
- name: Setup Pandoc | |
uses: r-lib/actions/setup-pandoc@v2 | |
- name: Run Staged dependencies | |
uses: insightsengineering/staged-dependencies-action@v1 | |
with: | |
run-system-dependencies: false | |
renv-restore: false | |
enable-check: false | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
##################### END boilerplate steps ##################### | |
- name: Run coverage 👟 | |
run: | | |
tryCatch( | |
expr = { | |
x <- covr::package_coverage( | |
path=".", | |
clean = FALSE, | |
quiet = FALSE | |
) | |
print(x) | |
covr::to_cobertura(x, filename = "coverage.xml") | |
p <- round(covr::percent_coverage(x)) | |
cat(p, file = "coverage.txt", sep = "") | |
covr::report( | |
x, | |
file = "coverage-report.html", | |
browse = FALSE | |
) | |
}, | |
error = function(e) { | |
message("Errors generated during coverage analysis:") | |
print(e) | |
error_file <- list.files(path = "/tmp", pattern="*.fail$", recursive = T, full.names = T)[1] | |
if (length(error_file) && file.exists(error_file)) { | |
cat("__________FULL OUTPUT__________") | |
writeLines(readLines(error_file)) | |
} | |
}, | |
warning = function(w) { | |
message("Warnings generated during coverage analysis:") | |
print(w) | |
} | |
) | |
shell: Rscript {0} | |
- name: Check whether coverage reports exists | |
id: check_coverage_reports | |
uses: andstor/file-existence-action@v1 | |
with: | |
files: "coverage.xml, coverage.txt, coverage-report.html" | |
- name: Set coverage percentage as output | |
id: set-coverage-percentage | |
run: echo "coverage-percentage=$(cat coverage.txt)" >> $GITHUB_OUTPUT | |
if: steps.check_coverage_reports.outputs.files_exists == 'true' | |
- name: Generate Coverage Summary Report | |
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request' | |
uses: irongut/[email protected] | |
with: | |
filename: coverage.xml | |
badge: true | |
fail_below_min: false | |
format: markdown | |
hide_branch_rate: true | |
hide_complexity: true | |
indicators: true | |
output: both | |
thresholds: '60 80' | |
- name: Upload report for review | |
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request' | |
uses: actions/upload-artifact@v2 | |
with: | |
name: coverage-report | |
path: "coverage-report.html" | |
continue-on-error: true | |
- name: Add Coverage PR Comment | |
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request' | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
header: code-coverage | |
path: code-coverage-results.md | |
continue-on-error: true | |
badge: | |
name: Generate badge for coverage | |
needs: [coverage] | |
runs-on: ubuntu-20.04 | |
if: > | |
inputs.skip-coverage-badges != 'true' || | |
!contains(github.event.commits[0].message, '[skip coverage]') | |
steps: | |
- name: Checkout the badges branch in repo | |
uses: actions/checkout@v3 | |
with: | |
ref: badges | |
path: badges | |
# Use the output from the `coverage` step | |
- name: Generate the badge SVG image | |
uses: emibcn/badge-action@v1 | |
id: badge | |
with: | |
label: 'Test Coverage' | |
status: "${{ needs.coverage.outputs.coverage-percent }}%" | |
color: ${{ | |
needs.coverage.outputs.coverage-percent > 90 && 'green' || | |
needs.coverage.outputs.coverage-percent > 80 && 'yellow,green' || | |
needs.coverage.outputs.coverage-percent > 70 && 'yellow' || | |
needs.coverage.outputs.coverage-percent > 60 && 'orange,yellow' || | |
needs.coverage.outputs.coverage-percent > 50 && 'orange' || | |
needs.coverage.outputs.coverage-percent > 40 && 'red,orange' || | |
needs.coverage.outputs.coverage-percent > 30 && 'red,red,orange' || | |
needs.coverage.outputs.coverage-percent > 20 && 'red,red,red,orange' || | |
'red' }} | |
path: badges/test-coverage.svg | |
- name: Commit badge | |
working-directory: ./badges | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions" | |
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
mkdir -p "${BRANCH}" | |
mv test-coverage.svg "${BRANCH}" | |
git add "${BRANCH}/test-coverage.svg" | |
git commit -m "Add/Update badge" || true | |
- name: Push badges | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: badges | |
directory: badges | |
continue-on-error: true |