# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # A reusable workflow to build and test Packager on every supported OS and # architecture. name: Build # Runs when called from another workflow. on: workflow_call: inputs: ref: required: true type: string secrets: # The GITHUB_TOKEN name is reserved, but not passed through implicitly. # So we call our secret parameter simply TOKEN. TOKEN: required: false # These below are not actual secrets, but secrets are the only place to # keep repo-specific configs that make this project friendlier to forks # and easier to debug. # If non-empty, start a debug SSH server on failures. ENABLE_DEBUG: required: false # If non-empty, enable self-hosted runners in the build matrix. ENABLE_SELF_HOSTED: required: false # By default, run all commands in a bash shell. On Windows, the default would # otherwise be powershell. defaults: run: shell: bash jobs: # Configure the build matrix based on inputs. The list of objects in the # build matrix contents can't be changed by conditionals, but it can be # computed by another job and deserialized. This uses # secrets.ENABLE_SELF_HOSTED to determine the build matrix, based on the # metadata in build-matrix.json. matrix_config: runs-on: ubuntu-latest outputs: INCLUDE: ${{ steps.configure.outputs.INCLUDE }} OS: ${{ steps.configure.outputs.OS }} ENABLE_DEBUG: ${{ steps.configure.outputs.ENABLE_DEBUG }} steps: - uses: actions/checkout@v2 with: ref: ${{ inputs.ref }} - name: Configure Build Matrix id: configure shell: node {0} run: | const enableDebug = "${{ secrets.ENABLE_DEBUG }}" != ''; const enableSelfHosted = "${{ secrets.ENABLE_SELF_HOSTED }}" != ''; // Use ENABLE_SELF_HOSTED to decide what the build matrix below // should include. const {hosted, selfHosted} = require("${{ github.workspace }}/.github/workflows/build-matrix.json"); const include = enableSelfHosted ? hosted.concat(selfHosted) : hosted; const os = include.map((config) => config.os); // Output JSON objects consumed by the build matrix below. console.log(`::set-output name=INCLUDE::${ JSON.stringify(include) }`); console.log(`::set-output name=OS::${ JSON.stringify(os) }`); // Output the debug flag directly. console.log(`::set-output name=ENABLE_DEBUG::${ enableDebug }`); // Log the outputs, for the sake of debugging this script. console.log({enableDebug, include, os}); build: needs: matrix_config strategy: fail-fast: false matrix: include: ${{ fromJSON(needs.matrix_config.outputs.INCLUDE) }} os: ${{ fromJSON(needs.matrix_config.outputs.OS) }} build_type: ["Debug", "Release"] lib_type: ["static", "shared"] name: ${{ matrix.os_name }} ${{ matrix.target_arch }} ${{ matrix.build_type }} ${{ matrix.lib_type }} runs-on: ${{ matrix.os }} steps: - name: Configure git to preserve line endings # Otherwise, tests fail on Windows because "golden" test outputs will not # have the correct line endings. run: git config --global core.autocrlf false - name: Checkout code uses: actions/checkout@v2 with: ref: ${{ inputs.ref }} submodules: true - name: Install Linux deps if: runner.os == 'Linux' run: sudo apt install -y libc-ares-dev - name: Generate build files run: | mkdir -p build/ if [[ "${{ matrix.lib_type }}" == "shared" ]]; then LIBPACKAGER_SHARED="ON" else LIBPACKAGER_SHARED="OFF" fi cmake \ -DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" \ -DLIBPACKAGER_SHARED="$LIBPACKAGER_SHARED" \ -S . \ -B build/ - name: Build # This is a universal build command, which will call make on Linux and # Visual Studio on Windows. Note that the VS generator is what cmake # calls a "multi-configuration" generator, and so the desired build # type must be specified for Windows. run: cmake --build build/ --config "${{ matrix.build_type }}" - name: Test run: cd build; ctest -C "${{ matrix.build_type }}" -V # TODO(joeyparrish): Prepare artifacts when build system is complete again # - name: Prepare artifacts (static release only) # run: | # BUILD_CONFIG="${{ matrix.build_type }}-${{ matrix.lib_type }}" # if [[ "$BUILD_CONFIG" != "Release-static" ]]; then # echo "Skipping artifacts for $BUILD_CONFIG." # exit 0 # fi # if [[ "${{ runner.os }}" == "Linux" ]]; then # echo "::group::Check for static executables" # ( # cd build/Release # # Prove that we built static executables on Linux. First, check that # # the executables exist, and fail if they do not. Then check "ldd", # # which will fail if the executable is not dynamically linked. If # # "ldd" succeeds, we fail the workflow. Finally, we call "true" so # # that the last executed statement will be a success, and the step # # won't be failed if we get that far. # ls packager mpd_generator >/dev/null || exit 1 # ldd packager 2>&1 && exit 1 # ldd mpd_generator 2>&1 && exit 1 # true # ) # echo "::endgroup::" # fi # echo "::group::Prepare artifacts folder" # mkdir artifacts # ARTIFACTS="$GITHUB_WORKSPACE/artifacts" # cd build/Release # echo "::endgroup::" # echo "::group::Strip executables" # strip packager${{ matrix.exe_ext }} # strip mpd_generator${{ matrix.exe_ext }} # echo "::endgroup::" # SUFFIX="-${{ matrix.os_name }}-${{ matrix.target_arch }}" # EXE_SUFFIX="$SUFFIX${{ matrix.exe_ext}}" # echo "::group::Copy packager" # cp packager${{ matrix.exe_ext }} $ARTIFACTS/packager$EXE_SUFFIX # echo "::endgroup::" # echo "::group::Copy mpd_generator" # cp mpd_generator${{ matrix.exe_ext }} $ARTIFACTS/mpd_generator$EXE_SUFFIX # echo "::endgroup::" # # The pssh-box bundle is OS and architecture independent. So only do # # it on this one OS and architecture, and give it a more generic # # filename. # if [[ '${{ matrix.os_name }}' == 'linux' && '${{ matrix.target_arch }}' == 'x64' ]]; then # echo "::group::Tar pssh-box" # tar -czf $ARTIFACTS/pssh-box.py.tar.gz pyproto pssh-box.py # echo "::endgroup::" # fi # TODO(joeyparrish): Attach artifacts when build system is complete again # - name: Attach artifacts to release # if: matrix.build_type == 'Release' && matrix.lib_type == 'static' # uses: dwenegar/upload-release-assets@v1 # env: # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # with: # release_id: ${{ needs.draft_release.outputs.release_id }} # assets_path: artifacts - name: Debug uses: mxschmitt/action-tmate@v3.6 with: limit-access-to-actor: true if: failure() && needs.matrix_config.outputs.ENABLE_DEBUG != ''