Skip to content

Commit bcbbdc4

Browse files
committed
Update Docker image workflow to generate and save SQL
1 parent ced5695 commit bcbbdc4

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

.github/workflows/docker-image.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,33 @@ jobs:
6464
registry: ghcr.io
6565
username: ${{ github.repository_owner }}
6666
password: ${{ secrets.GH_PAT }}
67+
- name: Install jq
68+
run: |
69+
sudo apt-get install jq
6770
- name: Generate SQL
6871
run: |
6972
echo "build_target=${{ matrix.build_target }}"
7073
echo "tag=${{ needs.define-matrix.outputs.tag }}"
7174
echo "tag_cn=${{ needs.define-matrix.outputs.tag_cn }}"
72-
echo "image_name=$image_name" >> $GITHUB_OUTPUT
73-
echo "image_name_cn=$image_name_cn" >> $GITHUB_OUTPUT
7475
image_name=$(bash script/get_image_name.sh ${{ github.repository_owner }} "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag }}")
7576
image_name_cn=$(bash script/get_image_name.sh ${{ github.repository_owner }} "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag_cn }}")
77+
echo "image_name=$image_name" >> $GITHUB_OUTPUT
78+
echo "image_name_cn=$image_name_cn" >> $GITHUB_OUTPUT
7679
template_json=$(bash script/get_template_config_json.sh "${{ matrix.build_target }}")
77-
template_repo_json=$(bash script/get_template_repo_json.sh "${{ matrix.build_target }}")
78-
sql=$(bash script/generate_template_sql.sh $image_name $template_json $template_repo_json)
79-
# 保存 SQL 到文件
80-
mkdir -p /sql/templates/
81-
build_target_filename=$(echo "${{ matrix.build_target }}" | sed 's/\//_/g')
82-
echo "$sql" > "/sql/templates/${{ build_target_filename }}.sql.tmp"
80+
echo "template_json=$template_json"
81+
template_repo_json=$(bash script/get_template_repo_config_json.sh "${{ matrix.build_target }}")
82+
echo "template_repo_json=$template_repo_json"
83+
sql=$(bash script/generate_template_sql.sh '$image_name' '$template_json' '$template_repo_json')
84+
echo "sql=$sql" >> $GITHUB_OUTPUT
85+
# - name: Save SQL to GitHub Packages
86+
# run: |
87+
# bash script/save_sql.sh "${{ matrix.build_target }}" "$sql"
88+
- run: mkdir -p sql/templates
89+
- run: echo $sql > sql/templates/$(echo "$BUILD_TARGET" | sed 's/\//_/g').sql
90+
- uses: actions/upload-artifact@v4
91+
with:
92+
name: upload sql
93+
path: sql/templates/$(echo "$BUILD_TARGET" | sed 's/\//_/g').sql
8394
- name: Build and push image
8495
run: |
8596
echo "building image $image_name"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "v4.10.0",
3+
"port": 4200,
4+
"isDeleted": false
5+
}

Framework/astro/repo.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "Astro",
3+
"isPublic": true,
4+
"kind": "FRAMEWORK",
5+
"description": "Complete Google Angular Development Toolchain Environment"
6+
}

bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Usage: script/generate_template_sql.sh <image> <template_json> <template_repo_json>

script/generate_template_sql.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/bin/bash
22

3-
# 确保脚本在发生错误时立即退出
4-
set -e
53

6-
if [ "$#" -ne 4 ]
7-
then
4+
if [ "$#" -ne 3 ]; then
85
echo "Usage: $0 <image> <template_json> <template_repo_json>"
96
exit 1
107
fi
@@ -14,13 +11,18 @@ IMAGE=$1
1411
TEMPLATE_JSON=$2
1512
TEMPLATE_REPO_JSON=$3
1613

14+
echo "IMAGE=$IMAGE"
15+
echo "TEMPLATE_JSON=$TEMPLATE_JSON"
16+
echo "TEMPLATE_REPO_JSON=$TEMPLATE_REPO_JSON"
17+
1718
SQL_DIR="sql"
1819
SQL_FILE="$SQL_DIR/$RUNTIME_NAME-$SHORT_COMMIT_ID.sql.tmp"
1920
# IMAGE="ghcr.io/labring-actions/devbox/$RUNTIME_NAME:$SHORT_COMMIT_ID"
2021
RUNTIME_NAME=$(echo "$TEMPLATE_REPO_JSON" | jq -r '.name')
2122
IS_PUBLIC=$(echo "$TEMPLATE_REPO_JSON" | jq -r '.isPublic')
2223
KIND=$(echo "$TEMPLATE_REPO_JSON" | jq -r '.kind')
2324

25+
2426
# 创建目录(如果不存在)
2527
mkdir -p $SQL_DIR
2628

@@ -53,7 +55,6 @@ WHERE NOT EXISTS (
5355
);
5456
5557
-- 2. 更新已存在的 Template为 isDeleted (如果有)
56-
WITH
5758
WITH org_uid AS (
5859
SELECT "uid" FROM "Organization"
5960
WHERE "name" = 'labring'
@@ -93,5 +94,3 @@ SELECT
9394
now(),
9495
now();
9596
EOF
96-
97-
echo "Generated SQL Template File: $SQL_FILE"

script/save_sql.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# 确保脚本在发生错误时立即退出
4+
set -e
5+
6+
if [ "$#" -ne 2 ]; then
7+
echo "Usage: $0 <build_target> <sql>"
8+
exit 1
9+
fi
10+
11+
BUILD_TARGET=$1
12+
SQL=$2
13+
14+
# 创建目录(如果不存在)
15+
mkdir -p sql/templates/
16+
17+
# 将build_target中的斜杠替换为下划线,用于文件名
18+
BUILD_TARGET_FILENAME=$(echo "$BUILD_TARGET" | sed 's/\//_/g')
19+
20+
# 保存SQL到文件
21+
echo "$SQL" > "/sql/templates/${BUILD_TARGET_FILENAME}.sql"
22+
23+
echo "SQL saved to /sql/templates/${BUILD_TARGET_FILENAME}.sql"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select * from user

0 commit comments

Comments
 (0)