Skip to content

Commit db89625

Browse files
committed
Initial commit
0 parents  commit db89625

File tree

744 files changed

+56028
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

744 files changed

+56028
-0
lines changed

.github/workflows/build-api-image.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
SHA=$(git rev-parse HEAD)
6+
REPO_NAME=langgenius/dify
7+
API_REPO_NAME="${REPO_NAME}-api"
8+
9+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
10+
REFSPEC=$(echo "${GITHUB_HEAD_REF}" | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40)
11+
PR_NUM=$(echo "${GITHUB_REF}" | sed 's:refs/pull/::' | sed 's:/merge::')
12+
LATEST_TAG="pr-${PR_NUM}"
13+
CACHE_FROM_TAG="latest"
14+
elif [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
15+
REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/tags/::' | head -c 40)
16+
LATEST_TAG="${REFSPEC}"
17+
CACHE_FROM_TAG="latest"
18+
else
19+
REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/heads/::' | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40)
20+
LATEST_TAG="${REFSPEC}"
21+
CACHE_FROM_TAG="${REFSPEC}"
22+
fi
23+
24+
if [[ "${REFSPEC}" == "main" ]]; then
25+
LATEST_TAG="latest"
26+
CACHE_FROM_TAG="latest"
27+
fi
28+
29+
echo "Pulling cache image ${API_REPO_NAME}:${CACHE_FROM_TAG}"
30+
if docker pull "${API_REPO_NAME}:${CACHE_FROM_TAG}"; then
31+
API_CACHE_FROM_SCRIPT="--cache-from ${API_REPO_NAME}:${CACHE_FROM_TAG}"
32+
else
33+
echo "WARNING: Failed to pull ${API_REPO_NAME}:${CACHE_FROM_TAG}, disable build image cache."
34+
API_CACHE_FROM_SCRIPT=""
35+
fi
36+
37+
38+
cat<<EOF
39+
Rolling with tags:
40+
- ${API_REPO_NAME}:${SHA}
41+
- ${API_REPO_NAME}:${REFSPEC}
42+
- ${API_REPO_NAME}:${LATEST_TAG}
43+
EOF
44+
45+
#
46+
# Build image
47+
#
48+
cd api
49+
docker build \
50+
${API_CACHE_FROM_SCRIPT} \
51+
--build-arg COMMIT_SHA=${SHA} \
52+
-t "${API_REPO_NAME}:${SHA}" \
53+
-t "${API_REPO_NAME}:${REFSPEC}" \
54+
-t "${API_REPO_NAME}:${LATEST_TAG}" \
55+
--label "sha=${SHA}" \
56+
--label "built_at=$(date)" \
57+
--label "build_actor=${GITHUB_ACTOR}" \
58+
.
59+
60+
# push
61+
docker push --all-tags "${API_REPO_NAME}"

.github/workflows/build-api-image.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Push API Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'deploy/dev'
8+
pull_request:
9+
types: [synchronize, opened, reopened, ready_for_review]
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
if: github.event.pull_request.draft == false
15+
steps:
16+
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
17+
uses: actions/checkout@v2
18+
with:
19+
persist-credentials: false
20+
21+
- name: Login to Docker Hub
22+
uses: docker/login-action@v2
23+
with:
24+
username: ${{ secrets.DOCKERHUB_USER }}
25+
password: ${{ secrets.DOCKERHUB_TOKEN }}
26+
27+
- name: Build and push Docker image
28+
shell: bash
29+
env:
30+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
31+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
32+
run: |
33+
/bin/bash .github/workflows/build-api-image.sh
34+
35+
- name: Deploy to server
36+
if: github.ref == 'refs/heads/deploy/dev'
37+
uses: appleboy/ssh-action@v0.1.8
38+
with:
39+
host: ${{ secrets.SSH_HOST }}
40+
username: ${{ secrets.SSH_USER }}
41+
key: ${{ secrets.SSH_PRIVATE_KEY }}
42+
script: |
43+
${{ secrets.SSH_SCRIPT }}

.github/workflows/build-web-image.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
SHA=$(git rev-parse HEAD)
6+
REPO_NAME=langgenius/dify
7+
WEB_REPO_NAME="${REPO_NAME}-web"
8+
9+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
10+
REFSPEC=$(echo "${GITHUB_HEAD_REF}" | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40)
11+
PR_NUM=$(echo "${GITHUB_REF}" | sed 's:refs/pull/::' | sed 's:/merge::')
12+
LATEST_TAG="pr-${PR_NUM}"
13+
CACHE_FROM_TAG="latest"
14+
elif [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
15+
REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/tags/::' | head -c 40)
16+
LATEST_TAG="${REFSPEC}"
17+
CACHE_FROM_TAG="latest"
18+
else
19+
REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/heads/::' | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40)
20+
LATEST_TAG="${REFSPEC}"
21+
CACHE_FROM_TAG="${REFSPEC}"
22+
fi
23+
24+
if [[ "${REFSPEC}" == "main" ]]; then
25+
LATEST_TAG="latest"
26+
CACHE_FROM_TAG="latest"
27+
fi
28+
29+
echo "Pulling cache image ${WEB_REPO_NAME}:${CACHE_FROM_TAG}"
30+
if docker pull "${WEB_REPO_NAME}:${CACHE_FROM_TAG}"; then
31+
WEB_CACHE_FROM_SCRIPT="--cache-from ${WEB_REPO_NAME}:${CACHE_FROM_TAG}"
32+
else
33+
echo "WARNING: Failed to pull ${WEB_REPO_NAME}:${CACHE_FROM_TAG}, disable build image cache."
34+
WEB_CACHE_FROM_SCRIPT=""
35+
fi
36+
37+
38+
cat<<EOF
39+
Rolling with tags:
40+
- ${WEB_REPO_NAME}:${SHA}
41+
- ${WEB_REPO_NAME}:${REFSPEC}
42+
- ${WEB_REPO_NAME}:${LATEST_TAG}
43+
EOF
44+
45+
#
46+
# Build image
47+
#
48+
cd web
49+
docker build \
50+
${WEB_CACHE_FROM_SCRIPT} \
51+
--build-arg COMMIT_SHA=${SHA} \
52+
-t "${WEB_REPO_NAME}:${SHA}" \
53+
-t "${WEB_REPO_NAME}:${REFSPEC}" \
54+
-t "${WEB_REPO_NAME}:${LATEST_TAG}" \
55+
--label "sha=${SHA}" \
56+
--label "built_at=$(date)" \
57+
--label "build_actor=${GITHUB_ACTOR}" \
58+
.
59+
60+
docker push --all-tags "${WEB_REPO_NAME}"

.github/workflows/build-web-image.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Push WEB Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'deploy/dev'
8+
pull_request:
9+
types: [synchronize, opened, reopened, ready_for_review]
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
if: github.event.pull_request.draft == false
15+
steps:
16+
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
17+
uses: actions/checkout@v2
18+
with:
19+
persist-credentials: false
20+
21+
- name: Login to Docker Hub
22+
uses: docker/login-action@v2
23+
with:
24+
username: ${{ secrets.DOCKERHUB_USER }}
25+
password: ${{ secrets.DOCKERHUB_TOKEN }}
26+
27+
- name: Build and push Docker image
28+
shell: bash
29+
env:
30+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
31+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
32+
run: |
33+
/bin/bash .github/workflows/build-web-image.sh
34+
35+
- name: Deploy to server
36+
if: github.ref == 'refs/heads/deploy/dev'
37+
uses: appleboy/ssh-action@v0.1.8
38+
with:
39+
host: ${{ secrets.SSH_HOST }}
40+
username: ${{ secrets.SSH_USER }}
41+
key: ${{ secrets.SSH_PRIVATE_KEY }}
42+
script: |
43+
${{ secrets.SSH_SCRIPT }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import re
3+
from zhon.hanzi import punctuation
4+
5+
def has_chinese_characters(text):
6+
for char in text:
7+
if '\u4e00' <= char <= '\u9fff' or char in punctuation:
8+
return True
9+
return False
10+
11+
def check_file_for_chinese_comments(file_path):
12+
with open(file_path, 'r', encoding='utf-8') as file:
13+
for line_number, line in enumerate(file, start=1):
14+
if has_chinese_characters(line):
15+
print(f"Found Chinese characters in {file_path} on line {line_number}:")
16+
print(line.strip())
17+
return True
18+
return False
19+
20+
def main():
21+
has_chinese = False
22+
excluded_files = ["model_template.py", 'stopwords.py', 'commands.py', 'indexing_runner.py']
23+
24+
for root, _, files in os.walk("."):
25+
for file in files:
26+
if file.endswith(".py") and file not in excluded_files:
27+
file_path = os.path.join(root, file)
28+
if check_file_for_chinese_comments(file_path):
29+
has_chinese = True
30+
31+
if has_chinese:
32+
raise Exception("Found Chinese characters in Python files. Please remove them.")
33+
34+
if __name__ == "__main__":
35+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Check for Chinese comments
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
check-chinese-comments:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Check out repository
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: 3.9
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install zhon
28+
29+
- name: Run script to check for Chinese comments
30+
run: |
31+
python .github/workflows/check_no_chinese_comments.py

.github/workflows/flake8.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: PEP8 Check
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
jobs:
8+
pep8:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python 3.10
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.10'
16+
- name: Install flake8
17+
run: pip install flake8
18+
- name: Run flake8
19+
run: flake8 --ignore=E501 .

0 commit comments

Comments
 (0)