This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync module repo -> push notebooks -> regenerate myst.yml toc -> push textbook repo | |
| on: | |
| repository_dispatch: | |
| types: [sync-module] | |
| workflow_dispatch: | |
| inputs: | |
| folder_name: | |
| description: Module folder in this repo (e.g. ecc-chemistry) | |
| required: true | |
| type: string | |
| source_repo: | |
| description: Source repo to sync from (owner/repo) | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync-push-notebooks-and-update-myst-toc: | |
| runs-on: ubuntu-latest | |
| env: | |
| SITE_REPO: ds-modules/ecc-textbook | |
| GH_PAT: ${{ secrets.ECC_TEXTBOOK_PAT }} | |
| MODULE_FOLDER: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.folder_name || github.event.client_payload.folder_name }} | |
| SOURCE_REPO: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_repo || github.event.client_payload.source_repo }} | |
| steps: | |
| # ----------------------------------------------------------------------- | |
| # 1. Pull THIS repo (so we can commit back into it) | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # ----------------------------------------------------------------------- | |
| # 2. Remove the old copy of this module & pull fresh | |
| - name: Purge and update module folder | |
| run: | | |
| MODULE="${{ env.MODULE_FOLDER }}" | |
| rm -rf "$MODULE" | |
| - uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ env.SOURCE_REPO }} | |
| path: tmp-source | |
| fetch-depth: 0 | |
| - name: Copy in new files (skip .git/.github) | |
| run: | | |
| rsync -a --delete --exclude .git --exclude .github tmp-source/ "${{ env.MODULE_FOLDER }}/" | |
| - name: Remove tmp-source checkout | |
| run: rm -rf tmp-source | |
| # ----------------------------------------------------------------------- | |
| # 3. Commit refreshed module back to notebooks repo | |
| - name: Commit back to notebooks repo | |
| run: | | |
| git config user.name "jedwin3210" | |
| git config user.email "jedwin321@berkeley.edu" | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git add . | |
| git commit -m "Auto-sync ${{ env.MODULE_FOLDER }} module" | |
| git push | |
| else | |
| echo "Nothing to commit." | |
| fi | |
| # ----------------------------------------------------------------------- | |
| # 4. Checkout textbook repo | |
| - name: Checkout textbook repo | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ env.SITE_REPO }} | |
| path: textbook | |
| token: ${{ env.GH_PAT }} | |
| fetch-depth: 0 | |
| # ----------------------------------------------------------------------- | |
| # 5. Mirror all ecc-* module folders into textbook repo | |
| - name: Sync ecc-* folders into textbook repo | |
| run: | | |
| set -euo pipefail | |
| while IFS= read -r module_dir; do | |
| module_name="$(basename "$module_dir")" | |
| echo "Syncing $module_name/" | |
| rsync -a --delete \ | |
| --exclude .git --exclude .github \ | |
| "$module_dir/" "textbook/$module_name/" | |
| done < <( | |
| find . -mindepth 1 -maxdepth 1 -type d -name 'ecc-*' -print | sort | |
| ) | |
| # ----------------------------------------------------------------------- | |
| # 6. Regenerate project.toc in myst.yml from notebook folders | |
| - name: Update myst.yml TOC | |
| run: | | |
| python .github/scripts/update_myst_toc.py \ | |
| --myst-yml textbook/myst.yml \ | |
| --scan-root . | |
| # ----------------------------------------------------------------------- | |
| # 7. Commit/push textbook repo updates | |
| - name: Commit to textbook repo | |
| run: | | |
| cd textbook | |
| git config user.name "jedwin3210" | |
| git config user.email "jedwin321@berkeley.edu" | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git add . | |
| git commit -m "Sync notebooks and regenerate myst.yml toc" | |
| git push | |
| else | |
| echo "Textbook repo already up to date." | |
| fi |