Skip to content

Commit

Permalink
Add option to have multiple unit test reports in the pkgdown document…
Browse files Browse the repository at this point in the history
…ation (#245)
  • Loading branch information
walkowif authored Jul 3, 2024
1 parent ad6cfa8 commit df038b2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/build-check-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ on:
required: false
type: boolean
default: false
unit-test-report-directory:
description: |
Directory name on gh-pages branch where the unit test report will be uploaded.
If the unit test report directory is different than the default 'unit-test-report',
it has to be added to the additional-unit-test-report-directories pkgdown workflow input.
Additionally, if the non-default unit test report should be shown in the GitHub Pages
documentation drop-down, it has to be added to _pkgdown.yaml.
required: false
type: string
default: "unit-test-report"

concurrency:
group: r-cmd-${{ inputs.concurrency-group }}-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -563,7 +573,7 @@ jobs:
&& github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: unit-test-report
name: unit-test-report-${{ inputs.concurrency-group }}
path: "index.html"

- name: Set output ⚙️
Expand Down Expand Up @@ -783,7 +793,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
path: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}/${{ env.PKGBUILD }}
name: ${{ env.PKGBUILD }}
name: ${{ env.PKGBUILD }}-${{ inputs.concurrency-group }}

- name: Upload logs artifact 🗞️
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -823,7 +833,7 @@ jobs:
- name: Download JUnit HTML report as artifact ⤵️
uses: actions/download-artifact@v4
with:
name: unit-test-report
name: unit-test-report-${{ inputs.concurrency-group }}
path: unit-test-report

- name: Upload JUnit HTML report to GitHub pages 🗞️
Expand All @@ -832,7 +842,7 @@ jobs:
with:
github_token: ${{ steps.github-token.outputs.token }}
publish_dir: ./unit-test-report
destination_dir: ${{ needs.build-install-check.outputs.current-branch-or-tag }}/unit-test-report
destination_dir: ${{ needs.build-install-check.outputs.current-branch-or-tag }}/${{ inputs.unit-test-report-directory }}

- name: Upload JUnit HTML report to GitHub pages (latest-tag) 🏷️
if: >
Expand All @@ -842,7 +852,7 @@ jobs:
with:
github_token: ${{ steps.github-token.outputs.token }}
publish_dir: ./unit-test-report
destination_dir: ${{ inputs.latest-tag-alt-name }}/unit-test-report
destination_dir: ${{ inputs.latest-tag-alt-name }}/${{ inputs.unit-test-report-directory }}

- name: Upload JUnit HTML report to GitHub pages (release-candidate) 🏷️
if: >
Expand All @@ -852,15 +862,15 @@ jobs:
with:
github_token: ${{ steps.github-token.outputs.token }}
publish_dir: ./unit-test-report
destination_dir: ${{ inputs.release-candidate-alt-name }}/unit-test-report
destination_dir: ${{ inputs.release-candidate-alt-name }}/${{ inputs.unit-test-report-directory }}

- name: Upload JUnit HTML report to GitHub pages (non-multiversion) 🗞️
if: needs.build-install-check.outputs.multiversion-docs == 'false'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ steps.github-token.outputs.token }}
publish_dir: ./unit-test-report
destination_dir: unit-test-report
destination_dir: ${{ inputs.unit-test-report-directory }}

upload-release-assets:
name: Upload build tar.gz
Expand All @@ -884,7 +894,7 @@ jobs:
- name: Download artifact ⏬
uses: actions/download-artifact@v4
with:
name: ${{ env.PKGBUILD }}
name: ${{ env.PKGBUILD }}-${{ inputs.concurrency-group }}

- name: Check if release exists
id: check-if-release-exists
Expand Down
47 changes: 44 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ on:
required: false
type: string
default: "."
additional-unit-test-report-directories:
description: |
If any *additional* unit test report directories are generated by the build-check-install workflow,
they should be listed as comma-separated directory list. If this input is empty, only coverage-report
and unit-test-report directories will be retained in the generated documentation directory.
Example:
unit-test-report-as-cran,unit-test-report-not-cran
required: false
type: string
default: ""

concurrency:
group: docs-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -254,14 +264,45 @@ jobs:
run: |
GH_PAGES_DIR="gh-pages/${{ steps.current-branch-or-tag.outputs.ref-name }}"
mkdir -p $GH_PAGES_DIR
echo "Current contents of $GH_PAGES_DIR:"
ls -l $GH_PAGES_DIR
# Remove contents except coverage-report and unit-test-report directories.
find $GH_PAGES_DIR -mindepth 1 -maxdepth 1 \
! -name coverage-report ! -name unit-test-report -exec rm -rf {} +
# Remove any existing documentation for the git tag, but retain coverage report and
# unit test reports which might have already been pushed to the gh-pages branch
# by the coverage and build-check-install workflows respectively.
directories_to_retain="coverage-report,unit-test-report"
if [[ "${{ inputs.additional-unit-test-report-directories }}" != "" ]]; then
directories_to_retain="${directories_to_retain},${{ inputs.additional-unit-test-report-directories }}"
fi
IFS=',' read -ra DIRECTORIES_TO_RETAIN <<< "$directories_to_retain"
echo "The following directories will be retained:"
for dir in "${DIRECTORIES_TO_RETAIN[@]}"; do
echo "$dir"
done
# Remove all files from GH_PAGES_DIR, except any DIRECTORIES_TO_RETAIN.
find $GH_PAGES_DIR -mindepth 1 -maxdepth 1 -print0 | while IFS= read -r -d '' file; do
file_to_be_removed="true"
# Check if the file/directory matches any directory to be retained.
for dir in "${DIRECTORIES_TO_RETAIN[@]}"; do
if [[ "$GH_PAGES_DIR/$dir" == "$file" ]]; then
echo "Not removing $file"
file_to_be_removed="false"
fi
done
if [[ "$file_to_be_removed" == "true" ]]; then
echo "Removing $file"
rm -rf "$file"
fi
done
echo "::group::gh-pages contents"
echo "Current contents of $GH_PAGES_DIR:"
ls -l $GH_PAGES_DIR
echo "::endgroup::"
# Copy generated pkgdown documentation to gh-pages branch.
cp -a ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}/docs/. $GH_PAGES_DIR
echo "::group::gh-pages contents"
echo "Current contents of $GH_PAGES_DIR:"
ls -l $GH_PAGES_DIR
echo "::endgroup::"
cd gh-pages
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
Expand Down

0 comments on commit df038b2

Please sign in to comment.