96 lines
3.0 KiB
YAML
96 lines
3.0 KiB
YAML
name: offline-release
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
package-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Prepare local worktree
|
|
env:
|
|
MAIBOT_REPO_SHA: ${{ gitea.sha }}
|
|
MAIBOT_REPO_REF: ${{ gitea.ref }}
|
|
MAIBOT_REPOSITORY: ${{ gitea.repository }}
|
|
MAIBOT_SERVER_URL: ${{ gitea.server_url }}
|
|
MAIBOT_REPO_URL: ${{ vars.MAIBOT_REPO_URL }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
worktree_root=/tmp/maibot-actions
|
|
worktree="${worktree_root}/${MAIBOT_REPO_SHA}"
|
|
|
|
rm -rf "$worktree"
|
|
mkdir -p "$worktree_root"
|
|
printf 'MAIBOT_WORKTREE=%s\n' "$worktree" >> "$GITHUB_ENV"
|
|
|
|
repo_url="${MAIBOT_REPO_URL:-${MAIBOT_SERVER_URL%/}/${MAIBOT_REPOSITORY}.git}"
|
|
auth_header="Authorization: token ${GITEA_TOKEN}"
|
|
|
|
echo "Resolving repository source: $repo_url"
|
|
git -c http.lowSpeedLimit=1 \
|
|
-c http.lowSpeedTime=30 \
|
|
-c http.extraHeader="$auth_header" \
|
|
ls-remote "$repo_url" "$MAIBOT_REPO_REF"
|
|
|
|
git init "$worktree"
|
|
git -C "$worktree" remote add origin "$repo_url"
|
|
git -C "$worktree" \
|
|
-c http.lowSpeedLimit=1 \
|
|
-c http.lowSpeedTime=30 \
|
|
-c http.extraHeader="$auth_header" \
|
|
fetch --depth=1 origin "$MAIBOT_REPO_SHA"
|
|
git -C "$worktree" checkout --force FETCH_HEAD
|
|
git -C "$worktree" clean -dffx
|
|
|
|
app_tag="$(git -C "$worktree" rev-parse --short=12 HEAD)"
|
|
printf 'APP_TAG=%s\n' "$app_tag" >> "$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
|