From 782db0d11ff025cff0a20867f20d5bcb98975807 Mon Sep 17 00:00:00 2001 From: Eugene Kozlov Date: Thu, 5 Sep 2024 19:54:04 +0400 Subject: [PATCH] Add CI. --- .github/workflows/build.yml | 114 ++++++++++++++++++++++++++++++++++++ ci_build.sh | 63 ++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 ci_build.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cf956ba --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,114 @@ +name: Build +on: + # Build on commits pushed, except when explicitly skipped. + push: + branches-ignore: + - 'no-ci-**' + - 'skip-ci-**' + # Build on pull requests, except drafts. + pull_request: + # Build on a schedule to keep up with the engine changes. + schedule: + - cron: '0 0 * * 0' + +env: + # Common settings. + CMAKE_VERSION: 3.21.x + # Common paths. + ci_source_dir: ${{ github.workspace }}/source-code + ci_build_script: ./source-code/ci_build.sh + ci_build_dir: ${{ github.workspace }}/cmake-build + ci_native_sdk_dir: ${{ github.workspace }}/SDK-native + ci_target_sdk_dir: ${{ github.workspace }}/SDK-target + # Parameters for uploading binaries to GitHub + ci_latest_release_url: https://uploads.github.com/repos/rbfx/Core.SamplePlugin/releases/173685124/assets{?name,label} + ci_latest_release_id: 173685124 + +jobs: + CheckSkipCI: + runs-on: ubuntu-20.04 + if: | + !contains(github.event.head_commit.message, '[skip ci]') && + !contains(github.event.pull_request.title, '[skip ci]') && + !contains(github.event.head_commit.message, '[skip-ci]') && + !contains(github.event.pull_request.title, '[skip-ci]') + steps: + - run: exit 0 + + Windows: + if: github.event.pull_request.draft == false + runs-on: windows-2022 + needs: [CheckSkipCI] + + strategy: + fail-fast: false + + env: + ci_platform: windows + ci_target_sdk_name: rebelfork-sdk-Windows-msvc-rel-dll-x64-latest.zip + ci_upload_release: ${{ + (github.repository == 'rbfx/Core.SamplePlugin') && + (github.ref == 'refs/heads/ek/ci') + }} + + steps: + - name: Checkout Plugin + uses: actions/checkout@v3 + with: + path: ${{ env.ci_source_dir }} + fetch-depth: 1 + submodules: true + + - name: Download target SDK + uses: robinraju/release-downloader@v1.8 + with: + repository: rbfx/rbfx + tag: latest + fileName: ${{ env.ci_target_sdk_name }} + + - name: Unzip target SDK + run: | + cd ${{ github.workspace }} + unzip ${{ env.ci_target_sdk_name }} + mv ./SDK ./SDK-target + + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1 + with: + cmake-version: '${{ env.CMAKE_VERSION }}' + + - name: Dependencies + shell: bash + run: ${{ env.ci_build_script }} dependencies + + - name: Generate + shell: bash + run: ${{ env.ci_build_script }} generate + + - name: Build + shell: bash + run: ${{ env.ci_build_script }} build + + - name: Prepare binaries + if: ${{ env.ci_upload_release == 'true' }} + shell: bash + run: ${{ env.ci_build_script }} prepare + + - name: Zip binaries + if: ${{ env.ci_upload_release == 'true' }} + uses: TheDoctor0/zip-release@0.7.6 + with: + directory: ${{ env.ci_build_dir }}/upload/ + filename: ${{ github.workspace }}/upload.zip + path: '.' + + - name: Release binaries + if: ${{ env.ci_upload_release == 'true' }} + uses: WebFreak001/deploy-nightly@v3.0.0 + with: + upload_url: ${{ env.ci_latest_release_url }} + release_id: ${{ env.ci_latest_release_id }} + asset_path: ${{ github.workspace }}/upload.zip + asset_name: 'Core.SamplePlugin-${{ github.job }}-latest.zip' + asset_content_type: application/zip + max_releases: 1 diff --git a/ci_build.sh b/ci_build.sh new file mode 100644 index 0000000..e2dda05 --- /dev/null +++ b/ci_build.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# build.sh ... +# ci_platform: windows +# ci_action: dependencies|generate|build|install|test +# ci_source_dir: source code directory +# ci_build_dir: cmake cache directory +# ci_native_sdk_dir: native SDK (linux) installation directory +# ci_target_sdk_dir: target SDK (web) installation directory + +ci_action=$1; shift; +ci_source_dir=${ci_source_dir%/}; # remove trailing slash if any + +echo "ci_platform=$ci_platform" +echo "ci_action=$ci_action" +echo "ci_source_dir=$ci_source_dir" +echo "ci_build_dir=$ci_build_dir" +echo "ci_native_sdk_dir=$ci_native_sdk_dir" +echo "ci_target_sdk_dir=$ci_target_sdk_dir" + +declare -A build_config=( + [web]='Release' + [windows]='RelWithDebInfo' +) + +function action-dependencies() { + : +} + +function action-generate() { + local params=( + "-B" + "$ci_build_dir" + "-S" + "$ci_source_dir" + "-DREBELFORK_SDK=$ci_target_sdk_dir" + ) + + if [[ "$ci_platform" == "windows" ]]; then + params+=( + "-G" + "Visual Studio 17 2022" + "-A" + "x64" + "-DCMAKE_BUILD_TYPE=${build_config[$ci_platform]}" + ) + fi + + cmake "${params[@]}" +} + +function action-build() { + cmake --build $ci_build_dir --parallel $(nproc) --config ${build_config[$ci_platform]} +} + +function action-prepare() { + cd $ci_build_dir + ls + mkdir upload + cp *.dll *.lib *.exp *.pdb ./upload/ +} + +action-$ci_action