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
4 changes: 0 additions & 4 deletions .github/workflows/phs_document.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ jobs:
container:
image: ghcr.io/public-health-scotland/phs-r-image

permissions:
contents: write
pull-requests: write

env:
GITHUB_PAT: ${{ secrets.PHS_ACTIONS_TOKEN || github.token }}

Expand Down
30 changes: 22 additions & 8 deletions .github/workflows/phs_package_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,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 @@ -59,7 +69,7 @@ jobs:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Build_README:
needs: [Style_and_document]
needs: [Style]
uses: ./.github/workflows/phs_build_readme.yaml
permissions:
contents: write
Expand All @@ -70,7 +80,7 @@ jobs:
group: ${{ github.workflow }}-build-readme-${{ 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 @@ -80,7 +90,7 @@ jobs:
group: ${{ inputs.limit_parallel == false && format('r-cmd-check-{0}-{1}', github.workflow, github.run_id) || 'phs-core-check-queue' }}
cancel-in-progress: false
R-CMD-check-extended:
needs: [Style_and_document]
needs: [Style, Document]
if: ${{ !github.event.pull_request.draft }}
uses: ./.github/workflows/phs_R-CMD-check-extended.yaml
permissions:
Expand All @@ -102,7 +112,8 @@ jobs:
cancel-in-progress: false
pkgdown:
needs:
- Style_and_document
- Style
- Document
- Build_README
- R-CMD-check-core
- R-CMD-check-extended
Expand All @@ -113,10 +124,12 @@ jobs:
contents: write
packages: read
secrets: inherit

# Final job to update status
finalize:
needs:
- Style_and_document
- Style
- Document
- Build_README
- R-CMD-check-core
- R-CMD-check-extended
Expand All @@ -136,7 +149,8 @@ jobs:
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const allSuccess = ${{ needs.Style_and_document.result == 'success' &&
const allSuccess = ${{ needs.Style.result == 'success' &&
needs.Document.result == 'success' &&
needs.Build_README.result == 'success' &&
needs.R-CMD-check-core.result == 'success' &&
(needs.R-CMD-check-extended.result == 'success' || needs.R-CMD-check-extended.result == 'skipped') &&
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phs_pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name: pkgdown.yaml

permissions:
contents: read
packages: read

jobs:
pkgdown:
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/phs_style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 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@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}

- 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

echo "Diffing $BASE_SHA..$HEAD_SHA"

# 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"
printf "%s\n" "$CHANGED_RMD"
else
echo "rmd_changed=false" >> "$GITHUB_OUTPUT"
echo "No .Rmd changes detected."
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', '**/*.R') }}
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@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
with:
commit_message: "Style code (GHA)"
commit_user_name: ${{ github.actor }}
commit_user_email: ${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com
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@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
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 }}

137 changes: 0 additions & 137 deletions .github/workflows/phs_style_and_document.yaml

This file was deleted.