Skip to content

Commit

Permalink
[workflows]:优化安装依赖时的重复代码;
Browse files Browse the repository at this point in the history
  • Loading branch information
RealChuan committed May 6, 2024
1 parent b733105 commit a52f020
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 270 deletions.
108 changes: 108 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: 'Install Dependencies'
description: 'Install vcpkg libraries and qt environment'
inputs:
os_name:
description: 'os name'
required: true
type: string
vcpkg_libs:
description: 'vcpkg libraries'
required: false
default: 'breakpad crashpad'
type: string
qt_modules:
description: 'qt modules'
required: false
default: 'qt5compat qtnetworkauth qtimageformats'
type: string
qt_ver:
description: 'qt version'
required: false
default: '6.7.0'
type: string

runs:
using: 'composite'

steps:
- name: Install vcpkg on macos
if: startsWith(runner.os, 'macOS')
shell: bash
run: |
sudo chmod +x install-vcpkg.sh
sudo ./install-vcpkg.sh
working-directory: ./scripts/macos

- name: Update vcpkg
shell: bash
run: |
cd "$VCPKG_INSTALLATION_ROOT"
git reset --hard
git pull --quiet
- name: Delete vcpkg.json
shell: bash
run: |
rm vcpkg.json
- name: Cache windows vcpkg
if: startsWith(runner.os, 'Windows')
uses: actions/cache@v4
with:
path: C:\vcpkg\installed
key: ${{ inputs.os_name }}-vcpkg-installed-${{ runner.os }}-${{ github.sha }}
restore-keys: |
${{ inputs.os_name }}-vcpkg-installed-${{ runner.os_name }}-
${{ inputs.os_name }}-vcpkg-installed-
${{ inputs.os_name }}-
save-always: true

- name: Cache macos or linux vcpkg
if: startsWith(runner.os, 'macOS') || startsWith(runner.os, 'Linux')
uses: actions/cache@v4
with:
path: /usr/local/share/vcpkg/installed
key: ${{ inputs.os_name }}-vcpkg-installed-${{ runner.os }}-${{ github.sha }}
restore-keys: |
${{ inputs.os_name }}-vcpkg-installed-${{ runner.os_name }}-
${{ inputs.os_name }}-vcpkg-installed-
${{ inputs.os_name }}-
save-always: true

- name: Install dependencies on windows
if: startsWith(runner.os, 'Windows')
shell: bash
run: |
choco install ninja
ninja --version
cmake --version
vcpkg install ${{ inputs.vcpkg_libs }} --triplet x64-windows || (cat C:/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install dependencies on macos
if: startsWith(runner.os, 'macOS')
shell: bash
run: |
brew install ninja pkg-config python-setuptools
ninja --version
cmake --version
clang --version
vcpkg install ${{ inputs.vcpkg_libs }} --triplet x64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
vcpkg install ${{ inputs.vcpkg_libs }} --triplet arm64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install dependencies on linux
if: startsWith(runner.os, 'Linux')
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev clang
ninja --version
cmake --version
gcc --version
vcpkg install ${{ inputs.vcpkg_libs }} --triplet x64-linux || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ inputs.qt_ver }}
modules: ${{ inputs.qt_modules }}
cache: 'true'
93 changes: 7 additions & 86 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ on:
- 'LICENSE'
- 'README*'

env:
MACOSX_DEPLOYMENT_TARGET: 11.0

jobs:
build:
name: Build
env:
MACOSX_DEPLOYMENT_TARGET: 11.0
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -42,106 +43,26 @@ jobs:
- windows-latest
- macos-latest
- ubuntu-latest
qt_ver:
- 6.7.0
qt_modules:
- qt5compat qtserialport qtnetworkauth qtmultimedia qtimageformats
build_type:
- "RelWithDebInfo"
generators:
- "Ninja"
arch:
- x86_64
vcpkg_libs:
- breakpad crashpad
include:
- os: macos-latest
qt_ver: 6.7.0
qt_modules: qt5compat qtserialport qtnetworkauth qtmultimedia qtimageformats
build_type: "RelWithDebInfo"
generators: "Ninja"
arch: arm64
vcpkg_libs: breakpad crashpad

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install vcpkg on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
sudo chmod +x install-vcpkg.sh
sudo ./install-vcpkg.sh
working-directory: ./scripts/macos

