You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.9 KiB
52 lines
1.9 KiB
kind: pipeline
|
|
type: exec
|
|
name: deploy
|
|
clone:
|
|
disable: true
|
|
|
|
# 触发分支须包含下方 DEPLOY_BRANCH(或在 Drone 仓库变量里覆盖 DEPLOY_BRANCH)
|
|
trigger:
|
|
branch:
|
|
- deploy
|
|
event:
|
|
- push
|
|
|
|
steps:
|
|
- name: deploy
|
|
environment:
|
|
DEPLOY_BRANCH: deploy
|
|
REPO_DIR: /root/projects/nuxt4-demo/nuxt4-demo-origin
|
|
GIT_REMOTE: git@gitee.com:xieyaxin/nuxt4-demo.git
|
|
UNZIP_DIR: /root/projects/nuxt4-demo/nuxt4-demo
|
|
DEPLOY_SSH_KEY:
|
|
from_secret: DEPLOY_SSH_KEY
|
|
commands:
|
|
- export HOME=/root
|
|
- mkdir -p -m 700 "$HOME/.ssh"
|
|
- umask 077 && printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/id_rsa"
|
|
- 'ssh-keyscan -H -T 15 gitee.com > "$HOME/.ssh/known_hosts" && chmod 644 "$HOME/.ssh/known_hosts"'
|
|
- 'export SSH_OPTS="-i $HOME/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=yes -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3"'
|
|
# Gitee 等在认证成功时仍可能返回非 0,故忽略退出码
|
|
- 'ssh $SSH_OPTS -T git@gitee.com || true'
|
|
- 'export GIT_SSH_COMMAND="ssh $SSH_OPTS"'
|
|
- |
|
|
set -e
|
|
BRANCH="$DEPLOY_BRANCH"
|
|
REPO_DIR="$REPO_DIR"
|
|
GIT_REMOTE="$GIT_REMOTE"
|
|
if [ -d "$REPO_DIR/.git" ]; then
|
|
git -C "$REPO_DIR" fetch --depth 1 origin "$BRANCH"
|
|
git -C "$REPO_DIR" checkout -B "$BRANCH" "origin/$BRANCH"
|
|
git -C "$REPO_DIR" reset --hard "origin/$BRANCH"
|
|
git -C "$REPO_DIR" clean -fdx
|
|
else
|
|
rm -rf "$REPO_DIR"
|
|
mkdir -p "$(dirname "$REPO_DIR")"
|
|
git clone --depth 1 -b "$BRANCH" "$GIT_REMOTE" "$REPO_DIR"
|
|
fi
|
|
- |
|
|
set -e
|
|
[ -f "$REPO_DIR/build-output.tar.gz" ] || { echo "build-output.tar.gz not found in $REPO_DIR"; exit 1; }
|
|
rm -rf "$UNZIP_DIR"
|
|
mkdir -p "$UNZIP_DIR"
|
|
tar -xzf "$REPO_DIR/build-output.tar.gz" -C "$UNZIP_DIR"
|