Rearrange file locations and install order #2
Workflow file for this run
This file contains 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: Check if ORM update is needed | ||
on: | ||
workflow_call: | ||
inputs: | ||
DATABASE_SCHEMA: | ||
required: true | ||
type: string | ||
jobs: | ||
orm-update: | ||
uses: ./.github/workflows/update-orm.yml | ||
name: Update ORM | ||
runs-on: ubuntu-latest | ||
container: mariadb | ||
services: | ||
mariadb: | ||
image: mariadb:10.6 | ||
env: | ||
MYSQL_DATABASE: ispybtest | ||
MYSQL_ROOT_PASSWORD: mysql_root_pwd | ||
ports: | ||
- 3306:3306 | ||
outputs: | ||
output1: ${{ steps.checkUpdate.needsUpdate }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.10 | ||
- name: Check if update is required | ||
id: checkUpdate | ||
run: | | ||
set -eu | ||
CURRENT_VERSION=$(grep __schema_version__ _auto_db_schema.py | cut -d'"' -f2) | ||
diff -a <(echo ${CURRENT_VERSION}) <(echo ${{ inputs.DATABASE_SCHEMA }}) >/dev/null && { | ||
echo "##[section]ORM is up to date (${CURRENT_VERSION})" | ||
echo "needsUpdate=false" >> $GITHUB_OUTPUT | ||
} || { | ||
echo "##[warning]ORM needs to be updated (${CURRENT_VERSION} -> ${{ inputs.DATABASE_SCHEMA }})." | ||
echo "needsUpdate=talse" >> $GITHUB_OUTPUT | ||
} | ||
working-directory: ./src/ispyb/sqlalchemy | ||
- name: Install sqlacodegen | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' }} | ||
run: | | ||
set -eux | ||
pip install -r requirements_orm.txt | ||
pip install pre-commit | ||
- name: Get database schema | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' }} | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ispyb-database.tar.gz | ||
path: dist/ | ||
- name: Set up reference database schema | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' }} | ||
run: | | ||
set -eu | ||
cat >~/.my.cnf <<EOF | ||
[client] | ||
user=root | ||
host=127.0.0.1 | ||
password=mysql_root_pwd | ||
database=ispybtest | ||
EOF | ||
echo "Installing mariadb-client" | ||
sudo apt-get install mariadb-client | ||
mkdir schema | ||
cd schema | ||
tar xfz "$(System.ArtifactsDirectory)/package/ispyb-database.tar.gz" | ||
patch -p1 < "$(Build.SourcesDirectory)/src/ispyb/sqlalchemy/sqlacodegen.patch" | ||
ln ~/.my.cnf .my.cnf -s | ||
printf 'Waiting for MySQL database to accept connections' | ||
until mysql -e "SHOW DATABASES" >/dev/null; do printf '.'; sleep 0.5; done | ||
printf '\n' | ||
echo "Installing reference database" | ||
./build.sh | ||
echo | ||
echo "Installed tables:" | ||
mysql -D ispyb_build -e "SHOW TABLES" | ||
working-directory: dist | ||
- name: Generate ORM | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' }} | ||
run: | | ||
set -eux | ||
sqlacodegen mysql+mysqlconnector://root:mysql_root_pwd@127.0.0.1/ispyb_build --noinflect --nojoined --outfile _auto_db_schema.py.in | ||
# This code produces false positives due to non-deterministic ordering. | ||
# Add an identifier to the file, and only update/PR the changes when the | ||
# identifier indicates the file is out of date. | ||
cat <(echo "__schema_version__ = \"${{ inputs.DATABASE_SCHEMA }}\"") _auto_db_schema.py.in > _auto_db_schema.py | ||
rm _auto_db_schema.py.in | ||
pre-commit run --files _auto_db_schema.py || echo pre-commit exited with non-zero return code | ||
working-directory: ./src/ispyb/sqlalchemy | ||
- name: Show differences | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' }} | ||
run: git diff | ||
- name: Store artifact | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ORM | ||
path: ./src/ispyb/sqlalchemy/_auto_db_schema.py | ||
- name: Create ORM pull request | ||
if: ${{ steps.checkUpdate.needsUpdate == 'true' && github.ref_name == 'main' }} | ||
run: .azure-pipelines/create-orm-update-pull-request | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |