Render README #10
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
name: Render README | |
on: | |
workflow_dispatch: | |
inputs: | |
r-version: | |
description: 'The version of R to use' | |
default: 'release' | |
required: false | |
type: choice | |
options: | |
- devel | |
- latest | |
skip-md-formatting: | |
description: 'Skip markdown auto-formatting' | |
default: false | |
required: false | |
type: boolean | |
workflow_call: | |
inputs: | |
r-version: | |
description: 'The version of R to use' | |
default: 'release' | |
required: false | |
type: string | |
skip-md-formatting: | |
description: 'Skip markdown auto-formatting' | |
default: false | |
required: false | |
type: boolean | |
jobs: | |
render: | |
name: Render | |
runs-on: ubuntu-latest | |
container: | |
image: "ghcr.io/pharmaverse/admiralci-${{ inputs.r-version }}:latest" | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
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: 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 }} | |
- name: Install dependencies from DESCRIPTION | |
run: | | |
remotes::install_local(force = TRUE, dependencies = TRUE) | |
shell: Rscript {0} | |
##################### END boilerplate steps ##################### | |
- name: Render README to markdown | |
run: | | |
if (file.exists("README.Rmd")) { | |
rmarkdown::render("README.Rmd", output_format = "md_document") | |
} | |
shell: Rscript {0} | |
env: | |
BRANCH_NAME: "${{ steps.branch-name.outputs.current_branch }}" | |
- name: Install Markdown formatter | |
if: ${{ !inputs.skip-md-formatting }} | |
run: | | |
npm install -g n # upgrade node version to use markdown-formatter | |
n latest | |
n prune | |
hash -r | |
node --version | |
npm install -g @quilicicf/markdown-formatter | |
shell: bash | |
- name: Commit and push formatted README.md | |
run: | | |
if [ "${{ inputs.skip-md-formatting }}" != "true" ] | |
then { | |
markdown-format -r -f README.md | |
} | |
fi | |
git config --global --add safe.directory "${GITHUB_WORKSPACE}" | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions" | |
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
git add README.md | |
git commit -m "[actions skip] Add/Update README.md for ${BRANCH}" || true | |
git push origin ${BRANCH} || echo "No changes to commit" |