Fix input variable reference in workflow #270
This file contains hidden or 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: Autopopulation | ||
| # Run the job if a PR was merged or a push occurred on main | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| sync-instances: | ||
| if: github.repository == 'openMetadataInitiative/openMINDS_instances' && ${{ !contains(github.event.head_commit.message, '[ci skip-autopopulate]') }} | ||
|
Check warning on line 14 in .github/workflows/autopopulation.yml
|
||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 # Fetch full history for accurate diff comparisons | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: '3.13' | ||
| - name: Process and Sync Changes in instance Files | ||
| id: process_sync_instances | ||
| run: | | ||
| # Identify modified or added .jsonld files | ||
| # Store them in changed_files.txt (fallback to true to prevent pipeline failure) | ||
| git checkout HEAD | ||
| git diff --name-only --diff-filter=AM HEAD^ HEAD | grep '\.jsonld$' > changed_files.txt || true | ||
| declare -A modified_jsons | ||
| declare -A file_versions | ||
| declare -A skip_files | ||
| # Process the list of changed .jsonld files | ||
| if [ -s changed_files.txt ]; then | ||
| while IFS= read -r file; do | ||
| FILE_MODULE=$(dirname "$file" | cut -d'/' -f3-) | ||
| FILE_NAME=$(basename "$file") | ||
| MODULE_NAME="$FILE_MODULE/$FILE_NAME" | ||
| FILE_VERSION=$(echo "$file" | cut -d'/' -f2) | ||
| # If the file appears in multiple versions on push, mark it for skipping | ||
| if [[ -n "${file_versions[$MODULE_NAME]}" ]]; then | ||
| skip_files[$MODULE_NAME]=1 | ||
| echo "Skipping all versions of $MODULE_NAME due to multiple versions detected." | ||
| # Store eligible .jsonld files for instance generation | ||
| else | ||
| file_versions[$MODULE_NAME]="$FILE_VERSION" | ||
| modified_jsons["$file"]="$FILE_VERSION" | ||
| fi | ||
| done < changed_files.txt | ||
| fi | ||
| # Process eligible .jsonld files for instance generation | ||
| if [ ${#modified_jsons[@]} -gt 0 ]; then | ||
| MAIN_FOLDER="instances" | ||
| # Fetch reference files required for instance generation | ||
| wget https://raw.githubusercontent.com/openMetadataInitiative/openMINDS/refs/heads/main/vocab/types.json -P .github/ | ||
| wget https://raw.githubusercontent.com/openMetadataInitiative/openMINDS/refs/heads/main/vocab/properties.json -P .github/ | ||
| wget https://raw.githubusercontent.com/openMetadataInitiative/openMINDS/refs/heads/pipeline/versions.json -P .github/ | ||
| # Loop through each modified .jsonld file | ||
| for FILE in "${!modified_jsons[@]}"; do | ||
| FILE_MODULE=$(dirname "$FILE" | cut -d'/' -f3-) | ||
| FILE_NAME=$(basename "$FILE") | ||
| MODULE_NAME="$FILE_MODULE/$FILE_NAME" | ||
| # Skip generation if marked for skipping | ||
| if [[ -n "${skip_files[$MODULE_NAME]}" ]]; then | ||
| echo "Skipping generation for $MODULE_NAME due to multiple versions in a merged PR/push." | ||
| continue | ||
| fi | ||
| # Retrieve version where the .jsonld file is located | ||
| FILE_VERSION="${modified_jsons[$FILE]}" | ||
| # Iterate over existing versions in the instances directory | ||
| for VERSION in $(ls "$MAIN_FOLDER"); do | ||
| if [ "$VERSION" != "$FILE_VERSION" ]; then | ||
| TARGET_FILE="$MAIN_FOLDER/$VERSION/$FILE_MODULE/$FILE_NAME" | ||
| TOP_LEVEL_DIR=$(echo "$FILE_MODULE" | cut -d'/' -f1) | ||
| # Target file does not exist in instances/VERSION/terminologies/terminology | ||
| if [[ "$FILE_MODULE" == "terminologies/terminology" ]] && [[ ! -e "$TARGET_FILE" ]]; then | ||
| echo "Skipping $TARGET_FILE: terminology file does not exist in $VERSION." | ||
| # Folder does not exist in instances/VERSION/terminologies/ | ||
| elif [[ "$FILE_MODULE" == terminologies/* ]] && [[ ! -d "$MAIN_FOLDER/$VERSION/$FILE_MODULE/" ]]; then | ||
| echo "Skipping $FILE_MODULE: folder does not exist in $VERSION." | ||
| # Top-level folder exists in instances/VERSION/ | ||
| elif [ -d "$MAIN_FOLDER/$VERSION/$TOP_LEVEL_DIR/" ]; then | ||
| mkdir -p "$MAIN_FOLDER/$VERSION/$FILE_MODULE/" | ||
| echo "Generating instance from $FILE to $TARGET_FILE." | ||
| python .github/scripts/sync_instances.py "$FILE" "$TARGET_FILE" "$VERSION" | ||
| # Top-level folder not in instances/VERSION/ | ||
| else | ||
| echo "Skipping $FILE_MODULE: top-level folder does not exist in $VERSION." | ||
| fi | ||
| fi | ||
| done | ||
| done | ||
| # Commit changes if any instances were modified | ||
| git config --global user.name "openMINDS pipeline" | ||
| git config --global user.email "support@openmetadatainitiative.org" | ||
| git add $MAIN_FOLDER/**/*.jsonld | ||
| git commit -m "Autopopulation of instance file." | ||
| git pull --rebase origin main | ||
| git push origin HEAD:main | ||
| else | ||
| echo "No JSON-LD files modified." | ||
| fi | ||
| shell: bash | ||