fix: use manual checkout for gitea actions
This commit is contained in:
+40
-10
@@ -14,14 +14,29 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
github-server-url: https://api.xiaoxiajianji.com/git
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)"
|
||||
git init .
|
||||
git remote add origin "$repo_url"
|
||||
git -c http.https://api.xiaoxiajianji.com/.extraheader="$auth_header" fetch --depth=1 origin "$GITHUB_SHA"
|
||||
git checkout --force FETCH_HEAD
|
||||
|
||||
- name: Sync code to staging workspace
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p /var/lib/xiaoxia-saas-staging/repo
|
||||
rsync -a --delete --exclude '.git' ./ /var/lib/xiaoxia-saas-staging/repo/
|
||||
set -euo pipefail
|
||||
python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
root = Path('/var/lib/xiaoxia-saas-staging/repo')
|
||||
if root.exists():
|
||||
shutil.rmtree(root)
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
PY
|
||||
tar --exclude=.git -cf - . | tar -xf - -C /var/lib/xiaoxia-saas-staging/repo
|
||||
|
||||
- name: Verify staging env file
|
||||
run: |
|
||||
@@ -69,14 +84,29 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
github-server-url: https://api.xiaoxiajianji.com/git
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)"
|
||||
git init .
|
||||
git remote add origin "$repo_url"
|
||||
git -c http.https://api.xiaoxiajianji.com/.extraheader="$auth_header" fetch --depth=1 origin "$GITHUB_SHA"
|
||||
git checkout --force FETCH_HEAD
|
||||
|
||||
- name: Sync code to production workspace
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p /var/lib/xiaoxia-saas-production/repo
|
||||
rsync -a --delete --exclude '.git' ./ /var/lib/xiaoxia-saas-production/repo/
|
||||
set -euo pipefail
|
||||
python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
root = Path('/var/lib/xiaoxia-saas-production/repo')
|
||||
if root.exists():
|
||||
shutil.rmtree(root)
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
PY
|
||||
tar --exclude=.git -cf - . | tar -xf - -C /var/lib/xiaoxia-saas-production/repo
|
||||
|
||||
- name: Verify production env file
|
||||
run: |
|
||||
|
||||
+28
-23
@@ -9,61 +9,66 @@ on:
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
github-server-url: https://api.xiaoxiajianji.com/git
|
||||
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)"
|
||||
git init .
|
||||
git remote add origin "$repo_url"
|
||||
git -c http.https://api.xiaoxiajianji.com/.extraheader="$auth_header" fetch --depth=1 origin "$GITHUB_SHA"
|
||||
git checkout --force FETCH_HEAD
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
pytest tests/integration/ -v --cov=packages --cov=apps --cov-report=xml --cov-report=term
|
||||
|
||||
- name: Upload coverage reports
|
||||
uses: codecov/codecov-action@v3
|
||||
if: always()
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
fail_ci_if_error: false
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
github-server-url: https://api.xiaoxiajianji.com/git
|
||||
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)"
|
||||
git init .
|
||||
git remote add origin "$repo_url"
|
||||
git -c http.https://api.xiaoxiajianji.com/.extraheader="$auth_header" fetch --depth=1 origin "$GITHUB_SHA"
|
||||
git checkout --force FETCH_HEAD
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
|
||||
- name: Install linting tools
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install black flake8 mypy
|
||||
|
||||
|
||||
- name: Run Black (check only)
|
||||
run: |
|
||||
black --check packages/ apps/ tests/
|
||||
|
||||
|
||||
- name: Run Flake8
|
||||
run: |
|
||||
flake8 packages/ apps/ tests/ --max-line-length=120 --extend-ignore=E203,W503
|
||||
|
||||
|
||||
- name: Run MyPy
|
||||
run: |
|
||||
mypy packages/ apps/ --ignore-missing-imports
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ mypy packages/ apps/ --ignore-missing-imports
|
||||
## 故障排查
|
||||
|
||||
### Actions 触发了但 checkout 失败
|
||||
优先检查 runner 能否从 job 容器访问 Gitea 实例地址;如果 Gitea 挂在 `/git` 这类子路径下,需要给 `actions/checkout` 显式传 `github-server-url`。
|
||||
优先检查 runner 能否从 job 容器访问 Gitea 实例地址;如果 Gitea 挂在 `/git` 这类子路径下,优先使用手写 `git fetch`,不要依赖 `actions/checkout` 自动拼接仓库地址。
|
||||
|
||||
### Deploy 成功但业务链不通
|
||||
优先检查:
|
||||
|
||||
Reference in New Issue
Block a user