Skip to content

fix(ci): refactor args #129

fix(ci): refactor args

fix(ci): refactor args #129

Workflow file for this run

name: Build
on:
release:
types: [ published ]
push:
pull_request:
workflow_dispatch:
inputs:
nightly:
type: boolean
default: true
description: "Whether to build nightly version"
version:
type: string
default: v0.0.0
description: "Version to build (e.g. v0.0.0)"
env:
QT_VERSION: '6.8.1'
LINUX_OPENSSL_VERSION: '3.0.15'
TARGET_NAME: 'HITszConnectForWindows'
DISPLAY_NAME: 'HITsz Connect for Windows'
jobs:
build-windows-x64:
runs-on: windows-latest
env:
ARCHIVE_NAME: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}-windows-x64
steps:
- uses: actions/checkout@v4
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2022_64'
modules: 'qt5compat'
cache: 'true'
cache-key-prefix: 'install-qt-action'
- name: Configure
env:
NIGHTLY_BUILD: ${{ inputs.nightly || github.event_name != 'release' }}
RELEASE_VERSION: ${{ inputs.version || github.event.release.tag_name }}
run: |
mkdir build
if ( [bool]::Parse("${{ env.NIGHTLY_BUILD }}") ) {
cmake -DNIGHTLY_BUILD=ON -DGIT_HASH=$(git rev-parse --short=7 HEAD) -DCMAKE_BUILD_TYPE=Release -S . -B build
} else {
$VER = "${{ env.RELEASE_VERSION }}".substring(1)
cmake -DNIGHTLY_BUILD=OFF -DREL_VER=$VER -DCMAKE_BUILD_TYPE=Release -S . -B build
}
- name: Build
run: |
cmake --build build --target ${{ env.TARGET_NAME }} --parallel $(nproc)
- name: Download and copy files
env:
VCINSTALLDIR: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC'
run: |
mkdir "${{ env.DISPLAY_NAME }}"
cd "${{ env.DISPLAY_NAME }}"
cp ../build/Release/${{ env.TARGET_NAME }}.exe .
windeployqt.exe ${{ env.TARGET_NAME }}.exe
curl -LO https://github.com/Mythologyli/zju-connect/releases/latest/download/zju-connect-windows-amd64.zip
tar -xf zju-connect-windows-amd64.zip
rm zju-connect-windows-amd64.zip
cp ../libs/wintun/bin/amd64/wintun.dll .
cd ..
Compress-Archive -Path "${{ env.DISPLAY_NAME }}" -DestinationPath ${{ env.ARCHIVE_NAME }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.zip
build-windows-arm64:
runs-on: windows-latest
env:
ARCHIVE_NAME: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}-windows-arm64
steps:
- uses: actions/checkout@v4
- name: Install target Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2022_arm64_cross_compiled'
modules: 'qt5compat'
cache: 'true'
cache-key-prefix: 'install-qt-action'
- name: Install host Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2022_64'
modules: 'qt5compat'
cache: 'true'
cache-key-prefix: 'install-qt-action'
set-env: 'false'
- name: Set up cross-compilation environment
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64_arm64
- name: Configure
env:
NIGHTLY_BUILD: ${{ inputs.nightly || github.event_name != 'release' }}
RELEASE_VERSION: ${{ inputs.version || github.event.release.tag_name }}
QT_HOST_PATH: ${{ github.workspace }}\..\Qt\${{ env.QT_VERSION }}\msvc2022_64
EXTRA_CMAKE_ARGS:
run: |
mkdir build
if ( [bool]::Parse("${{ env.NIGHTLY_BUILD }}") ) {
cmake -DNIGHTLY_BUILD=ON -DGIT_HASH=$(git rev-parse --short=7 HEAD) -DCMAKE_BUILD_TYPE=Release \
-D QT_HOST_PATH="${{ env.QT_HOST_PATH }}" -A ARM64 \
-S . -B build
} else {
$VER = "${{ env.RELEASE_VERSION }}".substring(1)
cmake -DNIGHTLY_BUILD=OFF -DREL_VER=$VER -DCMAKE_BUILD_TYPE=Release \
-DQT_HOST_PATH="${{ env.QT_HOST_PATH }}" -A ARM64 \
-S . -B build
}
- name: Build
run: |
cmake --build build --target ${{ env.TARGET_NAME }} --parallel $(nproc)
- name: Download and copy files
env:
VCINSTALLDIR: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC'
run: |
mkdir "${{ env.DISPLAY_NAME }}"
cd "${{ env.DISPLAY_NAME }}"
cp ../build/Release/${{ env.TARGET_NAME }}.exe .
windeployqt.exe --qtpaths "$QT_DIR\bin\qtpaths.bat" ${{ env.TARGET_NAME }}.exe
curl -LO https://github.com/Mythologyli/zju-connect/releases/latest/download/zju-connect-windows-arm64.zip
tar -xf zju-connect-windows-arm64.zip
rm zju-connect-windows-arm64.zip
cp ../libs/wintun/bin/arm64/wintun.dll .
cd ..
Compress-Archive -Path "${{ env.DISPLAY_NAME }}" -DestinationPath ${{ env.ARCHIVE_NAME }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.zip
build-macos-x64:
runs-on: macos-13
env:
ARCHIVE_NAME: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}-macos-x64
steps:
- uses: actions/checkout@v4
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
host: 'mac'
target: 'desktop'
arch: 'clang_64'
modules: 'qt5compat'
cache: 'true'
cache-key-prefix: 'install-qt-action'
- name: Configure
env:
NIGHTLY_BUILD: ${{ inputs.nightly || github.event_name != 'release' }}
RELEASE_VERSION: ${{ inputs.version || github.event.release.tag_name }}
run: |
mkdir build
if ${{ env.NIGHTLY_BUILD }} ; then
cmake -DNIGHTLY_BUILD=ON -DGIT_HASH=$(git rev-parse --short=7 HEAD) -DCMAKE_OSX_ARCHITECTURES="x86_64" -S . -B build
else
VER=${{ env.RELEASE_VERSION }}
cmake -DNIGHTLY_BUILD=OFF -DREL_VER=${VER#v} -DCMAKE_OSX_ARCHITECTURES="x86_64" -S . -B build
fi
- name: Build
run: |
cmake --build build --target ${{ env.TARGET_NAME }} --parallel $(nproc)
- name: Download and copy files
run: |
cp -R build/${{ env.TARGET_NAME }}.app .
curl -LO https://github.com/Mythologyli/zju-connect/releases/latest/download/zju-connect-darwin-amd64.zip
tar -xf zju-connect-darwin-amd64.zip
rm zju-connect-darwin-amd64.zip
cp zju-connect ${{ env.TARGET_NAME }}.app/Contents/MacOS/
macdeployqt ${{ env.TARGET_NAME }}.app
- name: Package dmg file
run: |
brew install create-dmg
mkdir dmg-build
create-dmg \
--background ./resource/dmg-background.png \
--window-size 430 480 \
--app-drop-link 200 0 \
--add-file "${{ env.DISPLAY_NAME }}.app" "./${{ env.TARGET_NAME }}.app" 0 0 \
--add-file 修复脚本.command ./resource/macos-fix.sh 100 200 \
--filesystem APFS \
${{ env.ARCHIVE_NAME }}.dmg dmg-build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.dmg
build-macos-arm64:
runs-on: macos-13
env:
ARCHIVE_NAME: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}-macos-arm64
steps:
- uses: actions/checkout@v4
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
host: 'mac'
target: 'desktop'
arch: 'clang_64'
modules: 'qt5compat'
cache: 'true'
cache-key-prefix: 'install-qt-action'
- name: Configure
env:
NIGHTLY_BUILD: ${{ inputs.nightly || github.event_name != 'release' }}
RELEASE_VERSION: ${{ inputs.version || github.event.release.tag_name }}
run: |
mkdir build
if ${{ env.NIGHTLY_BUILD }} ; then
cmake -DNIGHTLY_BUILD=ON -DGIT_HASH=$(git rev-parse --short=7 HEAD) -DCMAKE_OSX_ARCHITECTURES="arm64" -S . -B build
else
VER=${{ env.RELEASE_VERSION }}
cmake -DNIGHTLY_BUILD=OFF -DREL_VER=${VER#v} -DCMAKE_OSX_ARCHITECTURES="arm64" -S . -B build
fi
- name: Build
run: |
cmake --build build --target ${{ env.TARGET_NAME }} --parallel $(nproc)
- name: Download and copy files
run: |
cp -R build/${{ env.TARGET_NAME }}.app .
curl -LO https://github.com/Mythologyli/zju-connect/releases/latest/download/zju-connect-darwin-arm64.zip
tar -xf zju-connect-darwin-arm64.zip
rm zju-connect-darwin-arm64.zip
cp zju-connect ${{ env.TARGET_NAME }}.app/Contents/MacOS/
macdeployqt ${{ env.TARGET_NAME }}.app
- name: Package dmg file
run: |
brew install create-dmg
mkdir dmg-build
create-dmg \
--background ./resource/dmg-background.png \
--window-size 430 480 \
--app-drop-link 200 0 \
--add-file "${{ env.DISPLAY_NAME }}.app" "./${{ env.TARGET_NAME }}.app" 0 0 \
--add-file 修复脚本.command ./resource/macos-fix.sh 100 200 \
--filesystem APFS \
${{ env.ARCHIVE_NAME }}.dmg dmg-build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.dmg
build-linux-x64:
runs-on: ubuntu-20.04
env:
ARCHIVE_NAME: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}-linux-x64
steps:
- uses: actions/checkout@v4
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
host: 'linux'
target: 'desktop'
arch: 'linux_gcc_64'
modules: 'qt5compat'
cache: 'true'
cache-key-prefix: 'install-qt-action'
- name: Configure
env:
NIGHTLY_BUILD: ${{ inputs.nightly || github.event_name != 'release' }}
RELEASE_VERSION: ${{ inputs.version || github.event.release.tag_name }}
run: |
mkdir build
if ${{ env.NIGHTLY_BUILD }} ; then
cmake -DNIGHTLY_BUILD=ON -DGIT_HASH=$(git rev-parse --short=7 HEAD) -S . -B build
else
VER=${{ env.RELEASE_VERSION }}
cmake -DNIGHTLY_BUILD=OFF -DREL_VER=${VER#v} -S . -B build
fi
- name: Build
run: |
cmake --build build --target ${{ env.TARGET_NAME }} --parallel $(nproc)
- name: Restore cached openssl
id: cache-openssl
uses: actions/cache@v4
with:
path: openssl
key: ${{ runner.os }}-${{ runner.arch }}-openssl-${{ env.LINUX_OPENSSL_VERSION }}
- name: Build openssl
if: steps.cache-openssl.outputs.cache-hit != 'true'
run: |
# For package in Ubuntu 20.04, we have to install openssl 3.
wget -O openssl.tar.gz https://www.openssl.org/source/openssl-${{ env.LINUX_OPENSSL_VERSION }}.tar.gz
tar -zxf openssl.tar.gz
cd openssl-${{ env.LINUX_OPENSSL_VERSION }}/
./config --prefix=${GITHUB_WORKSPACE}/openssl
make -j$(nproc)
sudo make install
openssl version
- name: Download and copy files
run: |
sudo cp -R ${GITHUB_WORKSPACE}/openssl /usr/local/
echo '/usr/local/openssl/lib64' | sudo tee /etc/ld.so.conf.d/openssl.conf > /dev/null
sudo ldconfig
sudo apt install -y libxcb-cursor0 fuse
wget -O linuxdeploy https://github.com/linuxdeploy/linuxdeploy/releases/download/2.0.0-alpha-1-20241106/linuxdeploy-x86_64.AppImage
wget -O linuxdeploy-plugin-qt https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/2.0.0-alpha-1-20241106/linuxdeploy-plugin-qt-x86_64.AppImage
chmod a+x linuxdeploy linuxdeploy-plugin-qt
mkdir AppDir
mkdir -p AppDir/usr/bin AppDir/usr/lib AppDir/usr/share/applications AppDir/usr/share/icons/hicolor/scalable/apps
cp build/${{ env.TARGET_NAME }} AppDir/usr/bin/
wget -O zju-connect-linux-amd64.zip https://github.com/Mythologyli/zju-connect/releases/latest/download/zju-connect-linux-amd64.zip
unzip zju-connect-linux-amd64.zip
cp zju-connect AppDir/usr/bin/
cp resource/icon.png AppDir/usr/share/icons/hicolor/scalable/apps/${{ env.TARGET_NAME }}.png
cat <<EOF > AppDir/usr/share/applications/${{ env.TARGET_NAME }}.desktop
[Desktop Entry]
Name=${{ env.DISPLAY_NAME }}
Exec=${{ env.TARGET_NAME }}
Icon=${{ env.TARGET_NAME }}
Type=Application
Categories=Network;Security;
EOF
cp /usr/local/openssl/lib64/libssl.so.3 AppDir/usr/lib/
cp /usr/local/openssl/lib64/libcrypto.so.3 AppDir/usr/lib/
./linuxdeploy --appdir AppDir --output appimage --plugin qt
mv *.AppImage ${{ env.ARCHIVE_NAME }}.AppImage
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.AppImage
release:
runs-on: ubuntu-latest
if: github.event_name == 'release'
needs:
- build-windows-x64
- build-windows-arm64
- build-macos-x64
- build-macos-arm64
- build-linux-x64
env:
ARCHIVE_PREFIX: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ env.ARCHIVE_PREFIX }}-*
merge-multiple: true
- name: Upload to release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ github.event.release.tag_name }} ${{ env.ARCHIVE_PREFIX }}-*