42 lines
1.4 KiB
YAML
42 lines
1.4 KiB
YAML
name: Switch/Rollback Version
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: "enter the version to switch to (example: v1.0.2)"
|
|
required: true
|
|
default: ""
|
|
|
|
jobs:
|
|
switch-version:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Execute remote SSH commands
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: ${{ secrets.SERVER_USER }}
|
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
|
script: |
|
|
REMOTE_BASE=${{ secrets.REMOTE_PATH }}
|
|
RELEASES_PATH="$REMOTE_BASE/releases"
|
|
CURRENT_PATH="$REMOTE_BASE/current"
|
|
TARGET_VERSION="${{ github.event.inputs.version }}"
|
|
|
|
echo ">>> Switching to version: $TARGET_VERSION"
|
|
|
|
# 1. Check if the target directory exists
|
|
if [ -d "$RELEASES_PATH/$TARGET_VERSION" ]; then
|
|
# 2. Modify symbolic link (use -n and -f to ensure atomic replacement of directory links)
|
|
ln -sfn "$RELEASES_PATH/$TARGET_VERSION" "$CURRENT_PATH"
|
|
|
|
echo ">>> Switching to version: $TARGET_VERSION successfully"
|
|
ls -l "$CURRENT_PATH"
|
|
else
|
|
echo ">>> Error: Version $TARGET_VERSION does not exist in $RELEASES_PATH"
|
|
echo ">>> Existing version list:"
|
|
ls -1 "$RELEASES_PATH"
|
|
exit 1
|
|
fi
|