Try another approach #7
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: "Build & Publish Database Documentation" | |
on: | |
push: | |
branches: | |
- add-schema-spy-github-action | |
paths: | |
- "database/**" | |
- ".github/workflows/dbdocs.yml" | |
workflow_dispatch: | |
jobs: | |
build: | |
name: "Build SchemaSpy Documentation" | |
runs-on: ubuntu-24.04 | |
steps: | |
# Checkout our code | |
- name: "Checkout Code" | |
uses: actions/checkout@v4 | |
# Install the graphql-engine CLI | |
- name: "Install the graphql-engine CLI" | |
run: | | |
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | /bin/bash | |
# Build & Publish Database Documentation | |
- name: "Build & Publish Database Documentation" | |
env: | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
DBDOCS_TOKEN: ${{ secrets.DBDOCS_TOKEN }} | |
run: | | |
export BRANCH_NAME=${GITHUB_REF##*/}; | |
echo "SHA: ${GITHUB_SHA}"; | |
echo "ACTION/BRANCH_NAME: ${BRANCH_NAME}"; | |
echo "GR: ${GITHUB_REF}"; | |
echo "PWD: $(pwd)"; | |
echo "POSTGRES_PASSWORD=visionzero" > .env; | |
echo "POSTGRES_USER=visionzero" >> .env; | |
echo "POSTGRES_DB=atd_vz_data" >> .env; | |
echo "POSTGRES_HOST_AUTH_METHOD=trust" >> .env; | |
docker compose -f docker-compose-github-dbdocs-action.yml up -d postgis; | |
sleep 10; | |
docker compose -f docker-compose-github-dbdocs-action.yml up -d graphql-engine; | |
sleep 10; | |
cd database; | |
hasura --skip-update-check --database-name=default migrate apply; | |
cd ..; | |
if [ "$BRANCH_NAME" = "production" ]; then | |
PROJECT_NAME="Vision Zero Production"; | |
else | |
PROJECT_NAME="Vision Zero Staging"; | |
fi | |
npm install dbdocs -g; | |
dbdocs db2dbml postgres postgres://visionzero:visionzero@localhost:5432/atd_vz_data -o database.dbml; | |
dbdocs build ./database.dbml --project="$PROJECT_NAME" --public; | |
DOCS_URL="https://dbdocs.io/transportation.data/${PROJECT_NAME// /-}" | |
echo "Documentation URL: ${DOCS_URL}" | |
echo "docs_url=${DOCS_URL}" >> $GITHUB_ENV | |
# Update the check run details_url with the documentation URL | |
- name: "Update check run details_url" | |
uses: actions/github-script@v6 | |
env: | |
DOCS_URL: ${{ env.docs_url }} | |
with: | |
script: | | |
const DOCS_URL = process.env.DOCS_URL; | |
const { owner, repo } = context.repo; | |
const jobName = context.job; | |
// List all check runs for the current commit | |
const checkRunsResponse = await github.rest.checks.listForRef({ | |
owner, | |
repo, | |
ref: context.sha, | |
}); | |
// Find the check run that matches the current job name | |
const checkRun = checkRunsResponse.data.check_runs.find(cr => cr.name === jobName); | |
if (checkRun) { | |
// Update the check run with the documentation URL | |
await github.rest.checks.update({ | |
owner, | |
repo, | |
check_run_id: checkRun.id, | |
details_url: DOCS_URL, | |
}); | |
console.log(`Check run updated with details_url: ${DOCS_URL}`); | |
} else { | |
console.log(`Check run with name ${jobName} not found.`); | |
} |