diff --git a/.github/workflows/phs_document.yaml b/.github/workflows/phs_document.yaml new file mode 100644 index 0000000..c01f33b --- /dev/null +++ b/.github/workflows/phs_document.yaml @@ -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 }} diff --git a/.github/workflows/phs_package_checks.yaml b/.github/workflows/phs_package_checks.yaml index 5528062..d9ae83a 100644 --- a/.github/workflows/phs_package_checks.yaml +++ b/.github/workflows/phs_package_checks.yaml @@ -15,7 +15,7 @@ permissions: contents: read pull-requests: read statuses: read - + jobs: # Initial job to post status init: @@ -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 @@ -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 @@ -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: @@ -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, diff --git a/.github/workflows/phs_style.yaml b/.github/workflows/phs_style.yaml new file mode 100644 index 0000000..3c5d349 --- /dev/null +++ b/.github/workflows/phs_style.yaml @@ -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 }} + diff --git a/.github/workflows/phs_style_and_document.yaml b/.github/workflows/phs_style_and_document.yaml deleted file mode 100644 index 868680b..0000000 --- a/.github/workflows/phs_style_and_document.yaml +++ /dev/null @@ -1,139 +0,0 @@ -# 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_and_document.yaml - -permissions: - contents: read - pull-requests: read - -jobs: - phs_style_and_document: - name: "Automatically style and document the code" - 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@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 dependencies - uses: r-lib/actions/setup-r-dependencies@6f6e5bc62fba3a704f74e7ad7ef7676c5c6a2590 # v2.11.4 - with: - extra-packages: | - any::styler - any::roxygen2 - any::desc - needs: | - website - coverage - - - name: Enable styler cache - run: styler::cache_activate() - shell: Rscript {0} - - - name: Determine cache location - 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 - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 - with: - path: ${{ steps.styler-location.outputs.location }} - key: ${{ runner.os }}-styler-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-styler- - ${{ runner.os }}- - - - name: Style - run: styler::style_pkg() - shell: Rscript {0} - - - 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@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 - 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 }} - - - 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@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0 - with: - commit_message: "Document package (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_document.outputs.changes_detected == 'true' && steps.commit_step_document.outcome == 'failure' }} - uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 - with: - commit-message: "Document package (GHA)" - # Use a different branch name than the style PR - 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 }}