95 lines
3.1 KiB
YAML
95 lines
3.1 KiB
YAML
name: Build Windows EXE
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "**"
|
|
|
|
jobs:
|
|
build-windows:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y mingw-w64 cmake ninja-build curl jq
|
|
|
|
- name: Create MinGW toolchain
|
|
run: |
|
|
cat > mingw-toolchain.cmake <<'EOF'
|
|
set(CMAKE_SYSTEM_NAME Windows)
|
|
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
|
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
|
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
|
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
EOF
|
|
|
|
- name: Configure Windows release build
|
|
run: |
|
|
cmake -S . -B build-win -G Ninja \
|
|
-DCMAKE_TOOLCHAIN_FILE=mingw-toolchain.cmake \
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
|
|
- name: Build Windows executable
|
|
run: cmake --build build-win --parallel
|
|
|
|
- name: Prepare artifact
|
|
run: |
|
|
mkdir -p dist
|
|
cp build-win/bin/gitree.exe dist/Gitree-windows-x64.exe
|
|
|
|
- name: Upload Windows build
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: Gitree-windows-x64
|
|
path: dist/Gitree-windows-x64.exe
|
|
if-no-files-found: error
|
|
|
|
- name: Create prod release
|
|
if: ${{ gitea.ref_name == 'prod' }}
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
|
GITEA_SHA: ${{ gitea.sha }}
|
|
GITEA_RUN_NUMBER: ${{ gitea.run_number }}
|
|
run: |
|
|
if [ -z "$GITEA_TOKEN" ]; then
|
|
echo "The repository secret GITEA_TOKEN is required to publish prod releases."
|
|
exit 1
|
|
fi
|
|
|
|
short_sha="$(printf '%s' "$GITEA_SHA" | cut -c1-7)"
|
|
tag="prod-${GITEA_RUN_NUMBER}-${short_sha}"
|
|
api="${GITEA_SERVER_URL%/}/api/v1/repos/${GITEA_REPOSITORY}"
|
|
|
|
payload="$(jq -n \
|
|
--arg tag "$tag" \
|
|
--arg sha "$GITEA_SHA" \
|
|
--arg name "Gitree ${tag}" \
|
|
'{tag_name: $tag, target_commitish: $sha, name: $name, body: "Automated Windows release from the prod branch.", draft: false, prerelease: false}')"
|
|
|
|
release="$(curl --fail-with-body --silent --show-error \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
--data "$payload" \
|
|
"${api}/releases")"
|
|
release_id="$(printf '%s' "$release" | jq -er '.id')"
|
|
|
|
curl --fail-with-body --silent --show-error \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@dist/Gitree-windows-x64.exe" \
|
|
"${api}/releases/${release_id}/assets?name=Gitree-windows-x64.exe"
|