Skip to content

Commit 942d9eb

Browse files
committed
renamed push_pydantic_to_bkbit to push_model_to_bkbit, since we are now pushign both pydantic and jsonld-context
1 parent c5a85ee commit 942d9eb

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: push pydantic models and jsonld-context files to brain-bican/bkbit
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
model:
7+
description: 'model name'
8+
required: true
9+
type: string
10+
11+
12+
jobs:
13+
changed_files:
14+
runs-on: ubuntu-latest
15+
name: Test changed-files
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Git and cloning repository
19+
env:
20+
TARGET_REPO: brain-bican/bkbit
21+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
22+
run: |
23+
git config --global user.name "puja-trivedi"
24+
git config --global user.email "[email protected]"
25+
git clone https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/$TARGET_REPO.git
26+
27+
- name: Check if the model exists
28+
run: |
29+
if [ ! -f models_py-autogen/${{ inputs.model }}.py ]; then
30+
echo "Incorrect model name"
31+
exit 1
32+
fi
33+
34+
- name: Check if the jsonld-context file exists
35+
run: |
36+
if [ ! -f jsonld-context-autogen/${{ inputs.model }}.context.jsonld ]; then
37+
echo "jsonld-context file does not exist"
38+
exit 1
39+
fi
40+
- name: Compare pydantic files
41+
id: compare_pydantic
42+
run: |
43+
if [ ! -f bkbit/bkbit/models/${{ inputs.model }}.py ]; then
44+
echo "This is new model for bkbit"
45+
echo "changed=new" >> "$GITHUB_OUTPUT"
46+
elif diff models_py-autogen/${{ inputs.model }}.py bkbit/bkbit/models/${{ inputs.model }}.py > /dev/null; then
47+
echo "No changes in the pydantic model"
48+
echo "changed=false" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "Changes found in the pydantic model"
51+
echo "changed=true" >> "$GITHUB_OUTPUT"
52+
fi
53+
54+
- name: Compare jsonld-context files
55+
id: compare_jsonld
56+
run: |
57+
if [ ! -f bkbit/bkbit/models/${{ inputs.model }}.context.jsonld ]; then
58+
echo "This is new jsonld-context file for bkbit"
59+
echo "changed=new" >> "$GITHUB_OUTPUT"
60+
elif diff jsonld-context-autogen/${{ inputs.model }}.context.jsonld bkbit/bkbit/models/${{ inputs.model }}.context.jsonld > /dev/null; then
61+
echo "No changes in the jsonld-context file"
62+
echo "changed=false" >> "$GITHUB_OUTPUT"
63+
else
64+
echo "Changes found in the jsonld-context file"
65+
echo "changed=true" >> "$GITHUB_OUTPUT"
66+
fi
67+
68+
- name: Copy the pydantic model and jsonld-context file to bkbit and commit the changes
69+
if: ${{ steps.compare_pydantic.outputs.changed == 'true' || steps.compare_pydantic.outputs.changed == 'new' || steps.compare_jsonld.outputs.changed == 'true' || steps.compare_jsonld.outputs.changed == 'new' }}
70+
run: |
71+
echo "Copying the pydantic model ${{ inputs.model }} to bkbit"
72+
cp models_py-autogen/${{ inputs.model }}.py bkbit/bkbit/models/
73+
74+
echo "Copying the jsonld-context file ${{ inputs.model }}.context.jsonld to bkbit"
75+
cp jsonld-context-autogen/${{ inputs.model }}.context.jsonld bkbit/bkbit/models/
76+
77+
# Generate a unique branch name
78+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
79+
BRANCH_NAME="update_${{ inputs.model }}_${TIMESTAMP}"
80+
echo "Generated branch name: $BRANCH_NAME"
81+
# Set branch name as output
82+
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_ENV
83+
84+
cd bkbit
85+
git checkout -b $BRANCH_NAME
86+
git branch
87+
git add bkbit/models/*
88+
# Prepare commit message based on what changed
89+
if [ "${{ steps.compare_pydantic.outputs.changed }}" == "new" ] && [ "${{ steps.compare_jsonld.outputs.changed }}" == "new" ]; then
90+
git commit -m "The model ${{ inputs.model }} has been added to the brain-bican/models repo. The model in pydantic format and jsonld-context file are being automatically pushed from brain-bican/models to brain-bican/bkbit."
91+
elif [ "${{ steps.compare_pydantic.outputs.changed }}" == "new" ]; then
92+
git commit -m "The model ${{ inputs.model }} has been added to the brain-bican/models repo. The model in pydantic format is being automatically pushed from brain-bican/models to brain-bican/bkbit."
93+
elif [ "${{ steps.compare_jsonld.outputs.changed }}" == "new" ]; then
94+
git commit -m "The jsonld-context file for model ${{ inputs.model }} has been added to the brain-bican/models repo. The jsonld-context file is being automatically pushed from brain-bican/models to brain-bican/bkbit."
95+
else
96+
git commit -m "The model ${{ inputs.model }} has been modified in the brain-bican/models repo. Updated files are being automatically pushed from brain-bican/models to brain-bican/bkbit."
97+
fi
98+
cd ..
99+
100+
- name: Push changes to bkbit
101+
if: ${{ steps.compare_pydantic.outputs.changed == 'true' || steps.compare_pydantic.outputs.changed == 'new' || steps.compare_jsonld.outputs.changed == 'true' || steps.compare_jsonld.outputs.changed == 'new' }}
102+
env:
103+
TARGET_REPO: brain-bican/bkbit
104+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
105+
run: |
106+
cd bkbit
107+
git push origin ${{ env.branch_name }}
108+
109+
- name: Create pull request to bkbit
110+
if: ${{ steps.compare_pydantic.outputs.changed == 'true' || steps.compare_pydantic.outputs.changed == 'new' || steps.compare_jsonld.outputs.changed == 'true' || steps.compare_jsonld.outputs.changed == 'new' }}
111+
env:
112+
TARGET_REPO: brain-bican/bkbit
113+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
114+
run: |
115+
# Prepare PR title and body based on what changed
116+
PR_TITLE="Automated PR from brain-bican/models: updates for model ${{ inputs.model }}"
117+
PR_BODY="This PR includes changes to the model ${{ inputs.model }}:"
118+
119+
if [ "${{ steps.compare_pydantic.outputs.changed }}" == "new" ]; then
120+
PR_BODY="$PR_BODY\n- Added new pydantic model"
121+
elif [ "${{ steps.compare_pydantic.outputs.changed }}" == "true" ]; then
122+
PR_BODY="$PR_BODY\n- Updated pydantic model"
123+
fi
124+
125+
if [ "${{ steps.compare_jsonld.outputs.changed }}" == "new" ]; then
126+
PR_BODY="$PR_BODY\n- Added new jsonld-context file"
127+
elif [ "${{ steps.compare_jsonld.outputs.changed }}" == "true" ]; then
128+
PR_BODY="$PR_BODY\n- Updated jsonld-context file"
129+
fi
130+
131+
curl -X POST -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
132+
-d "{\"title\":\"$PR_TITLE\", \"body\":\"$PR_BODY\", \"head\":\"${{ env.branch_name }}\", \"base\":\"main\"}" \
133+
https://api.github.com/repos/$TARGET_REPO/pulls

0 commit comments

Comments
 (0)