Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validate-config action and README #20

Merged
merged 9 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions validate-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# validate-config

Ensure Hub configuration files remain valid.

This hubverse action installs the `hubAdmin` package from GitHub using pak as well as required system dependencies.

It then performs submission validation checks through function `hubAdmin::validate_hub_config()` and assumes you have all three of the required configuration JSON files in your `hub-config/` directory:

- `admin.json`
- `model-metadata-schema.json`
- `tasks.json`

When invalid config files are discovered, a GitHub comment is created (or updated) with a table containing information about the exact locations of the failures using the [`hubAdmin::view_config_val_errors()`](https://hubverse-org.github.io/hubAdmin/reference/view_config_val_errors.html) function.

The action is triggered by pull requests onto the `main` branch which add or modify files in the `hub-config/` directory. For hubs and repositories which differ in configuration, workflow dispatch will need to be customised manually in the hubs workflow file.

zkamvar marked this conversation as resolved.
Show resolved Hide resolved
67 changes: 67 additions & 0 deletions validate-config/validate-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Hub Config Validation (R)

on:
workflow_dispatch:
pull_request:
branches: main
paths:
- 'hub-config/**'
- '!**README**'
zkamvar marked this conversation as resolved.
Show resolved Hide resolved

jobs:
validate-hub-config:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
install-r: false
use-public-rspm: true

- name: Update R
run: |
sudo apt-get update

- uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: hubverse-org/hubAdmin, any::sessioninfo

- name: Run validations
id: validate
env:
PR_NUMBER: ${{ github.event.number }}
run: |
workspace <- "${{ github.workspace }}"
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
output <- Sys.getenv("GITHUB_OUTPUT")
diff <- file.path(workspace, "diff.md")
v <- hubAdmin::validate_hub_config(
hub_path = workspace
)
# check if there were any failures
invalid <- any(vapply(v, isFALSE, logical(1)))
if (invalid) {
cat("result=false", "\n", file = output, sep = "", append = TRUE)
# write output to HTML
tbl <- hubAdmin::view_config_val_errors(v)
writeLines("## :x: Invalid Configuration\n", diff)
cat("\nErrors were detected in one or more config files in `hub-config/`. Details about the exact locations of the errors can be found in the table below.\n", file = diff, append = TRUE)
cat(gt::as_raw_html(tbl), "\n", file = diff, sep = "", append = TRUE)
} else {
cat("result=true", "\n", file = output, sep = "", append = TRUE)
}
shell: Rscript {0}
- name: "Comment on PR"
id: comment-diff
if: ${{ github.event_name != 'workflow_dispatch' && steps.validate.outputs.result == 'false' }}
uses: carpentries/actions/comment-diff@main
with:
pr: ${{ github.event.number }}
path: ${{ github.workspace }}/diff.md
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
- name: Error on Failure
if: ${{ steps.validate.outputs.result == 'false' }}
run: exit 1