From c77ef5903f62eebdd37dcc98f313e3892ebd3c36 Mon Sep 17 00:00:00 2001 From: IanCa Date: Fri, 24 May 2024 13:56:28 -0500 Subject: [PATCH] Script for adding hedIds --- .github/workflows/add_hed_ids.yaml | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/add_hed_ids.yaml diff --git a/.github/workflows/add_hed_ids.yaml b/.github/workflows/add_hed_ids.yaml new file mode 100644 index 00000000..708722cb --- /dev/null +++ b/.github/workflows/add_hed_ids.yaml @@ -0,0 +1,81 @@ +name: Add hedIds + +on: + pull_request: + branches: ["main"] + +jobs: + process-changed-files: + runs-on: ubuntu-latest + + steps: + - name: Check if original repository + run: | + if [ "${{ github.head_ref }}" != "provisional" ]; then + echo "This workflow only runs from the 'provisional' branch." + exit 1 # Exit with failure to halt the workflow + fi +# if [ "${{ github.repository }}" != "hed-standard/hed-schemas" ]; then +# echo "This workflow is not running on the original repository. Exiting..." +# exit 1 # Exit with failure to halt the workflow +# fi + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. + ref: ${{github.event.pull_request.head.sha}} + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v44 + with: + since_last_remote_commit: false + + # This part might need revision. This avoids the extra merge commit. + - name: Fetch updates from the target branch + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'actions@github.com' + git fetch origin ${{ github.event.pull_request.base.ref }} + git rebase origin/${{ github.event.pull_request.base.ref }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: List all changed files + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + for file in "$ALL_CHANGED_FILES"; do + echo "$file was changed" + done + + - name: Install dependencies + run: pip install git+https://github.com/hed-standard/hed-python.git@develop + + - name: Update schemas + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + hed_update_schemas $ALL_CHANGED_FILES --set-ids + + - name: Check for changes + id: check-changes + run: | + if ! git diff --quiet || ! git diff --cached --quiet || git ls-files --others --exclude-standard | grep -q .; then + echo "changes_exist=true" >> $GITHUB_ENV + else + echo "changes_exist=false" >> $GITHUB_ENV + fi + + - name: Commit and push changes + if: env.changes_exist == 'true' + run: | + git add . + git commit -m "Automatic file updates" + git push origin HEAD:refs/heads/${{ github.head_ref }} + + +