fix: temporarily remove the work folder as sudo #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test | ||
on: | ||
workflow_call: | ||
inputs: | ||
build_type: | ||
description: 'The CMake build type, can be either: Release, Debug, RelWithDebInfo, etc.' | ||
default: Release | ||
required: false | ||
type: string | ||
build_args: | ||
description: 'Additional build parameters' | ||
default: '-DHAS_GAMS=off -DHAS_CPLEX=off -DHAS_GUROBI=off -DCOMPILE_TESTS=on -DSPDLOG_STATIC=on' | ||
required: false | ||
type: string | ||
job_count: | ||
description: 'The amount of jobs to use when building the program and dependencies.' | ||
default: 1 | ||
required: false | ||
type: number | ||
# Map the workflow outputs to job outputs | ||
version: | ||
description: 'The version to build SHOT as.' | ||
default: ${{ github.sha }} | ||
required: false | ||
type: string | ||
retention: | ||
description: 'The artifact retention period (in days)' | ||
default: 60 | ||
required: false | ||
type: number | ||
upload_artifacts: | ||
description: 'Should the artifacts be uploaded' | ||
default: true | ||
required: false | ||
type: boolean | ||
enable_gurobi: | ||
description: 'Is this a Gurobi build (this will install Gurobi)' | ||
default: false | ||
required: false | ||
type: boolean | ||
enable_gams: | ||
description: 'Is this a GAMS build (this will install GAMS)' | ||
default: false | ||
required: false | ||
type: boolean | ||
artifact_suffix: | ||
description: 'The suffix to add to the artifact name' | ||
default: '' | ||
required: false | ||
type: string | ||
secrets: | ||
gurobi_license: | ||
description: 'Gurobi license file secret' | ||
required: false | ||
gams_license: | ||
description: 'GAMS license file secret' | ||
required: false | ||
outputs: | ||
test-artifact: | ||
description: "Test artifact ID" | ||
value: ${{ jobs.build.outputs.test-artifact }} | ||
options-artifact: | ||
description: "SHOT Optionsfile artifact ID" | ||
value: ${{ jobs.build.outputs.options-artifact }} | ||
binary-artifact: | ||
description: "SHOT Binary artifact ID" | ||
value: ${{ jobs.build.outputs.binary-artifact }} | ||
package-artifact: | ||
description: "SHOT Package artifact ID" | ||
value: ${{ jobs.build.outputs.package-artifact }} | ||
library-artifact: | ||
description: "SHOT Libraries artifact ID" | ||
value: ${{ jobs.build.outputs.library-artifact }} | ||
env: | ||
BUILD_TYPE: ${{ inputs.build_type }} | ||
JOB_COUNT: ${{ inputs.job_count }} | ||
VERSION: ${{ inputs.version }} | ||
ARTIFACT_SUFFIX: ${{ inputs.artifact_suffix }} | ||
EXTRA_BUILD_ARGS: ${{ inputs.build_args }} | ||
GRB_LICENSE_FILE: ${{ github.workspace }}/gurobi.lic | ||
GRB_INSTALL_PATH: ${{ github.workspace }}/ThirdParty/gurobi1001 | ||
GAMS_LICENSE_FILE: ${{ github.workspace }}/ThirdParty/gams42.3_linux_x64_64_sfx/gamslice.txt | ||
GAMS_INSTALL_PATH: ${{ github.workspace }}/ThirdParty/gams42.3_linux_x64_64_sfx | ||
jobs: | ||
build: | ||
outputs: | ||
test-artifact: ${{ steps.artifact_outputs.test }} | ||
options-artifact: ${{ steps.artifact_outputs.options }} | ||
binary-artifact: ${{ steps.artifact_outputs.binary }} | ||
package-artifact: ${{ steps.artifact_outputs.package }} | ||
library-artifact: ${{ steps.artifact_outputs.library }} | ||
name: Build SHOT | ||
runs-on: [ self-hosted, linux, cmake ] | ||
env: | ||
GAMS_OPTIONS: -DHAS_GAMS=off | ||
GUROBI_OPTIONS: -DHAS_GUROBI=off | ||
steps: | ||
- name: Cleanup workspace | ||
run: | | ||
sudo rm -rf ./* || true | ||
rm -rf ./* || true | ||
3 | ||
sudo rm -rf ./.??* || true | ||
- uses: actions/checkout@v3 | ||
- name: Checkout submodules | ||
run: git submodule update --init --recursive | ||
- name: Create Build Environment | ||
# Some projects don't allow in-source building, so create a separate build directory | ||
# We'll use this as our working directory for all subsequent commands | ||
run: cmake -E make_directory ${{github.workspace}}/build | ||
- name: Install dependencies | ||
shell: bash | ||
run: sudo apt-get update ; sudo apt-get install -y libc6-dev libbz2-dev zlib1g-dev liblapack-dev libnauty2-dev libopenblas-base libopenblas-dev libmumps-dev pkgconf | ||
- name: Cache Cbc | ||
id: cache-cbc | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{github.workspace}}/ThirdParty/Cbc | ||
key: ${{ runner.os }}-cbc | ||
- name: Cache Ipopt | ||
id: cache-ipopt | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{github.workspace}}/ThirdParty/Ipopt | ||
key: ${{ runner.os }}-ipopt | ||
- name: Setup Coinbrew | ||
if: steps.cache-ipopt.outputs.cache-hit != 'true' || steps.cache-cbc.outputs.cache-hit != 'true' | ||
shell: bash | ||
working-directory: ${{github.workspace}}/build | ||
run: git -C "coinbrew" pull || git clone https://github.com/coin-or/coinbrew | ||
- name: Download and build Ipopt | ||
if: steps.cache-ipopt.outputs.cache-hit != 'true' | ||
shell: bash | ||
working-directory: ${{github.workspace}}/build/coinbrew | ||
run: ./coinbrew build Ipopt --verbosity 2 --prefix=${{github.workspace}}/ThirdParty/Ipopt -j $JOB_COUNT --no-prompt --tests none | ||
- name: Download and build Cbc | ||
if: steps.cache-cbc.outputs.cache-hit != 'true' | ||
shell: bash | ||
working-directory: ${{github.workspace}}/build/coinbrew | ||
run: rm -rf build dist ; ./coinbrew build Cbc@stable/2.10 --verbosity 2 -j $JOB_COUNT --prefix=${{github.workspace}}/ThirdParty/Cbc --no-prompt --tests none --no-third-party | ||
# Proprietary software setup happens here (GAMS and Gurobi) | ||
# First we create the license files from the base64 encoded secrets. | ||
- name: Setup Gurobi License file | ||
if: ${{ inputs.enable_gurobi }} | ||
shell: bash | ||
working-directory: ${{github.workspace}} | ||
run: echo ${{ secrets.gurobi_license }} | base64 -d > $GRB_LICENSE_FILE | ||
# Then we download and install Gurobi | ||
- name: Download Gurobi | ||
if: ${{ inputs.enable_gurobi }} | ||
shell: bash | ||
working-directory: ${{github.workspace}}/ThirdParty | ||
run: wget -q https://packages.gurobi.com/10.0/gurobi10.0.1_linux64.tar.gz ; tar -xvf gurobi10.0.1_linux64.tar.gz ; rm gurobi10.0.1_linux64.tar.gz | ||
# Finally, we set the environment variables needed for Gurobi to work. | ||
- name: Setup Gurobi environment variables | ||
if: ${{ inputs.enable_gurobi }} | ||
shell: bash | ||
working-directory: ${{github.workspace}}/ThirdParty | ||
run: | | ||
echo "${{ github.workspace }}/ThirdParty/gurobi1001/linux64/bin" >> $GITHUB_PATH | ||
echo "GUROBI_HOME=${{ github.workspace }}/ThirdParty/gurobi1001/linux64" >> $GITHUB_ENV | ||
echo "LD_LIBRARY_PATH=${{ github.workspace }}/ThirdParty/gurobi1001/linux64/lib" >> $GITHUB_ENV | ||
- name: Set Gurobi options | ||
if: ${{ inputs.enable_gurobi }} | ||
shell: bash | ||
run: echo "GUROBI_OPTIONS=-DHAS_GUROBI=on" >> $GITHUB_ENV | ||
# Next, we set up GAMS | ||
# Download GAMS | ||
- name: Download GAMS | ||
if: ${{ inputs.enable_gams }} | ||
shell: bash | ||
working-directory: ${{github.workspace}}/ThirdParty | ||
run: wget -q https://d37drm4t2jghv5.cloudfront.net/distributions/42.3.0/linux/linux_x64_64_sfx.exe ; chmod +x linux_x64_64_sfx.exe ; ./linux_x64_64_sfx.exe ; rm linux_x64_64_sfx.exe | ||
# Add the license file to the GAMS installation directory | ||
- name: Setup GAMS License file | ||
if: ${{ inputs.enable_gams }} | ||
shell: bash | ||
working-directory: ${{github.workspace}} | ||
run: echo ${{ secrets.gams_license }} | base64 -d > $GAMS_LICENSE_FILE | ||
- name: Install GAMS | ||
if: ${{ inputs.enable_gams }} | ||
shell: bash | ||
working-directory: ${{ github.workspace }}/ThirdParty/gams42.3_linux_x64_64_sfx/ | ||
run: ./gamsinst -a | ||
- name: Add GAMS to the path | ||
if: ${{ inputs.enable_gams }} | ||
shell: bash | ||
run: echo "$GAMS_INSTALL_PATH" >> $GITHUB_PATH | ||
- name: Set GAMS options | ||
if: ${{ inputs.enable_gams }} | ||
shell: bash | ||
run: echo "GAMS_OPTIONS=-DHAS_GAMS=on" >> $GITHUB_ENV | ||
- name: Configure CMake | ||
# Use a bash shell so we can use the same syntax for environment variable | ||
# access regardless of the host operating system | ||
shell: bash | ||
working-directory: ${{github.workspace}}/build | ||
# Note the current convention is to use the -S and -B options here to specify source | ||
# and build directories, but this is only available with CMake 3.13 and higher. | ||
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12 | ||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DHAS_CBC=on -DCBC_DIR=${{github.workspace}}/ThirdParty/Cbc -DHAS_IPOPT=ON -DIPOPT_DIR=${{github.workspace}}/ThirdParty/Ipopt -DGAMS_DIR=$GAMS_INSTALL_PATH -DGUROBI_DIR=$GRB_INSTALL_PATH -DCOMPILE_TESTS=on -DSPDLOG_STATIC=on $GAMS_OPTIONS $GUROBI_OPTIONS -DHAS_CPLEX=off | ||
- name: Build | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
# Execute the build. You can specify a specific target with "--target <NAME>" | ||
run: cmake --build . --config $BUILD_TYPE -j $JOB_COUNT | ||
- name: Generate Optionsfile | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
run: ./SHOT --opt | ||
- name: Test | ||
id: test | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
run: ctest -C $BUILD_TYPE --output-on-failure --output-junit test-output/ctest-junit-output.xml --output-log test-output/ctest-test.log | ||
- name: Construct package | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
run: make package | ||
# This will always run as we always want the test output, however if the files are not found, we just warn the user. | ||
- uses: actions/upload-artifact@v3 | ||
if: ${{ always() }} | ||
name: Upload test results | ||
with: | ||
name: test-logs-${{ env.VERSION }}${{ env.ARTIFACT_SUFFIX }} | ||
path: | | ||
${{github.workspace}}/build/test-output/*.log | ||
${{github.workspace}}/build/test-output/*.xml | ||
retention-days: ${{ inputs.retention }} | ||
- uses: actions/upload-artifact@v3 | ||
if: ${{ inputs.upload_artifacts }} | ||
name: Upload SHOT Optionsfile | ||
with: | ||
name: shot-optsfile-${{ env.VERSION }}${{ env.ARTIFACT_SUFFIX }} | ||
path: ${{github.workspace}}/build/SHOT.opt | ||
retention-days: ${{ inputs.retention }} | ||
- uses: actions/upload-artifact@v3 | ||
if: ${{ inputs.upload_artifacts }} | ||
name: Upload SHOT File | ||
with: | ||
name: shot-binary-${{ env.VERSION }}${{ env.ARTIFACT_SUFFIX }} | ||
path: ${{github.workspace}}/build/SHOT | ||
retention-days: ${{ inputs.retention }} | ||
- uses: actions/upload-artifact@v3 | ||
if: ${{ inputs.upload_artifacts }} | ||
name: Upload SHOT Package file | ||
with: | ||
name: shot-package-${{ env.VERSION }}${{ env.ARTIFACT_SUFFIX }} | ||
path: ${{github.workspace}}/build/SHOT-*-Linux.zip | ||
retention-days: ${{ inputs.retention }} | ||
- uses: actions/upload-artifact@v3 | ||
if: ${{ inputs.upload_artifacts }} | ||
name: Upload SHOT Libraries | ||
with: | ||
name: shot-libraries-${{ env.VERSION }}${{ env.ARTIFACT_SUFFIX }} | ||
path: | | ||
${{github.workspace}}/build/*.so | ||
${{github.workspace}}/build/*.a | ||
retention-days: ${{ inputs.retention }} | ||
- name: Output artifact names | ||
id: output-artifacts | ||
if: ${{ inputs.upload_artifacts }} | ||
shell: bash | ||
run: | | ||
echo "test=test-logs-${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
echo "options=shot-optsfile-${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
echo "binary=shot-binary-${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
echo "package=shot-package-${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
echo "library=shot-libraries-${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
- name: Output test artifacts | ||
if: ${{ inputs.upload_artifacts }} != true && steps.output-artifacts.outcome != 'success' | ||
shell: bash | ||
run: echo "test=test-logs-${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
- name: Cleanup license files | ||
if: ${{ success() || failure() }} | ||
shell: bash | ||
run: | | ||
rm -f $GRB_LICENSE_FILE | ||
rm -f $GAMS_LICENSE_FILE |