- Fail early with clear message when GITLAB_TOKEN is unset - Capture HTTP status code instead of relying on curl -f - Handle 404 by creating the wiki page if it doesn't exist yet - Print API response body on unexpected errors for easier debugging Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
140 lines
5.8 KiB
YAML
140 lines
5.8 KiB
YAML
stages:
|
|
- build
|
|
- wiki
|
|
|
|
# ── Linux native build ─────────────────────────────────────────────────────────
|
|
build-linux:
|
|
stage: build
|
|
image: ubuntu:24.04
|
|
variables:
|
|
QT_VERSION: "6.10.1"
|
|
QT_INSTALL_DIR: "/opt/qt"
|
|
before_script:
|
|
- apt-get update -qq
|
|
- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends
|
|
python3 python3-pip cmake ninja-build pkg-config git
|
|
build-essential libgl1-mesa-dev
|
|
libuchardet-dev
|
|
libquazip1-qt6-dev libminizip-dev
|
|
libdjvulibre-dev libwpd-dev
|
|
- pip3 install --quiet --break-system-packages aqtinstall
|
|
# Qt6 for Linux — provides headers, libs, and host tools
|
|
- aqt install-qt linux desktop ${QT_VERSION} linux_gcc_64
|
|
--outputdir ${QT_INSTALL_DIR}
|
|
script:
|
|
- QT_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64"
|
|
- cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release
|
|
-DCMAKE_PREFIX_PATH="${QT_DIR}"
|
|
- cmake --build build-linux --target asteria-qt
|
|
artifacts:
|
|
name: "asteria-qt-linux-${CI_COMMIT_SHORT_SHA}"
|
|
paths:
|
|
- build-linux/asteria-qt
|
|
expire_in: 1 day
|
|
when: on_success
|
|
|
|
# ── Windows cross-compile build (MinGW-w64 + aqtinstall) ──────────────────────
|
|
build-windows:
|
|
stage: build
|
|
image: ubuntu:24.04
|
|
variables:
|
|
QT_VERSION: "6.10.1"
|
|
QT_INSTALL_DIR: "/opt/qt"
|
|
SYSROOT: "/opt/mingw-sysroot"
|
|
before_script:
|
|
- apt-get update -qq
|
|
- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends
|
|
python3 python3-pip cmake ninja-build pkg-config git
|
|
gcc g++ mingw-w64
|
|
- pip3 install --quiet --break-system-packages aqtinstall
|
|
# Qt6 for Windows (MinGW 64-bit) — provides headers, import libs, and DLLs
|
|
- aqt install-qt linux desktop ${QT_VERSION} win64_mingw
|
|
--outputdir ${QT_INSTALL_DIR}
|
|
# Qt6 host tools (moc, rcc, qmlimportscanner …) must run on Linux
|
|
- aqt install-qt linux desktop ${QT_VERSION} linux_gcc_64
|
|
--outputdir ${QT_INSTALL_DIR}
|
|
# Build uchardet for MinGW from source
|
|
- git clone --depth 1 https://github.com/freedesktop/uchardet.git /tmp/uchardet
|
|
- cmake -B /tmp/uchardet-build /tmp/uchardet -G Ninja
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
-DCMAKE_TOOLCHAIN_FILE=${CI_PROJECT_DIR}/scripts/mingw-w64-toolchain.cmake
|
|
-DCMAKE_INSTALL_PREFIX=${SYSROOT}
|
|
-DBUILD_SHARED_LIBS=OFF
|
|
- cmake --build /tmp/uchardet-build
|
|
- cmake --install /tmp/uchardet-build
|
|
script:
|
|
- QT_WIN_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/mingw_64"
|
|
- QT_HOST_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64"
|
|
- cmake -B build-windows -G Ninja
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
-DCMAKE_TOOLCHAIN_FILE=${CI_PROJECT_DIR}/scripts/mingw-w64-toolchain.cmake
|
|
-DCMAKE_PREFIX_PATH="${QT_WIN_DIR};${SYSROOT}"
|
|
-DCMAKE_FIND_ROOT_PATH="${QT_WIN_DIR};${SYSROOT}"
|
|
-DQT_HOST_PATH="${QT_HOST_DIR}"
|
|
- cmake --build build-windows --target asteria-qt
|
|
artifacts:
|
|
name: "asteria-qt-windows-${CI_COMMIT_SHORT_SHA}"
|
|
paths:
|
|
- build-windows/asteria-qt.exe
|
|
expire_in: 1 day
|
|
when: on_success
|
|
|
|
# ── Update wiki with latest dev build links ────────────────────────────────────
|
|
update-wiki:
|
|
stage: wiki
|
|
image: alpine:latest
|
|
needs:
|
|
- build-linux
|
|
- build-windows
|
|
before_script:
|
|
- apk add --no-cache curl jq
|
|
script:
|
|
- |
|
|
if [ -z "${GITLAB_TOKEN}" ]; then
|
|
echo "ERROR: GITLAB_TOKEN CI/CD variable is not set"
|
|
exit 1
|
|
fi
|
|
- PROJECT_URL="https://gitlab.com/asteria-bookreader/asteria-qt"
|
|
- API_URL="https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}"
|
|
- ARTIFACTS_URL="${PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw"
|
|
- LINUX_URL="${ARTIFACTS_URL}/build-linux/asteria-qt?job=build-linux"
|
|
- WINDOWS_URL="${ARTIFACTS_URL}/build-windows/asteria-qt.exe?job=build-windows"
|
|
- |
|
|
HTTP_CODE=$(curl -s -o /tmp/wiki.json -w '%{http_code}' \
|
|
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
|
"${API_URL}/wikis/Asteria")
|
|
|
|
NEW_SECTION=$(printf '## Latest dev builds\n\n> Updated automatically by pipeline [#%s](%s) from `%s` @ %s\n\n| Platform | Download |\n|----------|----------|\n| Linux (x86_64) | [asteria-qt](%s) |\n| Windows (x86_64) | [asteria-qt.exe](%s) |' \
|
|
"${CI_PIPELINE_ID}" "${CI_PIPELINE_URL}" "${CI_COMMIT_REF_NAME}" "${CI_COMMIT_SHORT_SHA}" \
|
|
"${LINUX_URL}" "${WINDOWS_URL}")
|
|
|
|
if [ "${HTTP_CODE}" = "200" ]; then
|
|
WIKI_CONTENT=$(jq -r '.content' /tmp/wiki.json)
|
|
if printf '%s' "${WIKI_CONTENT}" | grep -q '^## Latest dev builds'; then
|
|
UPDATED=$(printf '%s' "${WIKI_CONTENT}" | awk -v new="${NEW_SECTION}" '
|
|
/^## Latest dev builds/ { found=1; printf "%s\n", new; next }
|
|
found && /^## / { found=0 }
|
|
!found { print }
|
|
')
|
|
else
|
|
UPDATED=$(printf '%s\n\n%s' "${WIKI_CONTENT}" "${NEW_SECTION}")
|
|
fi
|
|
curl -sf -X PUT \
|
|
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
|
--header "Content-Type: application/json" \
|
|
--data "$(jq -n --arg c "${UPDATED}" '{content:$c}')" \
|
|
"${API_URL}/wikis/Asteria"
|
|
elif [ "${HTTP_CODE}" = "404" ]; then
|
|
curl -sf -X POST \
|
|
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
|
--header "Content-Type: application/json" \
|
|
--data "$(jq -n --arg t "Asteria" --arg c "${NEW_SECTION}" '{title:$t,content:$c}')" \
|
|
"${API_URL}/wikis"
|
|
else
|
|
echo "ERROR: GitLab API returned HTTP ${HTTP_CODE}"
|
|
cat /tmp/wiki.json
|
|
exit 1
|
|
fi
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|