Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/phs_document.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:

name: phs_document.yaml

permissions:
contents: read
pull-requests: read

jobs:
phs_document:
name: "Automatically re-build the package documentation"
runs-on: ubuntu-latest
container:
image: rocker/r-ver
permissions:
contents: write
pull-requests: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Install git
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git

- name: Mark workspace as safe for Git
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Checkout repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@bd49c52ffe281809afa6f0fecbf37483c5dd0b93 # v2.11.3
with:
extra-packages: |
any::roxygen2
any::desc
needs: |
website
coverage

- name: Normalise DESCRIPTION
run: desc::desc_normalize()
shell: Rscript {0}

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: Commit and push changes
id: commit_step_document
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0
with:
commit_message: "Document package (GHA)"
continue-on-error: true

- name: Create Pull Request
if: ${{ steps.commit_step_document.outputs.changes_detected == 'true' && steps.commit_step_document.outcome == 'failure' }}
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
commit-message: "Document package (GHA)"
branch: auto-document-code
delete-branch: true
title: "Document package (GHA)"
labels: maintenance
base: ${{ github.event.pull_request.base.ref }}
body: |
This Pull Request was automatically created to apply documentation changes to your code.
Please review and merge this PR.
assignees: ${{ github.actor }}
reviewers: ${{ github.actor }}
32 changes: 21 additions & 11 deletions .github/workflows/phs_package_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
contents: read
pull-requests: read
statuses: read

jobs:
# Initial job to post status
init:
Expand All @@ -35,8 +35,18 @@ jobs:
description: 'Package checks in progress',
context: 'PHS Package Checks'
});
Style_and_document:
uses: ./.github/workflows/phs_style_and_document.yaml
Style:
uses: ./.github/workflows/phs_style.yaml
permissions:
contents: write
pull-requests: write
secrets: inherit
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Document:
needs: [Style]
uses: ./.github/workflows/phs_document.yaml
permissions:
contents: write
pull-requests: write
Expand All @@ -45,7 +55,7 @@ jobs:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
R-CMD-check-core:
needs: [Style_and_document]
needs: [Style, Document]
uses: ./.github/workflows/phs_R-CMD-check-core.yaml
permissions:
contents: read
Expand All @@ -72,14 +82,15 @@ jobs:
group: ${{ inputs.limit_parallel == false && format('test-coverage-{0}-{1}', github.workflow, github.run_id) || 'package-checks-queue' }}
cancel-in-progress: false
pkgdown:
needs: [Style_and_document]
needs: [Document]
uses: ./.github/workflows/phs_pkgdown.yaml
permissions:
contents: write
secrets: inherit

# Final job to update status
finalize:
needs: [Style_and_document, R-CMD-check-core, test-coverage, pkgdown]
needs: [Style, Document, R-CMD-check-core, test-coverage, pkgdown]
runs-on: ubuntu-latest
if: always()
permissions:
Expand All @@ -89,11 +100,10 @@ jobs:
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const allSuccess = ${{ needs.Style_and_document.result == 'success' &&
needs.R-CMD-check-core.result == 'success' &&
needs.test-coverage.result == 'success' &&
needs.pkgdown.result == 'success' }};

const allSuccess = ${{ needs.Style.result == 'success' &&
needs.Document.result == 'success' &&
needs.R-CMD-check-core.result == 'success' &&
needs.test-coverage.result == 'success'}};
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
137 changes: 137 additions & 0 deletions .github/workflows/phs_style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:

name: phs_style.yaml

permissions:
contents: read
pull-requests: read

jobs:
phs_style:
name: "Automatically style the code using air"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Install posit-dev/air
uses: posit-dev/setup-air@63e80dedb6d275c94a3841e15e5ff8691e1ab237 # v1.0.0

- name: Include standard air.toml (overwrite existing)
run: |
echo '[format]' > air.toml
echo 'line-ending = "lf"' >> air.toml

- name: Add air.toml to .Rbuildignore if it exists
run: |
if [ -f .Rbuildignore ]; then
grep -qxF 'air.toml' .Rbuildignore || echo 'air.toml' >> .Rbuildignore
fi

- name: Format using air
run: air format .

- name: Detect changed .Rmd files
id: changed_rmd
shell: bash
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
else
BASE_SHA="${{ github.event.before }}"
HEAD_SHA="${{ github.sha }}"
fi
# Handle first-push edge case: all-zero before SHA
if [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
CHANGED_RMD="$(git ls-files | grep -E '\.Rmd$' || true)"
else
CHANGED_RMD="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep -E '\.Rmd$' || true)"
fi
if [ -n "$CHANGED_RMD" ]; then
echo "rmd_changed=true" >> "$GITHUB_OUTPUT"
else
echo "rmd_changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Setup R
if: steps.changed_rmd.outputs.rmd_changed == 'true'
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install styler deps (cached)
if: steps.changed_rmd.outputs.rmd_changed == 'true'
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::styler
any::roxygen2
any::knitr

- name: Enable styler cache
if: steps.changed_rmd.outputs.rmd_changed == 'true'
run: styler::cache_activate()
shell: Rscript {0}

- name: Determine styler cache location
if: steps.changed_rmd.outputs.rmd_changed == 'true'
id: styler-location
run: |
cat(
"location=",
styler::cache_info(format = "tabular")$location,
"\n",
file = Sys.getenv("GITHUB_OUTPUT"),
append = TRUE,
sep = ""
)
shell: Rscript {0}

- name: Cache styler results
if: steps.changed_rmd.outputs.rmd_changed == 'true'
uses: actions/cache@v5
with:
path: ${{ steps.styler-location.outputs.location }}
key: ${{ runner.os }}-styler-${{ hashFiles('**/*.Rmd', '**/*.rmarkdown') }}
restore-keys: |
${{ runner.os }}-styler-

- name: Style .Rmd using styler
if: steps.changed_rmd.outputs.rmd_changed == 'true'
run: Rscript -e 'styler::style_dir(".", filetype = c("rmd", "rmarkdown"))'

- name: Commit and push changes
id: commit_step_style
uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5.2.0
with:
commit_message: "Style code (GHA)"
continue-on-error: true

- name: Create Pull Request
if: ${{ steps.commit_step_style.outputs.changes_detected == 'true' && steps.commit_step_style.outcome == 'failure' }}
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
commit-message: "Style code (GHA)"
branch: auto-style-code
delete-branch: true
title: "Style code (GHA)"
labels: maintenance
base: ${{ github.event.pull_request.base.ref }}
body: |
This Pull Request was automatically created to apply styling changes to your code.
Please review and merge this PR.
assignees: ${{ github.actor }}
reviewers: ${{ github.actor }}

Loading
Loading