Skip to content

Update 4C metadata and schema file #378

Update 4C metadata and schema file

Update 4C metadata and schema file #378

name: Update 4C metadata and schema file
on:
schedule:
- cron: "0 5 * * *" # run each night at 5AM. Current nightly 4C test should be completed by then
jobs:
update-4C-metadata-schema-file:
name: Update 4C metadata and schema file
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.PAT_4C_BOT_MERGE_TO_MAIN }}
- name: Pull latest metadata file from 4C
uses: dawidd6/action-download-artifact@v20
with:
repo: 4C-multiphysics/4C
github_token: ${{ secrets.ORGANIZATION_TOKEN }}
workflow: nightly_tests.yml
workflow_conclusion: completed
name: clang18_build-metadata
path: clang18_build-metadata
- name: Pull latest schema file from 4C
uses: dawidd6/action-download-artifact@v20
with:
repo: 4C-multiphysics/4C
github_token: ${{ secrets.ORGANIZATION_TOKEN }}
workflow: nightly_tests.yml
workflow_conclusion: completed
name: clang18_build-schema
path: clang18_build-schema
# Format new files with pre-commit (this needs to be done before the files are hashed to ensure that both are formatted)
- name: Set up virtual environment
uses: ./.github/actions/setup-env
with:
python-version: 3.13
- name: Install requirements
shell: bash -el {0}
run: |
conda activate fourcipp
pip install -e .[dev,safe]
pip install pre-commit
# files need to be specified because they are not yet staged and therefore pre-commit cannot find them
# pre-commit hook is run twice to not fail if the first run fails (due to formatting files)
- name: Run pre-commit, i.e., format files
shell: bash -el {0}
run: |
conda activate fourcipp
SKIP=no-commit-to-branch pre-commit run --files clang18_build-metadata/4C_metadata.yaml clang18_build-schema/4C_schema.json || SKIP=no-commit-to-branch pre-commit run --files clang18_build-metadata/4C_metadata.yaml clang18_build-schema/4C_schema.json
# Compare the hashes
- name: Check if metadata file has changed and overwrite old file if necessary
run: |
set -euo pipefail
hash_current=$(grep -v 'commit_hash' src/fourcipp/config/4C_metadata.yaml | sha256sum | awk '{print $1}')
hash_new=$(grep -v 'commit_hash' clang18_build-metadata/4C_metadata.yaml | sha256sum | awk '{print $1}')
echo "Current metadata file hash: $hash_current"
echo "New metadata file hash: $hash_new"
if [ "$hash_current" != "$hash_new" ]; then
mv clang18_build-metadata/4C_metadata.yaml src/fourcipp/config/4C_metadata.yaml
mv clang18_build-schema/4C_schema.json src/fourcipp/config/4C_schema.json
rm -r clang18_build-metadata
rm -r clang18_build-schema
echo "metadata_file_changed=true" >> $GITHUB_ENV
else
echo "metadata_file_changed=false" >> $GITHUB_ENV
fi
# Commit and push changes
- name: Get 4C hash for commit message
if: env.metadata_file_changed == 'true'
run: echo "fourc_commit_hash=$(awk '/commit_hash:/ {print $2}' src/fourcipp/config/4C_metadata.yaml)" >> $GITHUB_ENV
- name: Commit and push changes
if: env.metadata_file_changed == 'true'
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "Nightly update of 4C metadata and schema file (4C commit hash: ${{ env.fourc_commit_hash }})"
branch: main
push_options: --force
commit_options: "--no-verify"
commit_user_name: 4C-Bot
commit_user_email: 207683181+4C-Bot@users.noreply.github.com
commit_author: 4C-Bot <207683181+4C-Bot@users.noreply.github.com>