From 471c576fd4545f1b9f5e12f54f002e45fc0225b9 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 2 Jul 2021 13:58:17 +0300 Subject: workflows/test: factor out steps + refactoring --- .github/actions/build-foo-cygwin/action.yml | 20 +++++ .github/actions/build-foo/action.yml | 20 +++++ .github/actions/check-cc-cygwin/action.yml | 21 +++++ .github/actions/check-cc/action.yml | 16 ++++ .github/actions/run-foo/action.yml | 20 +++++ .github/workflows/test.yml | 128 ++++++++-------------------- 6 files changed, 133 insertions(+), 92 deletions(-) create mode 100644 .github/actions/build-foo-cygwin/action.yml create mode 100644 .github/actions/build-foo/action.yml create mode 100644 .github/actions/check-cc-cygwin/action.yml create mode 100644 .github/actions/check-cc/action.yml create mode 100644 .github/actions/run-foo/action.yml diff --git a/.github/actions/build-foo-cygwin/action.yml b/.github/actions/build-foo-cygwin/action.yml new file mode 100644 index 0000000..e1ae57c --- /dev/null +++ b/.github/actions/build-foo-cygwin/action.yml @@ -0,0 +1,20 @@ +name: Build foo.exe +description: Build foo.exe (on Cygwin) +inputs: + platform: + description: Target platform + required: true +runs: + using: composite + steps: + - run: | + IFS= read -r src_dir <<'EOF' + ${{ github.workspace }} + EOF + echo "$src_dir" + src_dir="$( cygpath -ua "$src_dir" )" + cd -- "$src_dir" + arch= + [ '${{ matrix.platform }}' == 'x86' ] && arch=-m32 + g++ $arch -std=c++14 -o foo foo.cpp + shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' diff --git a/.github/actions/build-foo/action.yml b/.github/actions/build-foo/action.yml new file mode 100644 index 0000000..c1a6fdd --- /dev/null +++ b/.github/actions/build-foo/action.yml @@ -0,0 +1,20 @@ +name: Build foo.exe +description: Build foo.exe +inputs: + platform: + description: Target platform + required: true +runs: + using: composite + steps: + - run: | + $flags = @() + if ('${{ matrix.platform }}' -eq 'x86') { + $flags += '-m32' + } + $flags += '-std=c++14','-o','foo','foo.cpp' + if ('${{ runner.os }}' -eq 'Linux') { + $flags += '-lpthread' + } + g++ $flags + shell: pwsh diff --git a/.github/actions/check-cc-cygwin/action.yml b/.github/actions/check-cc-cygwin/action.yml new file mode 100644 index 0000000..b0926cc --- /dev/null +++ b/.github/actions/check-cc-cygwin/action.yml @@ -0,0 +1,21 @@ +name: Check cc/c++ +description: Check cc/c++ (on Cygwin) +runs: + using: composite + steps: + # Is this really the most stable piece of `gcc --version` output? + - run: | + check_tool() { + local exe + for exe; do + output="$( "$exe" --version )" + echo "$output" + if ! echo "$output" | grep -F -- "This is free software; see the source for copying conditions."; then + echo 'Unexpected `'"$exe"' --version` output.' >&2 + exit 1 + fi + done + } + check_tool cc + check_tool c++ + shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' diff --git a/.github/actions/check-cc/action.yml b/.github/actions/check-cc/action.yml new file mode 100644 index 0000000..d2b98ed --- /dev/null +++ b/.github/actions/check-cc/action.yml @@ -0,0 +1,16 @@ +name: Check cc/c++ +description: Check cc/c++ +runs: + using: composite + steps: + # Is this really the most stable piece of `gcc --version` output? + - run: | + echo (Get-Command cc).Path + $cc = & cc --version + echo $cc + $($cc | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `cc --version` output") + echo (Get-Command c++).Path + $cxx = & c++ --version + echo $cxx + $($cxx | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `c++ --version` output") + shell: pwsh diff --git a/.github/actions/run-foo/action.yml b/.github/actions/run-foo/action.yml new file mode 100644 index 0000000..9e53df5 --- /dev/null +++ b/.github/actions/run-foo/action.yml @@ -0,0 +1,20 @@ +name: Run foo.exe +description: Run foo.exe and verify its output +runs: + using: composite + steps: + - run: | + $expected = @" + Doing something #1 + Doing something #2 + Doing something #3 + "@ + + $actual = & (Join-Path . foo) + $actual = $actual -join [Environment]::NewLine + + $($actual -eq $expected) -or $(throw @" + Unexpected output: + $actual + "@) + shell: pwsh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dcb1b46..5de83a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,118 +9,62 @@ on: workflow_dispatch: jobs: - test: + ubuntu: strategy: - fail-fast: false matrix: platform: [x86, x64] - cygwin: [0, 1] - hardlinks: [0, 1] - os: [ubuntu-18.04, ubuntu-20.04, ubuntu-latest, windows-latest] - - include: - # Prettier run names. - - {os: ubuntu-18.04, name: Ubuntu 18.04} - - {os: ubuntu-20.04, name: Ubuntu 20.04} - - {os: ubuntu-latest, name: Ubuntu (latest)} - - {cygwin: 1, name: Cygwin} - exclude: - # No Cygwin on Ubuntu. - - {os: ubuntu-18.04, cygwin: 1} - - {os: ubuntu-20.04, cygwin: 1} - - {os: ubuntu-latest, cygwin: 1} - # This action is not suitable for Windows hosts, use setup-mingw for - # that. - - {os: windows-latest, cygwin: 0} - # Only test hardlinks on Cygwin. - - {cygwin: 0, hardlinks: 1} - + os: [ubuntu-18.04, ubuntu-20.04, ubuntu-latest] runs-on: '${{ matrix.os }}' - - name: '${{ matrix.name }} / ${{ matrix.platform }} / Hardlinks: ${{ matrix.hardlinks }}' - - defaults: - run: - shell: pwsh - + name: 'Test: ${{ matrix.os }} / ${{ matrix.platform }}' steps: - name: Checkout uses: actions/checkout@v2 + - name: Set up GCC + uses: ./ + with: + platform: '${{ matrix.platform }}' + cc: 1 + - name: Build foo.exe + uses: ./.github/actions/build-foo + - name: Run foo.exe + uses: ./.github/actions/run-foo + - name: Check cc/c++ + uses: ./.github/actions/check-cc + cygwin: + strategy: + matrix: + platform: [x86, x64] + hardlinks: [0, 1] + runs-on: windows-latest + name: 'Cygwin: ${{ matrix.platform }} / hardlinks${{ matrix.hardlinks }}' + steps: + - name: Checkout + uses: actions/checkout@v2 - name: Clean up PATH uses: egor-tensin/cleanup-path@v1 - if: runner.os == 'Windows' - - name: Install Cygwin uses: egor-tensin/setup-cygwin@v3 with: platform: '${{ matrix.platform }}' - if: matrix.cygwin - - name: Set up GCC uses: ./ with: platform: '${{ matrix.platform }}' - cygwin: '${{ matrix.cygwin }}' + cygwin: 1 cc: 1 hardlinks: '${{ matrix.hardlinks }}' - - name: Build foo.exe - run: | - $flags = @() - if ('${{ matrix.platform }}' -eq 'x86') { - $flags += '-m32' - } - $flags += '-std=c++14','-o','foo','foo.cpp' - if ('${{ runner.os }}' -eq 'Linux') { - $flags += '-lpthread' - } - g++ $flags - if: '!matrix.cygwin || matrix.hardlinks' - - - name: Build foo.exe on Cygwin - run: | - $cwd = cygpath.exe -ua (Get-Location) - $arch = if ('${{ matrix.platform }}' -eq 'x64') { '-m64' } else { '-m32' } - $cmd = printf.exe -- 'cd %q && g++ %q -std=c++14 -o foo foo.cpp' $cwd $arch - bash.exe --login -o errexit -c $cmd - if: matrix.cygwin && !matrix.hardlinks - + uses: ./.github/actions/build-foo + if: matrix.hardlinks + - name: Build foo.exe + uses: ./.github/actions/build-foo-cygwin + if: '!matrix.hardlinks' - name: Run foo.exe - run: | - $expected = @" - Doing something #1 - Doing something #2 - Doing something #3 - "@ - - $actual = & (Join-Path . foo) - $actual = $actual -join [Environment]::NewLine - - $($actual -eq $expected) -or $(throw @" - Unexpected output: - $actual - "@) - - # Is this really the most stable piece of `gcc --version` output? + uses: ./.github/actions/run-foo - name: Check cc/c++ - run: | - echo (Get-Command cc).Path - $cc = & cc --version - echo $cc - $($cc | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `cc --version` output") - echo (Get-Command c++).Path - $cxx = & c++ --version - echo $cxx - $($cxx | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `c++ --version` output") - if: '!matrix.cygwin || matrix.hardlinks' - - - name: Check cc/c++ on Cygwin - run: | - $cc = bash.exe --login -o errexit -c 'cc --version' - echo $cc - $($cc | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `cc --version` output") - $cxx = bash.exe --login -o errexit -c 'c++ --version' - echo $cxx - $($cxx | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `c++ --version` output") - if: matrix.cygwin && !matrix.hardlinks + uses: ./.github/actions/check-cc + if: matrix.hardlinks + - name: Check cc/c++ + uses: ./.github/actions/check-cc-cygwin + if: '!matrix.hardlinks' -- cgit v1.2.3