-
Notifications
You must be signed in to change notification settings - Fork 11
85 lines (72 loc) · 2.67 KB
/
update_and_convert_schemas.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Update Schemas
on:
pull_request:
types: [opened, synchronize, reopened]
branches: ["*"]
jobs:
process-changed-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
# 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: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
# To compare changes between the current commit and the last pushed remote commit set `since_last_remote_commit: true`. e.g
with:
since_last_remote_commit: false
- 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/ianca/hed-python.git@develop
- name: Update schemas
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
SOURCE_BRANCH="${{ github.head_ref }}"
TARGET_BRANCH="${{ github.base_ref }}"
echo "Source Branch: $SOURCE_BRANCH"
echo "Target Branch: $TARGET_BRANCH"
if [ "$SOURCE_BRANCH" = "develop" ] && [ "$TARGET_BRANCH" = "main" ]; then
echo "Error: Source branch 'develop' is not allowed for this operation."
exit 1
elif [ "$TARGET_BRANCH" = "main" ]; then
python tests/convert_and_update_schema.py $ALL_CHANGED_FILES --set-ids
else
python tests/convert_and_update_schema.py $ALL_CHANGED_FILES
fi
- name: Check for changes
id: check-changes
run: |
git status
git add .
git status
git diff
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 }}