Skip to content

Merge pull request #101 from djarecka/ga_fix #1

Merge pull request #101 from djarecka/ga_fix

Merge pull request #101 from djarecka/ga_fix #1

name: push pydantic models to brain-bican/bkbit
on:
push:
branches:
- main
paths:
- 'models_py-autogen/**'
workflow_run:
workflows: [generating other formats]
types:
- completed
jobs:
changed_files:
runs-on: ubuntu-latest
name: Test changed-files
steps:
- uses: actions/checkout@v4
- name: Set up Git and cloning repository
env:
TARGET_REPO: brain-bican/bkbit
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
git config --global user.name "puja-trivedi"
git config --global user.email "[email protected]"
git clone https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/$TARGET_REPO.git
- name: Get changed files in the models_py-autogen folder
id: changed-files-specific
uses: tj-actions/changed-files@v45
with:
files: models_py-autogen/**
- name: Run step if any file(s) in the models_py-autogen folder change
if: steps.changed-files-specific.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
echo "One or more files in the models_py-autogen folder has changed."
echo "List all the files that have changed: $ALL_CHANGED_FILES"
echo "$ALL_CHANGED_FILES" | tr ',' '\n' | while read -r FILE; do
FILENAME=$(basename "$FILE")
echo "Processing file: $FILENAME"
cp $FILE bkbit/bkbit/models/$FILENAME
done
cd bkbit
ls -l bkbit/models
# Generate a unique branch name
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BRANCH_NAME="update_models_${TIMESTAMP}"
echo "Generated branch name: $BRANCH_NAME"
git checkout -b $BRANCH_NAME
git branch
git add bkbit/models/*
git commit -m "The listed model(s) have been modified in the brain-bican/models repo: ${ALL_CHANGED_FILES}. New version of model(s) in pydantic format are being pushed from brain-bican/models to brain-bican/bkbit."
cd ..
# Set branch name as output
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_ENV
- name: Push changes to bkbit
env:
TARGET_REPO: brain-bican/bkbit
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
cd bkbit
git push origin ${{ env.branch_name }}
- name: Create pull request to bkbit
env:
TARGET_REPO: brain-bican/bkbit
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
curl -X POST -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
-d "{\"title\":\"Automated PR from brain-bican/models: adding new version of pydantic model(s)\", \"body\":\"This PR includes changes to the following models:\\n\\n${ALL_CHANGED_FILES}\", \"head\":\"${{ env.branch_name }}\", \"base\":\"main\"}" \
https://api.github.com/repos/$TARGET_REPO/pulls