2024-10-23 ECDC models - SARIMA & SOCA simplex #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: HubSubmissionValidation(R) | |
on: | |
workflow_dispatch: | |
pull_request_target: | |
branches: main | |
paths: | |
- 'model-output/**' | |
- 'model-metadata/*' | |
- '!**README**' | |
- '!**.md' | |
- '!**.MD' | |
jobs: | |
validate-submission_job: | |
runs-on: ubuntu-latest | |
outputs: | |
changed_files: ${{ steps.get_changed_files.outputs.all_changed_files }} | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
# Get changes from pull request for later use | |
# -------------------------------------------- | |
- name: Get changes | |
id: get_changed_files | |
uses: tj-actions/changed-files@v41 | |
# DEBUG ONLY | |
- name: List all changed files | |
run: | | |
for file in ${{ steps.get_changed_files.outputs.all_changed_files }}; do | |
echo "$file was changed" | |
done | |
# Look for file outside allowed folders | |
# --------------------------------------- | |
- name: Check if file are outside the allowed folders | |
run: | | |
# List of allowed folders | |
ALLOWED_FOLDERS=("model-output/" "model-metadata/") | |
# Init var for not allowed files | |
FILES_OUTSIDE_FOLDERS="" | |
# Iterate over changes | |
for FILE in $(echo ${{ steps.changed-files.outputs.all_changed_files }} | jq -r '.[]'); do | |
MATCH_FOUND=false | |
# Check if file is under an allowed folder | |
for FOLDER in "${ALLOWED_FOLDERS[@]}"; do | |
if [[ "$FILE" == "$FOLDER"* ]]; then | |
MATCH_FOUND=true | |
break | |
fi | |
done | |
# If not mathced, add to forbidden list | |
if [ "$MATCH_FOUND" = false ]; then | |
FILES_OUTSIDE_FOLDERS="${FILES_OUTSIDE_FOLDERS} $FILE" | |
fi | |
done | |
# If one or more file outside allowed folders are present, submission fails | |
if [ ! -z "$FILES_OUTSIDE_FOLDERS" ]; then | |
echo "Error: PR contains files outside the allowed folders." | |
echo "Files outside allowed folders: $FILES_OUTSIDE_FOLDERS" | |
exit 1 | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
install-r: false | |
use-public-rspm: true | |
- name: Install system dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install libcurl4-openssl-dev libv8-dev | |
- uses: r-lib/actions/setup-r-dependencies@v2 | |
with: | |
packages: Infectious-Disease-Modeling-Hubs/hubValidations, any::sessioninfo | |
- 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 = TRUE | |
) | |
hubValidations::check_for_errors(v, verbose = TRUE) | |
shell: Rscript {0} | |
# Eventually comment on it | |
- name: Comment PR | |
uses: thollander/actions-comment-pull-request@v2 | |
with: | |
message: | | |
All validation checks completed successfully. | |
pr_number: ${{ github.event.pull_request.number }} | |
# Approve pull request | |
# --------------------------- | |
- name: Approve Pull Request | |
uses: juliangruber/[email protected] | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ github.event.pull_request.number }} | |
# And then merge it | |
# --------------------------- | |
- name: Merge the pull request | |
id: merge_pr | |
run: | | |
echo ">>> Merging PR URL: ${{ github.event.pull_request.html_url }}" | |
gh pr merge --auto --squash $PR_URL | |
env: | |
PR_URL: ${{ github.event.pull_request.html_url }} | |
GH_TOKEN: ${{ github.token }} | |
call-persisting-wf: | |
needs: validate-submission_job | |
uses: european-modelling-hubs/RespiCast-Covid19/.github/workflows/persist_changes.yml@main | |
with: | |
changes-list: ${{ needs.validate-submission_job.outputs.changed_files }} | |
secrets: | |
envPAT: ${{ secrets.GITHUB_TOKEN }} |