Move GitHub Actions CI scripts into separate files

Break the workflow into smaller stages (Configure, Build, Install,
Package, etc.) so that you can see exactly which stage failed in the
GitHub Actions run log.

Create a separate Bash CI script for each job stage (configure.sh,
build.sh, install.sh, package.sh, etc.) to reduce the size of the main
YAML workflow file and enable Bash syntax highlighting.

Close #917
This commit is contained in:
Peter Jonas 2021-06-10 16:52:24 +01:00 committed by Dmitry Vedenko
parent 3ebebbb360
commit 4b5c95d7fe
12 changed files with 257 additions and 201 deletions

View File

@ -1,92 +1,60 @@
#
# CMake based build for Audacity
#
name: CMake Build name: CMake Build
#
# Only execute on "git push" actions
#
on: on:
push: push:
# Remove the "#" from the next 2 lines if you need to disable this action
#branches:
# - disable
pull_request: pull_request:
# Remove the "#" from the next 2 lines if you need to disable this action
#branches:
# - disable
# defaults:
# Global environment variables run:
# shell: bash
env:
WXURL: https://github.com/audacity/wxWidgets
WXREF: audacity-fixes-3.1.3
WXWIN: ${{ github.workspace }}/wxwin
# As of 2021/01/01, github is using Xcode 12.2 as the default and
# it has a bug in the install_name_tool. So explicitly use 12.3
# instead.
DEVELOPER_DIR: /Applications/Xcode_12.3.app/Contents/Developer
CONAN_USER_HOME: "${{ github.workspace }}/conan-home/"
CONAN_USER_HOME_SHORT: "${{ github.workspace }}/conan-home/short"
#
# Define our job(s)
#
jobs: jobs:
build: build:
name: ${{ matrix.config.name }} name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }} runs-on: ${{ matrix.config.os }}
env:
AUDACITY_CMAKE_GENERATOR: ${{ matrix.config.generator }}
AUDACITY_ARCH_LABEL: ${{ matrix.config.arch }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
config: config:
- {
name: "Windows_32bit", - name: Ubuntu_18.04
os: windows-latest, os: ubuntu-18.04
generator: "Visual Studio 16 2019", arch: x86_64 # as reported by `arch` or `uname -m`
platform: "Win32" generator: Unix Makefiles
}
- { - name: macOS_Intel
name: "Windows_64bit", os: macos-latest
os: windows-latest, arch: Intel # as reported by Apple menu > About This Mac
generator: "Visual Studio 16 2019", generator: Xcode
platform: "x64"
} - name: Windows_32bit
- { os: windows-latest
name: "Ubuntu_18.04", arch: 32bit # as reported by Windows Settings > System > About
os: ubuntu-18.04, generator: Visual Studio 16 2019
generator: "Unix Makefiles"
} - name: Windows_64bit
- { os: windows-latest
name: "macOS", arch: 64bit # as reported by Windows Settings > System > About
os: macos-latest, generator: Visual Studio 16 2019
generator: "Xcode"
}
steps: steps:
# =========================================================================
# SHARED: Checkout source
# =========================================================================
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
# with:
# ref: master
# =========================================================================
# SHARED: Checkout source
# =========================================================================
- name: Calculate short hash
shell: bash
run: |
set -x
# Get the short hash
shorthash=$(git show -s --format='%h')
# Export the short hash for the upload step
echo "SHORTHASH=${shorthash}" >> ${GITHUB_ENV}
# Export the destination directory name
echo "DEST=${{matrix.config.name}}_${shorthash}" >> ${GITHUB_ENV}
- name: GitHub Action Cache for .conan - name: Dependencies
id: github-cache-conan run: |
exec bash "scripts/ci/dependencies.sh"
- name: Environment
run: |
source "scripts/ci/environment.sh"
- name: Cache for .conan
id: cache-conan
uses: actions/cache@v2 uses: actions/cache@v2
env: env:
cache-name: cache-conan-modules cache-name: cache-conan-modules
@ -95,146 +63,32 @@ jobs:
key: host-${{ matrix.config.name }}-${{ hashFiles('cmake-proxies/CMakeLists.txt') }} key: host-${{ matrix.config.name }}-${{ hashFiles('cmake-proxies/CMakeLists.txt') }}
restore-keys: | restore-keys: |
host-${{ matrix.config.name }}- host-${{ matrix.config.name }}-
- name: Check Sentry secrets
- name: Configure
env: env:
SENTRY_DSN_KEY: ${{ secrets.SENTRY_DSN_KEY }} SENTRY_DSN_KEY: ${{ secrets.SENTRY_DSN_KEY }}
SENTRY_HOST: ${{ secrets.SENTRY_HOST }} SENTRY_HOST: ${{ secrets.SENTRY_HOST }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
if: ${{ env.SENTRY_DSN_KEY != '' && env.SENTRY_HOST != '' && env.SENTRY_PROJECT != '' }}
shell: bash
run: | run: |
echo "SENTRY_PARAMETERS<<EOF" >> $GITHUB_ENV exec bash "scripts/ci/configure.sh"
echo "-DSENTRY_DSN_KEY=${SENTRY_DSN_KEY} -DSENTRY_HOST=${SENTRY_HOST} -DSENTRY_PROJECT=${SENTRY_PROJECT}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# ========================================================================= - name: Build
# WINDOWS: Build (for all versions of Windows)
# =========================================================================
- name: Build for Windows
if: startswith( matrix.config.os, 'windows' )
shell: bash
run: | run: |
set -x exec bash "scripts/ci/build.sh"
pip install conan
conan --version
# Configure Audacity - name: Install
#
cmake -S . \
-B build \
-G "${{matrix.config.generator}}" \
-A ${{matrix.config.platform}} \
-D audacity_use_pch=no \
-D audacity_has_networking=yes ${{ env.SENTRY_PARAMETERS }}
# Build Audacity
cmake --build build --config Release --verbose
# "Install" Audacity
mkdir -p "${DEST}"
cp -a build/bin/Release/* "${DEST}"
rm -f "${DEST}"/{*.iobj,*.ipdb}
# Create artifact (zipped as Github actions don't preserve permissions)
cmake -E tar c "${GITHUB_SHA}.zip" --format=zip "${DEST}"
# =========================================================================
# MACOS: Build (for all versions of MacOS)
# =========================================================================
- name: Build for macOS
if: startswith( matrix.config.os, 'macos' )
shell: bash
run: | run: |
set -x exec bash "scripts/ci/install.sh"
# Setup environment - name: Package
export PATH="/usr/local/bin:${PATH}"
export DYLD_LIBRARY_PATH="/usr/local/lib"
# Install required packages
brew install gettext
brew link --force gettext
brew install conan
conan --version
# Configure Audacity
cmake -S . \
-B build \
-T buildsystem=1 \
-G "${{matrix.config.generator}}" \
-D audacity_use_pch=no \
-D audacity_has_networking=yes ${{ env.SENTRY_PARAMETERS }}
# Build Audacity
cmake --build build --config Release
# "Install" Audacity
mkdir -p "${DEST}"
cp -a build/bin/Release/ "${DEST}"
# Create artifact (zipped as Github actions don't preserve permissions)
cmake -E tar c "${GITHUB_SHA}.zip" --format=zip "${DEST}"
# =========================================================================
# UBUNTU: Build (for all versions of Ubuntu)
# =========================================================================
- name: Build for Ubuntu
if: startswith( matrix.config.os, 'ubuntu' )
shell: bash
run: | run: |
set -x exec bash "scripts/ci/package.sh"
# Setup environment
export PATH="/usr/local/bin:${PATH}"
export LD_LIBRARY_PATH="/usr/local/lib"
# Install required packages
sudo apt-get update -y
sudo apt-get install -y libgtk2.0-dev libasound2-dev gettext python3-pip
sudo apt-get remove -y ccache
pip3 install wheel setuptools
pip3 install conan
conan --version
# Configure Audacity
cmake -S . \
-B build \
-G "${{matrix.config.generator}}" \
-D audacity_use_pch=no \
-D audacity_has_networking=yes ${{ env.SENTRY_PARAMETERS }}
# Build Audacity
cmake --build build --config Release
# "Install" Audacity
cmake --install build --config Release --prefix "${DEST}"
# Create the lib directory
mkdir -p ${DEST}/lib
# Create wrapper script
cat >"${DEST}/audacity" <<"EOF"
#!/bin/sh
lib="${0%/*}/lib/audacity"
export LD_LIBRARY_PATH="${lib}:${LD_LIBRARY_PATH}"
export AUDACITY_MODULES_PATH="${lib}/modules"
"${0%/*}/bin/audacity"
EOF
chmod +x "${DEST}/audacity"
# Create artifact (zipped as Github actions don't preserve permissions)
cmake -E tar c "${GITHUB_SHA}.zip" --format=zip "${DEST}"
# =========================================================================
# SHARED: Attach the artifact to the workflow results
# =========================================================================
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v2
with: with:
name: ${{ matrix.config.name }}_${{ env.SHORTHASH }} name: Audacity_${{ matrix.config.name }}_${{ github.run_id }}_${{ env.GIT_HASH_SHORT }}
path: ${{ github.sha }}.zip path: |
build/package/*
!build/package/_CPack_Packages
if-no-files-found: error

View File

@ -168,8 +168,12 @@ include( CMakePushCheckState )
include( GNUInstallDirs ) include( GNUInstallDirs )
include( TestBigEndian ) include( TestBigEndian )
set_from_env(SENTRY_DSN_KEY)
set_from_env(SENTRY_HOST)
set_from_env(SENTRY_PROJECT)
cmake_dependent_option( cmake_dependent_option(
${_OPT}has_sentry_reporting ${_OPT}has_sentry_reporting
"Build support for sending errors to Sentry" "Build support for sending errors to Sentry"
On On
"${_OPT}has_networking;DEFINED SENTRY_DSN_KEY;DEFINED SENTRY_HOST;DEFINED SENTRY_PROJECT" "${_OPT}has_networking;DEFINED SENTRY_DSN_KEY;DEFINED SENTRY_HOST;DEFINED SENTRY_PROJECT"
@ -525,3 +529,4 @@ execute_process( COMMAND
print_properties( TARGET "wxWidgets" ) print_properties( TARGET "wxWidgets" )
#]] #]]
include( Package ) # do this last

View File

@ -74,6 +74,15 @@ macro( set_cache_value var value )
set_property( CACHE ${var} PROPERTY VALUE "${value}" ) set_property( CACHE ${var} PROPERTY VALUE "${value}" )
endmacro() endmacro()
# Set a CMake variable to the value of the corresponding environment variable
# if the CMake variable is not already defined. Any addition arguments after
# the variable name are passed through to set().
macro( set_from_env var )
if( NOT DEFINED ${var} AND NOT "$ENV{${var}}" STREQUAL "" )
set( ${var} "$ENV{${var}}" ${ARGN} ) # pass additional args (e.g. CACHE)
endif()
endmacro()
# Set the given property and its config specific brethren to the same value # Set the given property and its config specific brethren to the same value
function( set_target_property_all target property value ) function( set_target_property_all target property value )
set_target_properties( "${target}" PROPERTIES "${property}" "${value}" ) set_target_properties( "${target}" PROPERTIES "${property}" "${value}" )

View File

@ -0,0 +1,25 @@
set(CPACK_PACKAGE_VERSION_MAJOR "${AUDACITY_VERSION}") # X
set(CPACK_PACKAGE_VERSION_MINOR "${AUDACITY_RELEASE}") # Y
set(CPACK_PACKAGE_VERSION_PATCH "${AUDACITY_REVISION}") # Z
# X.Y.Z-alpha-20210615
set(CPACK_PACKAGE_VERSION "${AUDACITY_VERSION}.${AUDACITY_RELEASE}.${AUDACITY_REVISION}${AUDACITY_SUFFIX}")
if(NOT AUDACITY_BUILD_LEVEL EQUAL 2)
# X.Y.Z-alpha-20210615+a1b2c3d
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}+${GIT_COMMIT_SHORT}")
endif()
# Audacity-X.Y.Z-alpha-20210615
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
if(NOT "$ENV{AUDACITY_ARCH_LABEL}" STREQUAL "")
# Audacity-X.Y.Z-alpha-20210615-x86_64
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-$ENV{AUDACITY_ARCH_LABEL}")
endif()
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/package")
set(CPACK_GENERATOR ZIP)
include(CPack) # do this last

8
linux/audacity.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
lib="${0%/*}/lib/audacity"
export LD_LIBRARY_PATH="${lib}:${LD_LIBRARY_PATH}"
export AUDACITY_MODULES_PATH="${lib}/modules"
exec "${0%/*}/bin/audacity" "$@"

22
scripts/ci/build.sh Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
((${BASH_VERSION%%.*} >= 4)) || { echo >&2 "$0: Error: Please upgrade Bash."; exit 1; }
set -euxo pipefail
if [[ "${OSTYPE}" == msys* ]]; then # Windows
cpus="${NUMBER_OF_PROCESSORS}"
elif [[ "${OSTYPE}" == darwin* ]]; then # macOS
cpus="$(sysctl -n hw.ncpu)"
else # Linux & others
cpus="$(nproc)"
fi
# Build Audacity
cmake --build build -j "${cpus}" --config "${AUDACITY_BUILD_TYPE}"

32
scripts/ci/configure.sh Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
((${BASH_VERSION%%.*} >= 4)) || { echo >&2 "$0: Error: Please upgrade Bash."; exit 1; }
set -euxo pipefail
conan --version # check it works
cmake_args=(
-S .
-B build
-G "${AUDACITY_CMAKE_GENERATOR}"
-D audacity_use_pch=no
-D audacity_has_networking=yes
-D CMAKE_BUILD_TYPE="${AUDACITY_BUILD_TYPE}"
-D CMAKE_INSTALL_PREFIX="${AUDACITY_INSTALL_PREFIX}"
)
if [[ "${AUDACITY_CMAKE_GENERATOR}" == "Visual Studio"* ]]; then
case "${AUDACITY_ARCH_LABEL}" in
32bit) cmake_args+=( -A Win32 ) ;;
64bit) cmake_args+=( -A x64 ) ;;
*) echo >&2 "$0: Unrecognised arch label '${AUDACITY_ARCH_LABEL}'" ; exit 1 ;;
esac
elif [[ "${AUDACITY_CMAKE_GENERATOR}" == Xcode* ]]; then
cmake_args+=(
-T buildsystem=1
)
fi
# Configure Audacity
cmake "${cmake_args[@]}"

49
scripts/ci/dependencies.sh Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
((${BASH_VERSION%%.*} >= 4)) || echo >&2 "$0: Warning: Using ancient Bash version ${BASH_VERSION}."
set -euxo pipefail
if [[ "${OSTYPE}" == msys* ]]; then # Windows
# Python packages
pip_packages=(
conan
)
pip3 install "${pip_packages[@]}"
elif [[ "${OSTYPE}" == darwin* ]]; then # macOS
# Homebrew packages
brew_packages=(
bash # macOS ships with Bash v3 for licensing reasons so upgrade it now
conan
)
brew install "${brew_packages[@]}"
else # Linux & others
# Distribution packages
if which apt-get; then
apt_packages=(
libasound2-dev
libgtk2.0-dev
gettext
python3-pip
)
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends "${apt_packages[@]}"
sudo apt-get remove -y ccache
else
echo >&2 "$0: Error: You don't have a recognized package manager installed."
exit 1
fi
# Python packages
pip_packages=(
conan
)
pip3 install wheel setuptools # need these first to install other packages (e.g. conan)
pip3 install "${pip_packages[@]}"
fi

25
scripts/ci/environment.sh Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
if [[ "$0" == "${BASH_SOURCE}" ]]; then
echo >&2 "$0: Please source this script instead of running it."
exit 1
fi
((${BASH_VERSION%%.*} >= 4)) || { echo >&2 "${BASH_SOURCE}: Error: Please upgrade Bash."; return 1; }
function gh_export()
{
[[ "${GITHUB_ENV-}" ]] || local -r GITHUB_ENV="/dev/null"
export -- "$@" && printf "%s\n" "$@" >> "${GITHUB_ENV}"
}
repository_root="$(cd "$(dirname "${BASH_SOURCE}")/../.."; echo "${PWD}")"
gh_export CONAN_USER_HOME="${repository_root}/conan-home/"
gh_export CONAN_USER_HOME_SHORT="${repository_root}/conan-home/short"
gh_export GIT_HASH="$(git show -s --format='%H')"
gh_export GIT_HASH_SHORT="$(git show -s --format='%h')"
gh_export AUDACITY_BUILD_TYPE="Release"
gh_export AUDACITY_INSTALL_PREFIX="${repository_root}/build/install"

8
scripts/ci/install.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
((${BASH_VERSION%%.*} >= 4)) || { echo >&2 "$0: Error: Please upgrade Bash."; exit 1; }
set -euxo pipefail
# Install Audacity
cmake --install build --config "${AUDACITY_BUILD_TYPE}" --verbose

8
scripts/ci/package.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
((${BASH_VERSION%%.*} >= 4)) || { echo >&2 "$0: Error: Please upgrade Bash."; exit 1; }
set -euxo pipefail
cd build
cpack -C "${AUDACITY_BUILD_TYPE}" --verbose

View File

@ -1339,7 +1339,15 @@ if( CMAKE_VERSION VERSION_GREATER_EQUAL "3.16" AND NOT CCACHE_PROGRAM )
endif() endif()
endif() endif()
if( NOT "${CMAKE_GENERATOR}" MATCHES "Xcode|Visual Studio*" ) if( "${CMAKE_GENERATOR}" MATCHES "Xcode|Visual Studio*" )
install(
DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/"
DESTINATION "."
USE_SOURCE_PERMISSIONS
PATTERN "*.pdb" EXCLUDE
PATTERN "*.ilk" EXCLUDE
)
else()
if( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) if( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
install( TARGETS ${TARGET} install( TARGETS ${TARGET}
DESTINATION "." DESTINATION "."
@ -1358,6 +1366,9 @@ if( NOT "${CMAKE_GENERATOR}" MATCHES "Xcode|Visual Studio*" )
DESTINATION "${_DATADIR}/mime/packages" ) DESTINATION "${_DATADIR}/mime/packages" )
install( FILES "${topdir}/presets/EQDefaultCurves.xml" install( FILES "${topdir}/presets/EQDefaultCurves.xml"
DESTINATION "${_PKGDATA}" ) DESTINATION "${_PKGDATA}" )
install( PROGRAMS "${PROJECT_SOURCE_DIR}/linux/audacity.sh"
DESTINATION "."
RENAME "audacity" )
endif() endif()
endif() endif()