-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d281e86
commit 9e4ddb8
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Deploy GitHub Pages | ||
|
||
# see also https://github.com/giselles-ai/erd/settings/pages | ||
|
||
on: | ||
# NOTE: Regardless of whether it's a push or a workflow_dispatch, we must specify the branch or tag for deployment in each environment. | ||
# see https://github.com/giselles-ai/erd/settings/environments | ||
push: | ||
branches: | ||
- gh-pages | ||
- main | ||
paths: | ||
- .github/workflows/github-pages.yml | ||
- drizzle/**/* | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# NOTE: Following the example below, the job is structured into distinct build and deploy phases. | ||
# see https://docs.github.com/ja/pages/getting-started-with-github-pages/using-custom-workflows-with-github-pages | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
|
||
services: | ||
# Note: Required for Step 2: Prepare the input file. | ||
postgres: | ||
image: postgres:15 | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
env: | ||
POSTGRES_PASSWORD: password | ||
|
||
steps: | ||
# Step 1: Download SQL files from another repository | ||
- name: Download SQL files | ||
shell: bash | ||
run: | | ||
# base URL | ||
base_url="https://github.com/giselles-ai/giselle/tree/main" | ||
# download migration files | ||
mkdir migrations | ||
for i in $(seq -f "%04g" 1 20); do | ||
# Define the base URL | ||
base_url="https://github.com/giselles-ai/giselle/tree/main/migrations" | ||
# Fetch the list of files in the migrations directory | ||
file_list=$(curl -s "$base_url" | grep -oP 'href="\K[^"]+\.sql') | ||
# Check if the file with the current sequence number exists | ||
for file in $file_list; do | ||
if [[ $file == *"${i}_"* ]]; then | ||
migration_url="https://github.com${file}" | ||
echo "Downloading $migration_url" | ||
curl -o "migrations/$(basename $file)" "$migration_url" | ||
break | ||
fi | ||
done | ||
# If no file was found for the current sequence number, break the loop | ||
if [[ ! -f "migrations/${i}_*.sql" ]]; then | ||
echo "No more migration files found for sequence number $i" | ||
break | ||
fi | ||
done | ||
# merge all migration files | ||
cat migrations/*.sql > migrations.sql | ||
# Step 2: Prepare the input file | ||
- name: Prepare the input file (dump.sql) | ||
shell: bash | ||
run: | | ||
pg_dump_docker_image="postgres:15" | ||
dbname="development" | ||
echo "CREATE DATABASE ${dbname}" | psql "postgres://postgres:password@0.0.0.0:5432" | ||
cat migrations.sql | psql "postgres://postgres:password@0.0.0.0:5432/${dbname}" | ||
docker run --rm \ | ||
--network host \ | ||
${pg_dump_docker_image} \ | ||
pg_dump --schema-only --no-privileges --no-owner \ | ||
"postgres://postgres:password@0.0.0.0:5432/${dbname}" > dump.sql | ||
# Step 3: Generate ERD (Entity-Relationship Diagram) to `./_site` | ||
- name: Generate ERD | ||
run: npx @liam-hq/cli@latest erd build --input dump.sql --format postgres | ||
- run: mv ./dist ./_site | ||
|
||
# Step 4: Upload Artifact | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v4 | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
|
||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: build | ||
permissions: | ||
id-token: write | ||
pages: write | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |