Skip to content

Sync MDDB database

Sync MDDB database #20

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: true
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 }}
ref: master
- 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 }}
env:
MDDB_REPOS: ${{ secrets.MDDB_REPOS }}
- name: Push to MDDB database repo
if: steps.split.outputs.subtree_commit != ''
env:
MDDB_REPOS: ${{ secrets.MDDB_REPOS }}
run: |
git push https://x-access-token:${MDDB_REPOS}@github.com/mmb-irb/mddb-database.git \
${{ steps.split.outputs.subtree_commit }}:master --force
echo "✅ MDDB database updated"