# jurplel/install-qt-action@v3, 这个action会修改默认的python版本,
# 会导致部分使用vcpkg的库编译失败,比如libsystemd,所以需要删除vcpkg.json
- name: Delete vcpkg.json
shell: bash
run: |
rm vcpkg.json
- name: Cache windows vcpkg
if: startsWith(matrix.os, 'windows')
uses: actions/cache@v4
with:
path: C:\vcpkg\installed
key: ${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-
${{ runner.os }}-vcpkg-installed-
${{ runner.os }}-
save-always: true
- name: Cache macos or ubuntu vcpkg
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
uses: actions/cache@v4
with:
path: /usr/local/share/vcpkg/installed
key: ${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-
${{ runner.os }}-vcpkg-installed-
${{ runner.os }}-
save-always: true

- name: Install dependencies on windows
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
choco install ninja
ninja --version
cmake --version
vcpkg install ${{ matrix.vcpkg_libs }} --triplet x64-windows || (cat C:/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev clang
ninja --version
cmake --version
gcc --version
vcpkg install ${{ matrix.vcpkg_libs }} --triplet x64-linux || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install dependencies on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
brew install ninja pkg-config python-setuptools
ninja --version
cmake --version
clang --version
vcpkg install ${{ matrix.vcpkg_libs }} --triplet x64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
vcpkg install ${{ matrix.vcpkg_libs }} --triplet arm64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install Qt
uses: jurplel/install-qt-action@v3
fetch-depth: 1

- uses: ./.github/actions/install-dependencies
with:
version: ${{ matrix.qt_ver }}
install-deps: 'true'
modules: '${{ matrix.qt_modules }}'
cache: 'true'
os_name: ${{ matrix.os }}

- name: Configure msvc for amd64
if: startsWith(matrix.os, 'windows')
Expand Down
102 changes: 16 additions & 86 deletions .github/workflows/qmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ on:
- 'README*'
- 'vcpkg.json'

env:
MACOSX_DEPLOYMENT_TARGET: 11.0

jobs:
build:
name: Build
env:
MACOSX_DEPLOYMENT_TARGET: 11.0
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -44,98 +45,20 @@ jobs:
- windows-2019
- macos-latest
- ubuntu-latest
qt_ver:
- 6.7.0
qt_modules:
- qt5compat qtserialport qtnetworkauth qtmultimedia qtimageformats
arch:
- x86_64
vcpkg_libs:
- breakpad crashpad
include:
- os: macos-latest
qt_ver: 6.7.0
qt_modules: qt5compat qtserialport qtnetworkauth qtmultimedia qtimageformats
arch: arm64
vcpkg_libs: breakpad crashpad

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install vcpkg on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
sudo chmod +x install-vcpkg.sh
sudo ./install-vcpkg.sh
working-directory: ./scripts/macos

- name: Delete vcpkg.json
shell: bash
run: |
rm vcpkg.json
- name: Cache windows vcpkg
if: startsWith(matrix.os, 'windows')
uses: actions/cache@v4
with:
path: C:\vcpkg\installed
key: ${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-
${{ runner.os }}-vcpkg-installed-
${{ runner.os }}-
save-always: true
- name: Cache macos or ubuntu vcpkg
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
uses: actions/cache@v4
with:
path: /usr/local/share/vcpkg/installed
key: ${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-
${{ runner.os }}-vcpkg-installed-
${{ runner.os }}-
save-always: true
fetch-depth: 1

- name: Install dependencies on windows
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
choco install ninja
ninja --version
cmake --version
vcpkg install ${{ matrix.vcpkg_libs }} --triplet x64-windows || (cat C:/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev clang
ninja --version
cmake --version
gcc --version
vcpkg install ${{ matrix.vcpkg_libs }} --triplet x64-linux || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install dependencies on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
brew install ninja pkg-config python-setuptools
ninja --version
cmake --version
clang --version
vcpkg install ${{ matrix.vcpkg_libs }} --triplet x64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
vcpkg install ${{ matrix.vcpkg_libs }} --triplet arm64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1)
- name: Install Qt
uses: jurplel/install-qt-action@v3
- uses: ./.github/actions/install-dependencies
with:
version: ${{ matrix.qt_ver }}
install-deps: 'true'
modules: '${{ matrix.qt_modules }}'
cache: 'true'
os_name: ${{ matrix.os }}

- name: mkdir build
shell: bash
Expand All @@ -150,10 +73,17 @@ jobs:
qmake ./../.
nmake
working-directory: build
- name: build macos or ubuntu
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
- name: ubuntu-build
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
qmake ./../.
make -j $(nproc)
working-directory: build
- name: macos-build
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
qmake QMAKE_APPLE_DEVICE_ARCHS="${{ matrix.arch }}" ./../.
make -j4
make -j $(sysctl -n hw.ncpu)
working-directory: build
Loading

0 comments on commit a52f020

Please sign in to comment.