128 lines
3.9 KiB
YAML
128 lines
3.9 KiB
YAML
name: test-build-release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
env:
|
|
GIT_SSH_COMMAND: ssh -o StrictHostKeyChecking=no
|
|
run: |
|
|
git clone --depth 1 ssh://git@jianfgit.xyz:220/jianf/TrulyMEM-TrueHumanMEM.git ./
|
|
|
|
- name: Verify workspace and Python
|
|
run: |
|
|
pwd
|
|
ls -la
|
|
python3 --version
|
|
|
|
- name: Run tests
|
|
run: |
|
|
python3 -m venv .venv-ci
|
|
. .venv-ci/bin/activate
|
|
pip install --upgrade pip
|
|
pip install -r requirements.txt pytest
|
|
pytest -q
|
|
|
|
build-linux:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
env:
|
|
GIT_SSH_COMMAND: ssh -o StrictHostKeyChecking=no
|
|
run: |
|
|
git clone --depth 1 ssh://git@jianfgit.xyz:220/jianf/TrulyMEM-TrueHumanMEM.git ./
|
|
|
|
- name: Verify build environment
|
|
run: |
|
|
pwd
|
|
python3 --version
|
|
tar --version | head -1
|
|
|
|
- name: Build Linux binary
|
|
run: |
|
|
bash build/build_linux.sh
|
|
|
|
- name: Pack release bundle
|
|
run: |
|
|
mkdir -p dist/release
|
|
cp dist/TrulyMEM dist/release/
|
|
cp dist/TrulyMEM.desktop dist/release/
|
|
[ -f pic/image.png ] && cp pic/image.png dist/release/ || true
|
|
tar -C dist/release -czf dist/TrulyMEM-linux-amd64.tar.gz .
|
|
ls -lh dist/TrulyMEM-linux-amd64.tar.gz
|
|
|
|
- name: Build AppImage if preinstalled
|
|
run: |
|
|
if command -v appimagetool >/dev/null 2>&1; then
|
|
bash build/build_appimage.sh
|
|
else
|
|
echo "appimagetool not found on runner, skip AppImage build"
|
|
fi
|
|
|
|
- name: Show build outputs
|
|
run: |
|
|
ls -lah dist/
|
|
|
|
- name: Create Gitea release
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
env:
|
|
GITEA_TOKEN: ${{ vars.GITEA_RELEASE_TOKEN }}
|
|
TAG_NAME: ${{ github.ref_name }}
|
|
REPO: ${{ github.repository }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
run: |
|
|
test -n "$GITEA_TOKEN"
|
|
|
|
# Build release payload via env var — avoids heredoc in YAML
|
|
export TAG_NAME
|
|
release_payload=$(python3 -c 'import os,json; t=os.environ["TAG_NAME"]; print(json.dumps({"tag_name":t,"name":t,"draft":false,"prerelease":false}))')
|
|
|
|
release_response=$(curl -fsSL \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-X POST \
|
|
"$SERVER_URL/api/v1/repos/$REPO/releases" \
|
|
-d "$release_payload" \
|
|
|| true)
|
|
|
|
# Extract release id or fallback to existing
|
|
export RELEASE_RESPONSE
|
|
release_id=$(python3 -c '
|
|
import os, json
|
|
raw = os.environ.get("RELEASE_RESPONSE", "").strip()
|
|
if raw:
|
|
try:
|
|
print(json.loads(raw)["id"])
|
|
except Exception:
|
|
pass
|
|
')
|
|
|
|
if [ -z "$release_id" ]; then
|
|
release_id=$(curl -fsSL \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
"$SERVER_URL/api/v1/repos/$REPO/releases/tags/$TAG_NAME" \
|
|
| python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])' \
|
|
2>/dev/null || true)
|
|
fi
|
|
|
|
for file in dist/TrulyMEM dist/TrulyMEM.desktop dist/TrulyMEM-linux-amd64.tar.gz dist/TrulyMEM.AppImage; do
|
|
if [ -f "$file" ]; then
|
|
name=$(basename "$file")
|
|
curl -fsSL \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @"$file" \
|
|
"$SERVER_URL/api/v1/repos/$REPO/releases/$release_id/assets?name=$name"
|
|
fi
|
|
done
|