automatic subtree merge #26
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 MDDB database | |
| on: | |
| # Run this workflow every time there is a push with changes under the stated directory | |
| push: | |
| paths: | |
| - 'src/mddb-database/**' | |
| branches: [ master ] | |
| # Allow also to manually run the workflow from github for debugging purposes | |
| workflow_dispatch: | |
| inputs: | |
| debug: | |
| type: boolean | |
| description: 'Open an interactive sesion' | |
| default: false | |
| required: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync-to-common-repo: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.MDDB_REPOS }} | |
| - name: Configure Git | |
| run: | | |
| git config user.name "CI Bot" | |
| git config user.email "ci@example.com" | |
| - name: Extract changes in MDDB database code | |
| id: split | |
| run: | | |
| # Make sure we are in the right commit | |
| echo "Current commit: $(git rev-parse HEAD)" | |
| echo "Current branch: $(git branch --show-current)" | |
| # Make sure the directory exists | |
| echo "Current directory: $(ls -d src/mddb-database/ || echo "Directory does not exist")" | |
| # git subtree split extract only commits under src/mddb-database/ and creates a temporal branch with clean history | |
| # The command 'git subtree split' creates a new temporal commit which contains changes only under the subtree directory | |
| # Therefore this commit is not visible neither in the repo history | |
| SUBTREE_COMMIT=$(git subtree split --prefix=src/mddb-database) | |
| echo $SUBTREE_COMMIT | |
| echo "subtree_commit=$SUBTREE_COMMIT" >> $GITHUB_OUTPUT | |
| echo "📦 Extracted commit: $SUBTREE_COMMIT" | |
| - name: Open debug session | |
| uses: mxschmitt/action-tmate@v3 | |
| if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug }} | |
| - name: Push to MDDB database repo | |
| if: steps.split.outputs.subtree_commit != '' | |
| run: | | |
| git push https://github.com/mmb-irb/mddb-database.git ${{ steps.split.outputs.subtree_commit }}:master | |
| echo "✅ MDDB database updated" |