Compare commits
3 Commits
796a2b7712
...
4832838a0d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4832838a0d | ||
|
|
8f6152a382 | ||
|
|
add0a6758e |
@@ -13,13 +13,13 @@ on:
|
||||
|
||||
jobs:
|
||||
cross-build-windows:
|
||||
# Gitea act_runner 标签为 9950x;该工作流在 Linux Runner 中交叉编译 Windows x86_64 包。
|
||||
runs-on: 9950x
|
||||
# 使用可访问 GitHub 的 Gitea act_runner(runner-mihomo),可直接拉取 actions/checkout、actions/upload-artifact 等 GitHub Action。
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: fedora:latest
|
||||
|
||||
steps:
|
||||
- name: Configure Fedora TUNA mirror
|
||||
- name: Prepare action runtime
|
||||
run: |
|
||||
set -euo pipefail
|
||||
sed -e 's|^metalink=|#metalink=|g' \
|
||||
@@ -29,23 +29,10 @@ jobs:
|
||||
sed -i 's|^enabled=1|enabled=0|g' /etc/yum.repos.d/fedora-cisco-openh264.repo
|
||||
fi
|
||||
dnf makecache --refresh -y
|
||||
dnf install -y git nodejs
|
||||
|
||||
- name: Checkout
|
||||
run: |
|
||||
set -euo pipefail
|
||||
dnf install -y git rsync
|
||||
WORKDIR="$(pwd)"
|
||||
SRC_DIR="$(mktemp -d /tmp/chengnan-source.XXXXXX)"
|
||||
REPO_URL="${GITHUB_SERVER_URL:-https://git.luochen570.cn}/${GITHUB_REPOSITORY}.git"
|
||||
TOKEN="${GITHUB_TOKEN:-}"
|
||||
if [ -n "$TOKEN" ]; then
|
||||
git -c http.extraHeader="Authorization: token ${TOKEN}" \
|
||||
clone --depth 1 --branch "${GITHUB_REF_NAME:-main}" "$REPO_URL" "$SRC_DIR"
|
||||
else
|
||||
git clone --depth 1 --branch "${GITHUB_REF_NAME:-main}" "$REPO_URL" "$SRC_DIR"
|
||||
fi
|
||||
rsync -a --delete "$SRC_DIR/" "$WORKDIR/"
|
||||
rm -rf "$SRC_DIR"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install cross build dependencies
|
||||
run: |
|
||||
@@ -56,6 +43,7 @@ jobs:
|
||||
ninja-build \
|
||||
p7zip \
|
||||
p7zip-plugins \
|
||||
python3 \
|
||||
mingw64-gcc-c++ \
|
||||
mingw64-qt6-qtbase \
|
||||
mingw64-opencv
|
||||
@@ -121,64 +109,111 @@ jobs:
|
||||
(cd dist-windows-cross && 7z a -tzip "${PACKAGE_NAME}.zip" "${PACKAGE_NAME}" >/dev/null)
|
||||
(cd dist-windows-cross && sha256sum "${PACKAGE_NAME}.zip" > "${PACKAGE_NAME}.zip.sha256")
|
||||
|
||||
# 当前 Gitea 上传入口约 60 秒会返回 502;大文件按 15 MiB 分片上传。
|
||||
ZIP="dist-windows-cross/${PACKAGE_NAME}.zip"
|
||||
split -b 15M -d -a 3 "$ZIP" "${ZIP}.part-"
|
||||
(cd dist-windows-cross && sha256sum "${PACKAGE_NAME}.zip".part-* > "${PACKAGE_NAME}.zip.parts.sha256")
|
||||
du -h "$ZIP" "${ZIP}".part-*
|
||||
du -h "dist-windows-cross/${PACKAGE_NAME}.zip"
|
||||
|
||||
- name: Verify package
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test -s dist-windows-cross/chengnan-windows-x86_64-cross.zip
|
||||
test -s dist-windows-cross/chengnan-windows-x86_64-cross.zip.part-000
|
||||
test -s dist-windows-cross/chengnan-windows-x86_64-cross.zip.parts.sha256
|
||||
test -s dist-windows-cross/chengnan-windows-x86_64-cross.zip.sha256
|
||||
(cd dist-windows-cross && sha256sum -c chengnan-windows-x86_64-cross.zip.sha256)
|
||||
(cd dist-windows-cross && sha256sum -c chengnan-windows-x86_64-cross.zip.parts.sha256)
|
||||
7z l dist-windows-cross/chengnan-windows-x86_64-cross.zip | grep 'chengnan.exe'
|
||||
7z l dist-windows-cross/chengnan-windows-x86_64-cross.zip | grep 'platforms/'
|
||||
python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
limit = 20 * 1024 * 1024
|
||||
for part in Path('dist-windows-cross').glob('chengnan-windows-x86_64-cross.zip.part-*'):
|
||||
size = part.stat().st_size
|
||||
print(part.name, size)
|
||||
if size > limit:
|
||||
raise SystemExit(f'{part} is too large for the current Gitea upload path')
|
||||
PY
|
||||
|
||||
- name: Upload package to Gitea Packages
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: chengnan-windows-x86_64-cross
|
||||
path: |
|
||||
dist-windows-cross/chengnan-windows-x86_64-cross.zip
|
||||
dist-windows-cross/chengnan-windows-x86_64-cross.zip.sha256
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Upload package to repository release
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
env:
|
||||
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
||||
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
PACKAGE_NAME="chengnan-windows-x86_64-cross"
|
||||
VERSION="${GITHUB_SHA:-manual}"
|
||||
VERSION="${VERSION:0:10}"
|
||||
OWNER="${GITHUB_REPOSITORY%%/*}"
|
||||
API_BASE="${GITHUB_SERVER_URL:-https://git.luochen570.cn}/api/packages/${OWNER}/generic/chengnan/${VERSION}"
|
||||
TOKEN="${PACKAGE_TOKEN:-${GITHUB_TOKEN:-}}"
|
||||
SERVER_URL="${GITHUB_SERVER_URL:-https://git.luochen570.cn}"
|
||||
REPOSITORY="${GITHUB_REPOSITORY}"
|
||||
API_BASE="${SERVER_URL}/api/v1/repos/${REPOSITORY}"
|
||||
TOKEN="${RELEASE_TOKEN:-${GITHUB_TOKEN:-}}"
|
||||
test -n "$TOKEN"
|
||||
upload_file() {
|
||||
|
||||
if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
|
||||
TAG_NAME="${GITHUB_REF_NAME}"
|
||||
RELEASE_NAME="${GITHUB_REF_NAME}"
|
||||
PRERELEASE=false
|
||||
else
|
||||
TAG_NAME="build-${GITHUB_SHA:0:10}"
|
||||
RELEASE_NAME="chengnan ${GITHUB_SHA:0:10}"
|
||||
PRERELEASE=true
|
||||
fi
|
||||
|
||||
json_escape() {
|
||||
python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
|
||||
}
|
||||
|
||||
release_payload="$(printf '{"tag_name":%s,"target_commitish":%s,"name":%s,"body":%s,"draft":false,"prerelease":%s}' \
|
||||
"$(printf '%s' "$TAG_NAME" | json_escape)" \
|
||||
"$(printf '%s' "${GITHUB_SHA}" | json_escape)" \
|
||||
"$(printf '%s' "$RELEASE_NAME" | json_escape)" \
|
||||
"$(printf 'Automated Windows x86_64 cross build from Gitea Actions.\n' | json_escape)" \
|
||||
"$PRERELEASE")"
|
||||
|
||||
status="$(curl --show-error --silent --location \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data "$release_payload" \
|
||||
--write-out '%{http_code}' \
|
||||
--output /tmp/gitea-release-response.json \
|
||||
"${API_BASE}/releases")"
|
||||
|
||||
if [ "$status" = "409" ] || [ "$status" = "422" ]; then
|
||||
RELEASE_ID="$(curl --show-error --silent --location \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
"${API_BASE}/releases/tags/${TAG_NAME}" \
|
||||
| python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')"
|
||||
elif [ "$status" = "201" ] || [ "$status" = "200" ]; then
|
||||
RELEASE_ID="$(python3 -c 'import json,sys; print(json.load(open("/tmp/gitea-release-response.json"))["id"])')"
|
||||
else
|
||||
echo "Create release failed with HTTP ${status}" >&2
|
||||
cat /tmp/gitea-release-response.json >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upload_asset() {
|
||||
local src="$1"
|
||||
local url="$2"
|
||||
local name
|
||||
local existing_id
|
||||
local status
|
||||
name="$(basename "$src")"
|
||||
existing_id="$(curl --show-error --silent --location \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets" \
|
||||
| ASSET_NAME="$name" python3 -c 'import json,os,sys; assets=json.load(sys.stdin); print(next((str(a["id"]) for a in assets if a.get("name")==os.environ["ASSET_NAME"]), ""))')"
|
||||
if [ -n "$existing_id" ]; then
|
||||
curl --show-error --silent --location \
|
||||
--request DELETE \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--output /tmp/gitea-release-asset-delete-response.json \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets/${existing_id}"
|
||||
fi
|
||||
status="$(curl --show-error --silent --location \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$src" \
|
||||
--form "attachment=@${src};filename=${name}" \
|
||||
--write-out '%{http_code}' \
|
||||
--output /tmp/gitea-upload-response.txt \
|
||||
"$url")"
|
||||
--output /tmp/gitea-release-asset-response.json \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets?name=${name}")"
|
||||
if [ "$status" != "201" ] && [ "$status" != "200" ]; then
|
||||
echo "Upload failed with HTTP ${status}: ${url}" >&2
|
||||
cat /tmp/gitea-upload-response.txt >&2
|
||||
echo "Upload release asset failed with HTTP ${status}: ${name}" >&2
|
||||
cat /tmp/gitea-release-asset-response.json >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
for part in dist-windows-cross/${PACKAGE_NAME}.zip.part-*; do
|
||||
upload_file "$part" "${API_BASE}/$(basename "$part")"
|
||||
done
|
||||
upload_file "dist-windows-cross/${PACKAGE_NAME}.zip.sha256" "${API_BASE}/${PACKAGE_NAME}.zip.sha256"
|
||||
upload_file "dist-windows-cross/${PACKAGE_NAME}.zip.parts.sha256" "${API_BASE}/${PACKAGE_NAME}.zip.parts.sha256"
|
||||
echo "Package uploaded to: ${API_BASE}/"
|
||||
echo "Download all ${PACKAGE_NAME}.zip.part-* files, then reconstruct with: cat ${PACKAGE_NAME}.zip.part-* > ${PACKAGE_NAME}.zip"
|
||||
|
||||
upload_asset "dist-windows-cross/${PACKAGE_NAME}.zip"
|
||||
upload_asset "dist-windows-cross/${PACKAGE_NAME}.zip.sha256"
|
||||
echo "Release assets uploaded to ${SERVER_URL}/${REPOSITORY}/releases/tag/${TAG_NAME}"
|
||||
|
||||
Reference in New Issue
Block a user