mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-12 02:57:22 +00:00
96 lines
3.7 KiB
Java
96 lines
3.7 KiB
Java
name: Master Auto Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [ master ]
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: master-auto-deploy-production
|
|
cancel-in-progress: false
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-22.04
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up JDK 21
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '21'
|
|
distribution: temurin
|
|
cache: maven
|
|
|
|
- name: Build with Maven
|
|
run: mvn -B package -Dmaven.test.skip=true --file pom.xml
|
|
|
|
- name: Upload server jar artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: kkfileview-server-jar
|
|
path: server/target/kkFileView-*.jar
|
|
retention-days: 7
|
|
|
|
deploy-windows:
|
|
needs: build
|
|
runs-on: ubuntu-22.04
|
|
env:
|
|
GITHUB_REPOSITORY_NAME: ${{ github.repository }}
|
|
GITHUB_RUN_ID_VALUE: ${{ github.run_id }}
|
|
KK_DEPLOY_HOST: ${{ secrets.KK_DEPLOY_HOST }}
|
|
KK_DEPLOY_PORT: ${{ secrets.KK_DEPLOY_PORT }}
|
|
KK_DEPLOY_USERNAME: ${{ secrets.KK_DEPLOY_USERNAME }}
|
|
KK_DEPLOY_PASSWORD: ${{ secrets.KK_DEPLOY_PASSWORD }}
|
|
KK_DEPLOY_ROOT: ${{ secrets.KK_DEPLOY_ROOT }}
|
|
KK_DEPLOY_HEALTH_URL: ${{ secrets.KK_DEPLOY_HEALTH_URL }}
|
|
KK_DEPLOY_ARTIFACT_NAME: kkfileview-server-jar
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Install WinRM dependencies
|
|
run: pip install pywinrm
|
|
|
|
- name: Validate deploy secrets
|
|
run: |
|
|
test -n "$KK_DEPLOY_HOST" || (echo "Missing secret: KK_DEPLOY_HOST" && exit 1)
|
|
test -n "$KK_DEPLOY_USERNAME" || (echo "Missing secret: KK_DEPLOY_USERNAME" && exit 1)
|
|
test -n "$KK_DEPLOY_PASSWORD" || (echo "Missing secret: KK_DEPLOY_PASSWORD" && exit 1)
|
|
|
|
- name: Resolve artifact download URL
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
artifact_json=$(curl -fsSL \
|
|
-H "Authorization: Bearer $GH_TOKEN" \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
"https://api.github.com/repos/$GITHUB_REPOSITORY_NAME/actions/runs/$GITHUB_RUN_ID_VALUE/artifacts")
|
|
artifact_id=$(ARTIFACT_JSON="$artifact_json" ARTIFACT_NAME="$KK_DEPLOY_ARTIFACT_NAME" python -c "import json, os; payload=json.loads(os.environ['ARTIFACT_JSON']); name=os.environ['ARTIFACT_NAME']; matches=[artifact for artifact in payload.get('artifacts', []) if artifact.get('name') == name]; matches or (_ for _ in ()).throw(SystemExit(f\"Artifact '{name}' not found for run\")); len(matches) == 1 or (_ for _ in ()).throw(SystemExit(f\"Expected one artifact named '{name}', found {len(matches)}\")); print(matches[0]['id'])")
|
|
headers_file=$(mktemp)
|
|
curl -fsS -D "$headers_file" -o /dev/null \
|
|
-H "Authorization: Bearer $GH_TOKEN" \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
"https://api.github.com/repos/$GITHUB_REPOSITORY_NAME/actions/artifacts/$artifact_id/zip"
|
|
artifact_url=$(awk 'BEGIN{IGNORECASE=1} /^location:/ { sub(/\r$/, "", $0); print substr($0, index($0, ":") + 2); exit }' "$headers_file")
|
|
test -n "$artifact_url" || (echo "Failed to resolve artifact download redirect URL" && exit 1)
|
|
rm -f "$headers_file"
|
|
echo "KK_DEPLOY_ARTIFACT_URL=$artifact_url" >> "$GITHUB_ENV"
|
|
|
|
- name: Deploy to Windows server
|
|
run: python .github/scripts/deploy_windows_winrm.py
|