Files
pk-lab-xhs/.gitea/workflows/deploy.yml
T
codex-bot 350aae797f
Verify mini program and deploy preview / verify-deploy (push) Failing after 34s
feat: launch PK testing application
2026-09-18 21:50:25 +08:00

50 lines
2.2 KiB
YAML

name: Verify mini program and deploy preview
on:
push:
branches: [main]
pull_request:
concurrency:
group: pk-lab-xhs-production
cancel-in-progress: false
jobs:
verify-deploy:
runs-on: ubuntu-latest
container: { image: docker:27-cli }
timeout-minutes: 20
env:
SOURCE_SERVER: ${{ gitea.server_url }}
SOURCE_REPOSITORY: ${{ gitea.repository }}
SOURCE_REVISION: ${{ gitea.sha }}
DEPLOY_PORT: ${{ vars.DEPLOY_PORT || '3001' }}
API_BASE_URL: ${{ vars.API_BASE_URL || 'http://47.76.92.159:18082' }}
steps:
- name: Fetch exact revision
env: { SOURCE_TOKEN: "${{ secrets.GITEA_TOKEN }}" }
run: |
set -eu
apk add --no-cache python3 nodejs curl
python3 - <<'PY'
import io,os,shutil,tarfile,tempfile,urllib.request
from pathlib import Path
url=f"{os.environ['SOURCE_SERVER'].rstrip('/')}/api/v1/repos/{os.environ['SOURCE_REPOSITORY']}/archive/{os.environ['SOURCE_REVISION']}.tar.gz"
req=urllib.request.Request(url,headers={'Authorization':'token '+os.environ['SOURCE_TOKEN']})
with urllib.request.urlopen(req,timeout=60) as r:data=r.read()
with tempfile.TemporaryDirectory() as d:
with tarfile.open(fileobj=io.BytesIO(data),mode='r:gz') as a:a.extractall(d,filter='data')
roots=list(Path(d).iterdir());shutil.copytree(roots[0],Path.cwd(),dirs_exist_ok=True)
PY
- name: Check source and preview
run: npm run check
- name: Build preview image
run: docker build -t "pk-lab-xhs:$SOURCE_REVISION" .
- name: Update permanent preview container
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
run: |
set -eu
docker rm -f pk-lab-xhs-preview 2>/dev/null || true
docker run -d --name pk-lab-xhs-preview --restart unless-stopped --read-only --tmpfs /var/cache/nginx --tmpfs /var/run -e API_BASE_URL="$API_BASE_URL" -p "$DEPLOY_PORT:8080" "pk-lab-xhs:$SOURCE_REVISION"
for i in 1 2 3 4 5 6; do curl -fsS "http://127.0.0.1:$DEPLOY_PORT/health" && exit 0; sleep 2; done
docker logs pk-lab-xhs-preview
exit 1