From a4e8d225184f3bb721528e13a6995de0f920e65b Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Wed, 31 Mar 2021 11:45:33 +0200 Subject: Split workflow for Haskell and Fortran fpm (#419) --- .github/workflows/CI.yml | 200 +++++++++++++++++++++++++++++++++++++++---- ci/run_tests.bat | 214 ----------------------------------------------- ci/run_tests.sh | 174 +++++++++++++++++++------------------- 3 files changed, 268 insertions(+), 320 deletions(-) delete mode 100755 ci/run_tests.bat diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9ab8f5c..9fc7918 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,6 +1,6 @@ name: CI -on: +on: push: pull_request: release: @@ -16,7 +16,7 @@ env: RUST_BACKTRACE: "full" # Make Rust print full backtrace on error jobs: - Build: + stack-build: runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -88,7 +88,7 @@ jobs: uses: nanzm/get-time-action@v1.0 with: format: 'YYYY-MM' - + - name: Setup github actions cache id: cache uses: actions/cache@v2 @@ -98,9 +98,9 @@ jobs: - name: Build Haskell fpm run: | - cd bootstrap stack build stack install + working-directory: bootstrap - name: put fpm to PATH (macOS) if: contains(matrix.os, 'macos') @@ -116,34 +116,200 @@ jobs: if: contains(matrix.os, 'ubuntu') run: | sudo cp /home/runner/.local/bin/fpm /usr/local/bin - + - name: Run tests on Haskell fpm run: | - cd bootstrap stack test - - - name: Build and test Fortran fpm - run: ${{ matrix.TEST_SCRIPT }} - - - name: Build and test Fortran fpm (release version) - run: ${{ matrix.TEST_SCRIPT }} ${{ matrix.RELEASE_FLAGS }} + working-directory: bootstrap # ----- Upload binaries if creating a release ----- - name: Check that fpm --version matches release tag if: github.event_name == 'release' run: | - cd fpm ${{ matrix.GET_VERSION_CMD }} > fpm_version - fpm run -- "--version" | ${{ matrix.CHECK_VERSION_CMD }} + working-directory: fpm - name: Stage release files for upload if: github.event_name == 'release' run: | - cd fpm - fpm run ${{ matrix.RELEASE_FLAGS }} --runner ${{ matrix.RELEASE_CMD }} ${{ matrix.BOOTSTRAP_RELEASE_CMD }} ${{ matrix.HASH_CMD }} - + working-directory: fpm + + - name: Upload assets + if: github.event_name == 'release' + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: fpm/fpm-* + file_glob: true + tag: ${{ github.ref }} + overwrite: true + + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + gcc_v: [9] # Version of GFortran we want to use. + include: + - os: ubuntu-latest + os-arch: linux-x86_64 + release-flags: --flag '--static -g -fbacktrace -O3' + sha256sum: sha256sum + + - os: macos-latest + os-arch: macos-x86_64 + release-flags: --flag '-g -fbacktrace -O3' + sha256sum: shasum -a 256 + + - os: windows-latest + os-arch: windows-x86_64 + release-flags: --flag '--static -g -fbacktrace -O3' + exe: .exe + sha256sum: sha256sum + + env: + FC: gfortran + GCC_V: ${{ matrix.gcc_v }} + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: Install GFortran macOS + if: contains(matrix.os, 'macos') + run: | + ln -s /usr/local/bin/gfortran-${GCC_V} /usr/local/bin/gfortran + which gfortran-${GCC_V} + which gfortran + + - name: Install GFortran Linux + if: contains(matrix.os, 'ubuntu') + run: | + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \ + --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \ + --slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_V} + + # Phase 1: Bootstrap fpm with existing version + - name: Install fpm + uses: fortran-lang/setup-fpm@v3 + with: + fpm-version: 'v0.2.0' + + - name: Remove fpm from path + shell: bash + run: | + mv $(which fpm) fpm-bootstrap${{ matrix.exe }} + echo "BOOTSTRAP=$PWD/fpm-bootstrap" | cat >> $GITHUB_ENV + + - name: Build Fortran fpm (bootstrap) + shell: bash + run: | + ${{ env.BOOTSTRAP }} build + working-directory: fpm + + - name: Run Fortran fpm (bootstrap) + shell: bash + run: | + ${{ env.BOOTSTRAP }} run + ${{ env.BOOTSTRAP }} run -- --version + ${{ env.BOOTSTRAP }} run -- --help + working-directory: fpm + + - name: Test Fortran fpm (bootstrap) + shell: bash + run: | + ${{ env.BOOTSTRAP }} test + working-directory: fpm + + - name: Install Fortran fpm (bootstrap) + shell: bash + run: | + ${{ env.BOOTSTRAP }} install + working-directory: fpm + + # Phase 2: Bootstrap fpm with itself + - name: Replace bootstrapping version + shell: bash + run: | + ${{ env.BOOTSTRAP }} run --runner cp -- fpm-debug${{ matrix.exe }} + rm -v ${{ env.BOOTSTRAP }} + echo "FPM=$PWD/fpm-debug" | cat >> $GITHUB_ENV + working-directory: fpm + + - name: Get version (normal) + if: github.event_name != 'release' + shell: bash + run: | + VERSION=$(git rev-parse --short HEAD) + echo "VERSION=$VERSION" | cat >> $GITHUB_ENV + + - name: Get version (release) + if: github.event_name == 'release' + shell: bash + run: | + VERSION=$(echo ${{ github.ref }} | cut -dv -f2) + echo "VERSION=$VERSION" | cat >> $GITHUB_ENV + FPM_VERSION=$(${{ env.FPM }} --version | grep -o '${{ env.REGEX }}') + [ "$VERSION" = "$FPM_VERSION" ] + env: + REGEX: '[0-9]\{1,4\}\.[0-9]\{1,4\}\.[0-9]\{1,4\}' + + - name: Build example packages + shell: bash + run: | + ci/run_tests.sh "${{ env.FPM }}" + + - name: Build Fortran fpm + shell: bash + run: | + ${{ env.FPM }} build ${{ matrix.release-flags }} + working-directory: fpm + + - name: Run Fortran fpm + shell: bash + run: | + ${{ env.FPM }} run ${{ matrix.release-flags }} + ${{ env.FPM }} run ${{ matrix.release-flags }} -- --version + ${{ env.FPM }} run ${{ matrix.release-flags }} -- --help + working-directory: fpm + + - name: Test Fortran fpm + shell: bash + run: | + ${{ env.FPM }} test ${{ matrix.release-flags }} + working-directory: fpm + + - name: Install Fortran fpm + shell: bash + run: | + ${{ env.FPM }} install ${{ matrix.release-flags }} + working-directory: fpm + + - name: Package release version + shell: bash + run: | + ${{ env.FPM }} run ${{ matrix.release-flags }} --runner cp -- ${{ env.EXE }} + rm -v ${{ env.FPM }} + echo "FPM_RELEASE=$PWD/${{ env.EXE }}" | cat >> $GITHUB_ENV + working-directory: fpm + env: + EXE: fpm-${{ env.VERSION }}-${{ matrix.os-arch }}${{ matrix.exe }} + + - name: Run release version + shell: bash + run: | + ci/run_tests.sh "${{ env.FPM_RELEASE }}" + + - name: Stage release files for upload + if: github.event_name == 'release' + shell: bash + run: | + ${{ matrix.sha256sum }} ${{ env.FPM_RELEASE }} > ${{ env.FPM_RELEASE }}.sha256 + working-directory: fpm + - name: Upload assets if: github.event_name == 'release' uses: svenstaro/upload-release-action@v2 diff --git a/ci/run_tests.bat b/ci/run_tests.bat deleted file mode 100755 index e010e9f..0000000 --- a/ci/run_tests.bat +++ /dev/null @@ -1,214 +0,0 @@ -@echo on - -cd fpm -if errorlevel 1 exit 1 - -fpm build %* -if errorlevel 1 exit 1 - -fpm run %* -if errorlevel 1 exit 1 - -fpm run %* -- --help -if errorlevel 1 exit 1 - -fpm run %* -- --version -if errorlevel 1 exit 1 - -rmdir fpm_scratch_* /s /q -fpm test %* -if errorlevel 1 exit 1 -rmdir fpm_scratch_* /s /q - -for /f %%i in ('fpm run %* --runner echo') do set fpm_path=%%i -echo %fpm_path% - -%fpm_path% -if errorlevel 1 exit 1 - -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% install --prefix "%CD%\_dist" --no-rebuild -if errorlevel 1 exit 1 - -cd ..\example_packages\hello_world -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target hello_world -if errorlevel 1 exit 1 - -%fpm_path% run -if errorlevel 1 exit 1 - - -cd ..\hello_fpm -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target hello_fpm -if errorlevel 1 exit 1 - - -cd ..\circular_test -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - - -cd ..\circular_example -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - - -cd ..\hello_complex -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% test -if errorlevel 1 exit 1 - -%fpm_path% run --target say_Hello -if errorlevel 1 exit 1 - -%fpm_path% run --target say_goodbye -if errorlevel 1 exit 1 - -%fpm_path% test --target greet_test -if errorlevel 1 exit 1 - -%fpm_path% test --target farewell_test -if errorlevel 1 exit 1 - - -cd ..\hello_complex_2 -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target say_hello_world -if errorlevel 1 exit 1 - -%fpm_path% run --target say_goodbye -if errorlevel 1 exit 1 - -%fpm_path% test --target greet_test -if errorlevel 1 exit 1 - -%fpm_path% test --target farewell_test - - -cd ..\with_examples -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --example --target demo-prog -if errorlevel 1 exit 1 - -%fpm_path% run --target demo-prog -if errorlevel 1 exit 1 - - -cd ..\auto_discovery_off -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target auto_discovery_off -if errorlevel 1 exit 1 - -%fpm_path% test --target my_test -if errorlevel 1 exit 1 - -if exist .\build\gfortran_*\app\unused exit /B 1 - -if exist .\build\gfortran_*\test\unused_test exit /B 1 - - -cd ..\with_c -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target with_c -if errorlevel 1 exit 1 - - -cd ..\submodules -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - - -cd ..\program_with_module -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target Program_with_module -if errorlevel 1 exit 1 - - -cd ..\link_executable -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -%fpm_path% run --target gomp_test -if errorlevel 1 exit 1 - - -cd ..\fortran_includes -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - - -cd ..\c_includes -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - - -cd ..\c_header_only -if errorlevel 1 exit 1 - -del /q /f build -%fpm_path% build -if errorlevel 1 exit 1 - -cd ..\.. diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 647c57a..ffcd9c2 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -1,102 +1,98 @@ #!/bin/bash set -ex -cd $(dirname $0)/../fpm +cd "$(dirname $0)/.." -fpm build $@ - -# Run fpm executable -fpm run $@ -fpm run $@ -- --version -fpm run $@ -- --help - -# Run tests -rm -rf fpm_scratch_*/ -fpm test $@ -rm -rf fpm_scratch_*/ - -f_fpm_path="$(fpm run $@ --runner echo)" - -# Let fpm build itself -"${f_fpm_path}" build - -# Install fpm into local directory -"${f_fpm_path}" install --prefix "$PWD/_dist" --no-rebuild +if [ "$1" ]; then + fpm="$1" +else + fpm=fpm +fi # Build example packages -cd ../example_packages/ +pushd example_packages/ rm -rf ./*/build -cd hello_world - -"${f_fpm_path}" build -"${f_fpm_path}" run --target hello_world -"${f_fpm_path}" run - -cd ../hello_fpm -"${f_fpm_path}" build -"${f_fpm_path}" run --target hello_fpm - -cd ../circular_test -"${f_fpm_path}" build - -cd ../circular_example -"${f_fpm_path}" build - -cd ../hello_complex -"${f_fpm_path}" build -"${f_fpm_path}" test -"${f_fpm_path}" run --target say_Hello -"${f_fpm_path}" run --target say_goodbye -"${f_fpm_path}" test --target greet_test -"${f_fpm_path}" test --target farewell_test - -cd ../hello_complex_2 -"${f_fpm_path}" build -"${f_fpm_path}" run --target say_hello_world -"${f_fpm_path}" run --target say_goodbye -"${f_fpm_path}" test --target greet_test -"${f_fpm_path}" test --target farewell_test - -cd ../with_examples -"${f_fpm_path}" build -"${f_fpm_path}" run --example --target demo-prog -"${f_fpm_path}" run --target demo-prog - -cd ../auto_discovery_off -"${f_fpm_path}" build -"${f_fpm_path}" run --target auto_discovery_off -"${f_fpm_path}" test --target my_test +pushd hello_world +"$fpm" build +"$fpm" run --target hello_world +"$fpm" run +popd + +pushd hello_fpm +"$fpm" build +"$fpm" run --target hello_fpm +popd + +pushd circular_test +"$fpm" build +popd + +pushd circular_example +"$fpm" build +popd + +pushd hello_complex +"$fpm" build +"$fpm" test +"$fpm" run --target say_Hello +"$fpm" run --target say_goodbye +"$fpm" test --target greet_test +"$fpm" test --target farewell_test +popd + +pushd hello_complex_2 +"$fpm" build +"$fpm" run --target say_hello_world +"$fpm" run --target say_goodbye +"$fpm" test --target greet_test +"$fpm" test --target farewell_test +popd + +pushd with_examples +"$fpm" build +"$fpm" run --example --target demo-prog +"$fpm" run --target demo-prog +popd + +pushd auto_discovery_off +"$fpm" build +"$fpm" run --target auto_discovery_off +"$fpm" test --target my_test test ! -x ./build/gfortran_*/app/unused test ! -x ./build/gfortran_*/test/unused_test - -cd ../with_c -"${f_fpm_path}" build -"${f_fpm_path}" run --target with_c - -cd ../submodules -"${f_fpm_path}" build - -cd ../program_with_module -"${f_fpm_path}" build -"${f_fpm_path}" run --target Program_with_module - -cd ../link_external -"${f_fpm_path}" build -"${f_fpm_path}" run --target link_external - -cd ../link_executable -"${f_fpm_path}" build -"${f_fpm_path}" run --target gomp_test - -cd ../fortran_includes -"${f_fpm_path}" build - -cd ../c_includes -"${f_fpm_path}" build - -cd ../c_header_only -"${f_fpm_path}" build +popd + +pushd with_c +"$fpm" build +"$fpm" run --target with_c +popd + +pushd submodules +"$fpm" build +popd + +pushd program_with_module +"$fpm" build +"$fpm" run --target Program_with_module +popd + +pushd link_executable +"$fpm" build +"$fpm" run --target gomp_test +popd + +pushd fortran_includes +"$fpm" build +popd + +pushd c_includes +"$fpm" build +popd + +pushd c_header_only +"$fpm" build +popd # Cleanup rm -rf ./*/build -- cgit v1.2.3