Skip to content

2024-12-21 UBCStat Forecasts #26

2024-12-21 UBCStat Forecasts

2024-12-21 UBCStat Forecasts #26

name: Hub Submission Validation (R)
on:
workflow_dispatch:
pull_request:
branches: main
paths:
- 'model-output/**'
- 'model-metadata/*'
- '!**README**'
jobs:
validate_and_check:
runs-on: ubuntu-22.04 # R not supported for ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the entire Git history to ensure all commits are available
# Set up R environment
- uses: r-lib/actions/setup-r@v2
with:
install-r: false
use-public-rspm: true
extra-repositories: 'https://hubverse-org.r-universe.dev'
- name: Update R
run: |
sudo apt-get update
- uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::hubValidations
any::sessioninfo
# Check for changes outside allowed directories
- name: Get base and head commits
id: commits
run: |
echo "BASE_COMMIT=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
echo "HEAD_COMMIT=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
- name: Run git diff to find changed files
run: |
git diff --name-only ${{ env.BASE_COMMIT }} ${{ env.HEAD_COMMIT }} > changed_files.txt
echo "Changed files:"
cat changed_files.txt
- name: Check if changes are outside allowed directories
run: |
# Filter out files not in the allowed directories
UNALLOWED_CHANGES=$(grep -vE '^model-metadata/|^model-output/' changed_files.txt || true)
if [[ -n "$UNALLOWED_CHANGES" ]]; then
echo "Error: Changes outside allowed directories detected:"
echo "$UNALLOWED_CHANGES"
exit 1
else
echo "All changes are within allowed directories."
fi
# Run R-based validations
- name: Run validations
env:
PR_NUMBER: ${{ github.event.number }}
run: |
library("hubValidations")
v <- hubValidations::validate_pr(
gh_repo = Sys.getenv("GITHUB_REPOSITORY"),
pr_number = Sys.getenv("PR_NUMBER"),
skip_submit_window_check = FALSE
)
hubValidations::check_for_errors(v, verbose = TRUE)
shell: Rscript {0}