Skip to content

Commit

Permalink
Rewrite core.R to Python (#26)
Browse files Browse the repository at this point in the history
This change is not backwards-compatible - it will require the release of
new major version of the action.
The following inputs are not supported anymore:
* `insert-after-section`
* `version-tab`

Additionally, the format of the `refs-order` input has changed.

---------

Co-authored-by: cicdguy <26552821+cicdguy@users.noreply.github.com>
Co-authored-by: cicdguy <cicdguy@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent abaaa32 commit f2d7715
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 455 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cla.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: CLA 🔏

on:
Expand Down
37 changes: 31 additions & 6 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,46 @@ on:

jobs:
lint:
permissions:
# To write linting fixes
contents: write
# To write Super-linter status checks
statuses: write
name: Lint Code Base
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Lint Code Base
uses: github/super-linter/slim@v4
uses: super-linter/super-linter/slim@v7.1.0
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: main
VALIDATE_R: true
VALIDATE_YAML: true
VALIDATE_BASH_EXEC: true
VALIDATE_DOCKERFILE_HADOLINT: true
FIX_PYTHON_BLACK: true
FIX_PYTHON_RUFF: true
FIX_PYTHON_ISORT: true
FIX_PYTHON_PYINK: true
FIX_YAML_PRETTIER: true
FIX_MARKDOWN: true
FIX_MARKDOWN_PRETTIER: true
VALIDATE_CHECKOV: false
VALIDATE_PYTHON_PYLINT: false
VALIDATE_PYTHON_FLAKE8: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Commit & Push Linting Fixes
# Run only on:
# - Pull requests
# - Not on the default branch
if: >
github.event_name == 'pull_request' &&
github.ref_name != github.event.repository.default_branch
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
commit_message: "chore: fix linting issues"
commit_user_name: super-linter
commit_user_email: super-linter@super-linter.dev
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
super-linter-output/
6 changes: 0 additions & 6 deletions .lintr

This file was deleted.

108 changes: 48 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,94 @@
# MultiVersion pkgdown docs action
<!-- BEGIN_ACTION_DOC -->

Github Action to generate multiple versions of [`pkgdown`](https://pkgdown.r-lib.org/) docs for R packages.
# R pkgdown Multi Version docs

This Github Actions works under the following assumptions:
GitHub Action to generate multiple versions of [`pkgdown`](https://pkgdown.r-lib.org/) docs for R packages.

* R package documentation is generated by the R function [`pkgdown::build_site`](https://pkgdown.r-lib.org/reference/build_site.html)
* Documentation is published to the `gh-pages` branch of the package repository and Github Pages is enabled at the root level of the branch
* The version of `pkgdown` used to generate the documentation is `>= v2.0.0`
* The `pkgdown` documentation uses Bootstrap 5
* The `URL` field in the package DESCRIPTION file contains a reference to the pkgdown site URL (see step 1 [here](https://pkgdown.r-lib.org/articles/pkgdown.html#promoting))
This GitHub Actions works under the following assumptions:

- R package documentation is generated by the R function [`pkgdown::build_site`](https://pkgdown.r-lib.org/reference/build_site.html)
- Documentation is published to the `gh-pages` branch of the package repository and GitHub Pages is enabled at the root level of the branch
- The version of `pkgdown` used to generate the documentation is `>= v2.0.0`
- The `pkgdown` documentation uses Bootstrap 5
- The `URL` field in the package DESCRIPTION file contains a reference to the pkgdown site URL (see step 1 [here](https://pkgdown.r-lib.org/articles/pkgdown.html#promoting))

An example of the output of the action can be seen below:

![Screenshot with example output](example.png)

## Action type
## Description

Composite
Generates multisite R documentation created with pkgdown.

## Inputs
## Action Type

* `path`:
Composite

_Description_: Path to package's root
## Author

_Required_: `false`
Insights Engineering

_Default_: `.`
## Inputs

* `default-landing-page`:
- `path`:

_Description_: The default branch or tag on gh-pages that corresponds to the landing page. For instance, if your root index page on gh-pages is built using the 'main' branch, then the root page of the website will correspond to this page. If 'latest-tag' is selected, then the latest version will become the default.
_Description_: Path to package's root

_Required_: `false`
_Required_: `false`

_Default_: `main`
_Default_: `.`

* `branches-or-tags-to-list`:
- `default-landing-page`:

_Description_: Which branches or tags should be listed under the 'Versions' dropdown menu on the landing page? This input should be a regular expression in R.
_Description_: The default branch or tag on gh-pages that corresponds to the landing page.
For instance, if your root index page on gh-pages is built using the 'main'
branch, then the root page of the site will correspond to this page.
If 'latest-tag' is selected, then the latest version will become the default.

_Required_: `false`
_Required_: `false`

_Default_: `^main$|^devel$|^pre-release$|^latest-tag$|^develop$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)$`
_Default_: `main`

* `insert-after-section`:
- `branches-or-tags-to-list`:

_Description_: After which section in the navbar should the 'Versions' dropdown be added? Choose between 'Reference' and 'Changelog' for the surest of choices.
_Description_: Which branches or tags should be listed under the 'Versions' dropdown menu on the landing page? This input should be a regular expression in R.

_Required_: `false`

_Default_: `Changelog`

* `version-tab`:
_Default_: `^main$|^devel$|^prerelease$|^latest-tag$|^release-candidate$|^develop$|^v([0-9]+\.)?([0-9]+\.)?([0-9]+)|^v([0-9]+\.)?([0-9]+\.)?([0-9]+)(-rc[0-9]+)$`

_Description_: Configuration of how the drop-down list should appear for multiple versions. It should be set as an ASCII text representation of an R list object. Example:
- `refs-order`:

```R
list(config = list(
tooltip = list(
main = "Tooltip for main branch"
),
text = list(
main = "main branch"
)
))
```

String should be quoted with " sign
_Description_: The order in which refs should appear in the drop-down list. Versions not in the vector
will appear below refs listed here.
If docs have never been generated for the ref, the ref will not appear in the
drop-down. Similarly, if docs have been generated for the ref, but the ref is not
listed in the vector, it will not appear in the drop-down.
Example (the refs on the list should be separated by space):
main devel prerelease latest-tag

_Required_: `false`

_Default_: ``
* `refs-order`:
_Description_: The order in which refs should appear in the drop-down list. Versions not in the vector
will appear below refs listed here.
_Default_: `main devel prerelease latest-tag`

If docs have never been generated for the ref, the ref will not appear in the
drop-down. Similarly, if docs have been generated for the ref, but the ref is not
listed in the vector, it will not appear in the drop-down.
- `latest-tag-alt-name`:

Example:
`c("main", "devel", "pre-release", "latest-tag")`
_Description_: An alternate name for the 'latest-tag' item

_Required_: `false`

_Default_: `c("main", "devel", "pre-release", "latest-tag")`
_Default_: `""`

* `latest-tag-alt-name`:
- `release-candidate-alt-name`:

_Description_: An alternate name for the 'latest-tag' item
_Description_: An alternate name for the 'release-candidate' item

_Required_: `false`

_Default_: `''`
_Default_: `""`

## Outputs

None.
## Usage
None

Please refer to [this example](https://github.com/insightsengineering/r.pkg.template/blob/main/.github/workflows/pkgdown.yaml) workflow to see how this action is used in an end-to-end documentation publishing workflow.
<!-- END_ACTION_DOC -->
65 changes: 17 additions & 48 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: R pkgdown Multi Version docs
author: Insights Engineering
description: Generates multisite R documentation created with pkgdown.
branding:
icon: 'anchor'
color: 'orange'
icon: "anchor"
color: "orange"
inputs:
path:
description: Path to package's root
Expand All @@ -13,65 +13,39 @@ inputs:
description: |
The default branch or tag on gh-pages that corresponds to the landing page.
For instance, if your root index page on gh-pages is built using the 'main'
branch, then the root page of the website will correspond to this page.
branch, then the root page of the site will correspond to this page.
If 'latest-tag' is selected, then the latest version will become the default.
default: main
required: false
branches-or-tags-to-list:
description:
Which branches or tags should be listed under the
description: Which branches or tags should be listed under the
'Versions' dropdown menu on the landing page?
This input should be a regular expression in R.
required: false
default: >-
^main$|^devel$|^pre-release$|^latest-tag$|^release-candidate$|^develop$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)(-rc[0-9]+)$
insert-after-section:
description:
After which section in the navbar should the 'Versions'
dropdown be added? Choose between 'Reference' and 'Changelog'
for the surest of choices.
required: false
default: Changelog
version-tab:
description: |
Configuration how should the dropdownlist appear for multiple versions.
It should be set as an ASCII text representation of an R list object
Example:
"""
list(config = list(
tooltip = list(
main = "Tooltip for main branch"
),
text = list(
main = "main branch"
)
))
"""
String should be quoted with " sign
required: false
default: ""
^main$|^devel$|^prerelease$|^latest-tag$|^release-candidate$|^develop$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)(-rc[0-9]+)$
refs-order:
description: |
The order in which refs should appear in the drop-down list. Versions not in the vector
will appear below refs listed here.
If docs have never been generated for the ref, the ref will not appear in the
drop-down. Similarly, if docs have been generated for the ref, but the ref is not
listed in the vector, it will not appear in the drop-down.
Example:
c("main", "devel", "pre-release", "latest-tag")
Example (the refs on the list should be separated by space):
main devel prerelease latest-tag
required: false
default: c("main", "devel", "pre-release", "latest-tag")
default: "main devel prerelease latest-tag"
latest-tag-alt-name:
description: An alternate name for the 'latest-tag' item
required: false
default: ''
default: ""
release-candidate-alt-name:
description: An alternate name for the 'release-candidate' item
required: false
default: ''
default: ""

runs:
using: 'composite'
using: "composite"
steps:
- name: Create copy of latest tag
run: |
Expand Down Expand Up @@ -150,17 +124,12 @@ runs:

- name: Run multi-version site creation script
run: |
source(file.path(
Sys.getenv("GITHUB_ACTION_PATH"), "core.R")
)
setwd("${{ inputs.path }}")
update_content(
refs_to_list = "${{ inputs.branches-or-tags-to-list }}",
refs_order = ${{ inputs.refs-order }},
insert_after_section = "${{ inputs.insert-after-section }}",
version_tab = '${{ inputs.version-tab }}'
)
shell: Rscript {0}
pip install lxml packaging
python ${GITHUB_ACTION_PATH}/core.py ${{ github.event.repository.name }}/ \
--pattern '${{ inputs.branches-or-tags-to-list }}' \
--refs_order ${{ inputs.refs-order }} \
--base_url https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/
shell: bash

- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
Loading

0 comments on commit f2d7715

Please sign in to comment.