74 lines
2.2 KiB
YAML
74 lines
2.2 KiB
YAML
name: offline-release
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
package-and-deploy:
|
|
runs-on: build-host
|
|
steps:
|
|
- name: Prepare local worktree
|
|
env:
|
|
MAIBOT_REPO_URL: http://127.0.0.1:3000/${{ gitea.repository }}.git
|
|
MAIBOT_REPO_SHA: ${{ gitea.sha }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
worktree_root=/tmp/maibot-actions
|
|
worktree="${worktree_root}/${MAIBOT_REPO_SHA}"
|
|
|
|
rm -rf "$worktree"
|
|
mkdir -p "$worktree_root"
|
|
|
|
git clone --no-checkout "$MAIBOT_REPO_URL" "$worktree"
|
|
git -C "$worktree" checkout --force "$MAIBOT_REPO_SHA"
|
|
git -C "$worktree" clean -dffx
|
|
|
|
app_tag="$(git -C "$worktree" rev-parse --short=12 HEAD)"
|
|
printf 'APP_TAG=%s\n' "$app_tag" >> "$GITHUB_ENV"
|
|
printf 'MAIBOT_WORKTREE=%s\n' "$worktree" >> "$GITHUB_ENV"
|
|
|
|
- name: Stage release directory
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
release_root="${MAIBOT_RELEASE_ROOT:-/srv/maibot/releases}"
|
|
case "$release_root" in
|
|
/srv/maibot/releases|/srv/maibot/releases/*) ;;
|
|
*)
|
|
echo "release root must stay under /srv/maibot/releases" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
release_dir="${release_root}/${APP_TAG}"
|
|
rm -rf "$release_dir"
|
|
mkdir -p "$release_dir"
|
|
git -C "$MAIBOT_WORKTREE" archive HEAD | tar -x -C "$release_dir"
|
|
|
|
printf 'RELEASE_DIR=%s\n' "$release_dir" >> "$GITHUB_ENV"
|
|
|
|
- name: Deploy release
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
runtime_root="${MAIBOT_RUNTIME_ROOT:-/root/maibot-offline}"
|
|
chmod +x "$RELEASE_DIR/deploy/server-maibot/activate-release.sh"
|
|
MAIBOT_RUNTIME_ROOT="$runtime_root" "$RELEASE_DIR/deploy/server-maibot/activate-release.sh" "$RELEASE_DIR"
|
|
|
|
- name: Cleanup worktree
|
|
if: ${{ always() }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
worktree_root=/tmp/maibot-actions/
|
|
case "${MAIBOT_WORKTREE:-}" in
|
|
${worktree_root}*)
|
|
rm -rf "$MAIBOT_WORKTREE"
|
|
;;
|
|
esac
|