Skip to content

Manual Sync Files on Merge #29

Manual Sync Files on Merge

Manual Sync Files on Merge #29

Workflow file for this run

name: Manual Sync Files on Merge
on:
pull_request:
branches:
- main
types: [closed]
workflow_dispatch:
env:
SOURCE_DIR: ./src/
TARGET_OWNER: larshinueber
TARGET_REPO: foo-space
TARGET_DIR: foo-space/docs/source/_src_getting_started/_src_examples/notebooks/
jobs:
sync:
# if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
env:
BRANCH_NAME: man-repo-sync-${{ github.event_name == 'pull_request' && github.event.pull_request.number || 'dispatch' }}
GH_TOKEN: ${{ secrets.GH_PAT }}
steps:
- name: Checkout source repository
uses: actions/checkout@v4
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: ${{ env.TARGET_OWNER }}/${{ env.TARGET_REPO }}
token: ${{ secrets.GH_PAT }}
ref: main
path: ./${{ env.TARGET_REPO }}
- name: Create new branch
run: |
cd ./${{ env.TARGET_REPO }}
# TODO: how can multiple open PRs be handled?
echo ${{ env.BRANCH_NAME }}
git checkout -b ${{ env.BRANCH_NAME }}
git pull --set-upstream origin ${{ env.BRANCH_NAME }}
ls -la
cd ..
# if: github.event_name == 'pull_request'
# BRANCH_NAME: "man-repo-sync-pr-${{ github.event.pull_request.number }}"
# if: github.event_name == 'workflow_dispatch'
# BRANCH_NAME: man-repo-sync-dispatch
- name: Delete old files
run: |
rm -rf ${{ env.TARGET_DIR }}
ls -la
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Copy new files
run: |
# cd ..
echo ${{ github.workspace }}
# TODO: generalized, sync all .ipynb files
python .github/scripts/copy_notebooks.py ${{ env.SOURCE_DIR }} ${{ env.TARGET_DIR }}
- name: Push changes
run: |
cd ./${{ env.TARGET_REPO }}
git config --global user.email github-actions
git config --global user.name [email protected]
git status
if [[ $(git diff --cached --numstat | wc -l) > 0 ]]; then
git add .
git commit -m "Auto-update foo-space examples"
git push --set-upstream origin ${{ env.BRANCH_NAME }};
fi
git status
- name: Create PR
if: github.event_name == 'pull_request'
run: |
gh pr create --title "Auto-update foo-space examples" --body "Please manually remove all non *.ipynp-files." --base main
- name:
if: github.event_name == 'workflow_dispatch'
run: |
git status
if [[ $(gh pr list -S head:man-repo-sync-dispatch --json title) == "[]" ]];
then gh pr create --title "Auto-update foo-space examples" --body "Please manually remove all non *.ipynp-files." --base main;
fi