Merge pull request #120 from Sharpie/swap-contains #8
This file contains hidden or 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 an OpenVox vanagon project | ||
|
Check failure on line 1 in .github/workflows/build_vanagon.yml
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| ref: | ||
| description: 'Git ref to build' | ||
| required: false | ||
| type: string | ||
| project_name: | ||
| description: 'The vanagon project to build' | ||
| required: true | ||
| type: string | ||
| platform_list: | ||
| description: 'A comma-separated list of platforms to build for. Do not include spaces. If not provided, will use the default list of platforms supported by OpenVox.' | ||
| required: false | ||
| type: string | ||
| vanagon_branch: | ||
| description: 'The branch of the vanagon repository to use' | ||
| required: false | ||
| type: string | ||
| default: 'main' | ||
| working_directory: | ||
| description: 'The directory inside the repo containing the vanagon project. For repos that are specifically vanagon projects, leave this as default.' | ||
| required: false | ||
| type: string | ||
| default: '.' | ||
| upload_to_s3: | ||
| description: 'Whether to upload the built artifacts to S3. If false, the artifacts will only be uploaded as workflow artifacts.' | ||
| required: false | ||
| type: boolean | ||
| default: true | ||
| branch: | ||
| description: 'Release branch being built. Selects the default platform list.' | ||
| type: string | ||
| required: false | ||
| default: 'main' | ||
| env: | ||
| VANAGON_LOCATION: "https://github.com/openvoxproject/vanagon#${{ inputs.vanagon_branch }}" | ||
| jobs: | ||
| set-matrix: | ||
| runs-on: ubuntu-24.04 | ||
| outputs: | ||
| build_matrix: ${{ steps.set-matrix.outputs.build_matrix }} | ||
| steps: | ||
| - name: Checkout platform config | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| repository: OpenVoxProject/shared-actions | ||
| ref: main | ||
| path: .shared-actions | ||
| sparse-checkout: platforms.json | ||
| sparse-checkout-cone-mode: false | ||
| - id: set-matrix | ||
| env: | ||
| PLATFORM_LIST: ${{ inputs.platform_list }} | ||
| PROJECT_NAME: ${{ inputs.project_name }} | ||
| BRANCH: ${{ inputs.branch }} | ||
| run: | | ||
| mapfile -t default_list < <(jq -r --arg branch "${BRANCH}" '.[$branch].vanagon[]' .shared-actions/platforms.json) | ||
| if [[ -n "${PLATFORM_LIST}" ]]; then | ||
| IFS=',' read -r -a platforms <<< "${PLATFORM_LIST}" | ||
| else | ||
| platforms=("${default_list[@]}") | ||
| # openbolt and openbolt-runtime do not support redhatfips or el-7 | ||
| if [[ "${PROJECT_NAME}" == openbolt* ]]; then | ||
| mapfile -t platforms < <(printf '%s\n' "${platforms[@]}" | grep -v -e '^redhatfips-' -e '^el-7-') | ||
| fi | ||
| fi | ||
| build_platforms=() | ||
| for platform in "${platforms[@]}"; do | ||
| case "$platform" in | ||
| macos-*-x86_64) | ||
| runner="macos-26" | ||
| shell="arch -x86_64 /bin/bash -e {0}" | ||
| ;; | ||
| macos-*-arm64) | ||
| runner="macos-26" | ||
| shell="bash" | ||
| ;; | ||
| windows-all-*) | ||
| runner="windows-2025-vs2026" | ||
| # igncr is required so that Cygwin doesn't get confused by Windows line endings | ||
| shell="C:/cygwin64/bin/bash.exe -eo pipefail -o igncr '{0}'" | ||
| ;; | ||
| windows-msys2-*) | ||
| runner="windows-2025-vs2026" | ||
| # msys2.cmd is created by the msys2/setup-msys action. | ||
| # It typically lives at D:\a\_temp\setup-msys2\msys2.cmd | ||
| # and is basically a wrapper to invoke `bash.exe -leo pipefail` | ||
| # with MSYSTEM=UCRT64 and MSYS_PATH_TYPE=minimal | ||
| shell="msys2 '{0}'" | ||
| ;; | ||
| *-aarch64 | *-arm64 | *-armhf) | ||
| runner="ubuntu-24.04-arm" | ||
| shell="bash" | ||
| ;; | ||
| *) | ||
| runner="ubuntu-24.04" | ||
| shell="bash" | ||
| ;; | ||
| esac | ||
| build_platforms+=("{\"platform\":\"$platform\",\"runner\":\"$runner\",\"shell\":\"$shell\"}") | ||
| done | ||
| matrix_json="[$(IFS=','; echo "${build_platforms[*]}")]" | ||
| echo "build_matrix=$matrix_json" >> "${GITHUB_OUTPUT}" | ||
| build: | ||
| needs: set-matrix | ||
| timeout-minutes: 600 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: ${{ fromJSON(needs.set-matrix.outputs.build_matrix) }} | ||
| runs-on: ${{ matrix.runner }} | ||
| defaults: | ||
| run: | ||
| shell: ${{ matrix.shell }} | ||
| steps: | ||
| - name: Install Ruby (except Windows and macos-all-x86_64) | ||
| if: ${{ matrix.platform != 'macos-all-x86_64' && ! startsWith(matrix.platform, 'windows') }} | ||
| uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0 | ||
| with: | ||
| ruby-version: '3.2' | ||
| - name: Setup brew and Ruby (MacOS x86_64 only) | ||
| if: ${{ matrix.platform == 'macos-all-x86_64' }} | ||
| # We must fully uninstall the existing brew install as we need | ||
| # the x86_64 version, and then we must install Ruby ourselves | ||
| shell: bash | ||
| run: |- | ||
| echo '*** Removing existing homebrew installation ***' | ||
| brew list --cask | xargs -r brew uninstall --cask --force | ||
| brew list --formula | xargs -r brew uninstall --force --ignore-dependencies | ||
| brew autoremove | ||
| sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force | ||
| echo '*** Removing /opt/homebrew directory ***' | ||
| sudo rm -rf /opt/homebrew | ||
| echo '*** Installing x86_64 homebrew and Ruby ***' | ||
| arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | ||
| arch -x86_64 /bin/bash -c 'brew install ruby@3.2' | ||
| echo '*** Setting up environment variables ***' | ||
| eval "$(/usr/local/bin/brew shellenv)" | ||
| echo "HOMEBREW_PREFIX=${HOMEBREW_PREFIX}" >> $GITHUB_ENV | ||
| echo "HOMEBREW_CELLAR=${HOMEBREW_CELLAR}" >> $GITHUB_ENV | ||
| echo "HOMEBREW_REPOSITORY=${HOMEBREW_REPOSITORY}" >> $GITHUB_ENV | ||
| echo "MANPATH=${MANPATH}" >> $GITHUB_ENV | ||
| echo "INFOPATH=${INFOPATH}" >> $GITHUB_ENV | ||
| echo "${HOMEBREW_PREFIX}/bin" >> $GITHUB_PATH | ||
| echo "${HOMEBREW_PREFIX}/sbin" >> $GITHUB_PATH | ||
| echo '/usr/local/opt/ruby@3.2/bin' >> $GITHUB_PATH | ||
| echo '/usr/local/lib/ruby/gems/3.2.0/bin' >> $GITHUB_PATH | ||
| echo '*** Using 2.x version of bundler for now ***' | ||
| arch -x86_64 /usr/local/opt/ruby@3.2/bin/gem install bundler -v 2.7.2 | ||
| echo "BUNDLER_VERSION=2.7.2" >> $GITHUB_ENV | ||
| - name: Set up MSYS2 (Windows only) | ||
| if: ${{ startsWith(matrix.platform, 'windows-msys2') }} | ||
| uses: msys2/setup-msys2@66cd2cce69caa17b53920067426061ca1de3a884 # v2.32.0 | ||
| with: | ||
| msystem: UCRT64 | ||
| update: true | ||
| # Install packages required by bundle install. | ||
| # Uses Cygwin-mode packages rather than Windows native packages | ||
| # as Vanagon expects to be interacting with a POSIX environment. | ||
| install: >- | ||
| ruby | ||
| gcc | ||
| make | ||
| git | ||
| libffi-devel | ||
| libyaml-devel | ||
| - name: Configure MSYS2 (Windows only) | ||
| if: ${{ startsWith(matrix.platform, 'windows-msys2') }} | ||
| env: | ||
| # Disable MSYS2 PATH stripping so that winget CLI is visible. | ||
| MSYS2_PATH_TYPE: inherit | ||
| run: | | ||
| # bundle install hangs under MSYS2 Ruby when more than one | ||
| # job is run in parallel. | ||
| bundle config set --global jobs 1 | ||
| # This is so that Puppet doesn't throw up when we look up Puppet.version in the | ||
| # openvox repo. It will think it is in a posix environment, but it should not | ||
| # matter for any other part of the build process. | ||
| # See https://github.com/OpenVoxProject/openvox/blob/5bcee89748ad1069ac31504cbc4853a6d636c2b0/lib/puppet/feature/base.rb#L13-L19 | ||
| echo "root:*:0:0:::" >>/etc/passwd | ||
| # WinGet exits with a failure code if asked to install an | ||
| # already-installed package. | ||
| winget list \ | ||
| --accept-source-agreements \ | ||
| --id WiXToolset.WiXToolset --source winget || \ | ||
| winget install \ | ||
| --accept-source-agreements --accept-package-agreements --silent \ | ||
| --id WiXToolset.WiXToolset --source winget | ||
| - name: Set git params for Windows | ||
| if: ${{ startsWith(matrix.platform, 'windows') }} | ||
| shell: pwsh | ||
| run: | | ||
| # Without this, patch.exe fails due to line ending differences | ||
| git config --global core.autocrlf false | ||
| git config --global core.eol lf | ||
| - name: Checkout code | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ inputs.ref }} | ||
| fetch-depth: 0 # So we fetch all history and tags and can build non-tagged versions | ||
| - name: Install Cygwin and bootstrap dependencies (Windows only) | ||
| if: ${{ startsWith(matrix.platform, 'windows-all') }} | ||
| shell: pwsh | ||
| working-directory: ${{ inputs.working_directory }} | ||
| run: | | ||
| .\setup.ps1 | ||
| # This is to make sure Cygwin binaries are used over preinstalled items | ||
| echo "C:\cygwin64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | ||
| # This is to fix file permissions issues when we check out code outside of Cygwin | ||
| echo "none /cygdrive cygdrive binary,noacl,posix=0,user 0 0" | Out-File -FilePath C:\cygwin64\etc\fstab -Encoding ASCII | ||
| # This is so that Puppet doesn't throw up when we look up Puppet.version in the | ||
| # openvox repo. It will think it is in a posix environment, but it should not | ||
| # matter for any other part of the build process. | ||
| # See https://github.com/OpenVoxProject/openvox/blob/5bcee89748ad1069ac31504cbc4853a6d636c2b0/lib/puppet/feature/base.rb#L13-L19 | ||
| echo "root:*:0:0:::" | Out-File -FilePath C:\cygwin64\etc\passwd -Encoding ASCII | ||
| - name: Bundle install | ||
| working-directory: ${{ inputs.working_directory }} | ||
| env: | ||
| # Ensure only POSIX compilers and runtime libs are on the PATH. | ||
| # Default is UCRT64, which prioritizes /ucrt64/bin/gcc, and that | ||
| # breaks `bundle install` for MSYS POSIX Ruby. | ||
| MSYSTEM: MSYS | ||
| run: | | ||
| bundle install --retry=3 | ||
| # from https://github.com/Sharpie/puppet-build-experiment/blob/master/resources/bolt/tasks/configure_builder.sh#L3-L14 | ||
| - name: Force docker into 32bit mode | ||
| if: contains(matrix.platform, 'armhf') | ||
| run: | | ||
| sudo mkdir -p /etc/systemd/system/docker.service.d | ||
| echo -e "[Service]\nExecStart=\nExecStart=/usr/bin/setarch linux32 -B /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock\n" | sudo tee /etc/systemd/system/docker.service.d/override.conf | ||
| sudo mkdir -p /etc/systemd/system/containerd.service.d | ||
| echo -e "[Service]\nExecStart=\nExecStart=/usr/bin/setarch linux32 -B /usr/bin/containerd\n" | sudo tee /etc/systemd/system/containerd.service.d/override.conf | ||
| sudo systemctl daemon-reload | ||
| sudo systemctl restart docker.service containerd.service | ||
| sudo systemctl status docker.service containerd.service | ||
| sudo systemctl show docker.service containerd.service | ||
| - name: Run build script and save git describe | ||
| id: build | ||
| working-directory: ${{ inputs.working_directory }} | ||
| env: | ||
| PROJECT_NAME: ${{ inputs.project_name }} | ||
| BUILD_PLATFORM: ${{ matrix.platform }} | ||
| run: |- | ||
| rm -rf output | ||
| DESCRIBE=$(git describe --abbrev=9) | ||
| case "${DESCRIBE}" in | ||
| *-alpha[0-9]|*-beta[0-9]|*-rc[0-9]) | ||
| printf 'describe=%s\n' "$(sed 's/-/~/' <<<"$DESCRIBE")" >>$GITHUB_OUTPUT | ||
| ;; | ||
| *) | ||
| printf 'describe=%s\n' "${DESCRIBE//-/.}" >>$GITHUB_OUTPUT | ||
| ;; | ||
| esac | ||
| bundle exec rake "vox:build[${PROJECT_NAME},${BUILD_PLATFORM}]" | ||
| - name: Upload build artifacts | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: build-artifacts-${{ steps.build.outputs.describe }}-${{ matrix.platform }} | ||
| path: ${{ inputs.working_directory }}/output/ | ||
| - name: Configure OSUOSL CA Certificate for S3 | ||
| if: >- | ||
| inputs.upload_to_s3 && | ||
| ( secrets.S3_ENDPOINT_URL == 'https://s3.osuosl.org' ) | ||
| uses: ./.github/actions/setup-osuosl-ca | ||
| - name: Upload output to S3 | ||
| if: ${{ inputs.upload_to_s3 }} | ||
| working-directory: ${{ inputs.working_directory }} | ||
| env: | ||
| ENDPOINT_URL: ${{ secrets.S3_ENDPOINT_URL }} | ||
| BUCKET_NAME: ${{ secrets.S3_ARTIFACTS_BUCKET_NAME }} | ||
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| # https://github.com/boto/boto3/issues/4398#issuecomment-2619946229 | ||
| AWS_REQUEST_CHECKSUM_CALCULATION: "WHEN_REQUIRED" | ||
| AWS_RESPONSE_CHECKSUM_VALIDATION: "WHEN_REQUIRED" | ||
| BUILD_DESCRIBE: ${{ steps.build.outputs.describe }} | ||
| BUILD_PLATFORM: ${{ matrix.platform }} | ||
| # Disable MSYS2 PATH stripping so that aws CLI installed on | ||
| # GitHub Runners is visible. | ||
| MSYS2_PATH_TYPE: inherit | ||
| run: bundle exec rake "vox:upload[${BUILD_DESCRIBE},${BUILD_PLATFORM}]" | ||