From 74b72f61dccc723bf0f8ba96e221b0cdaeef56ee Mon Sep 17 00:00:00 2001 From: Nils Hjelte Date: Sun, 1 Oct 2023 19:27:17 +0200 Subject: [PATCH] Refactor build workflow with template --- .github/workflows/build-and-test-template.yml | 207 ++++++++++++++++++ .github/workflows/build-and-test.yml | 179 +-------------- .github/workflows/publish-release-version.yml | 2 +- 3 files changed, 213 insertions(+), 175 deletions(-) create mode 100644 .github/workflows/build-and-test-template.yml diff --git a/.github/workflows/build-and-test-template.yml b/.github/workflows/build-and-test-template.yml new file mode 100644 index 0000000..8c28717 --- /dev/null +++ b/.github/workflows/build-and-test-template.yml @@ -0,0 +1,207 @@ +name: Build and test + +# README: +# +# The semantics for running shell commands in GitHub actions is non-obvious. Please read +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell +# before modifying this file. Our strategy is to rely on the built-in (unspecified) shell, and +# explicitly set the shell settings we want (with `set -eo pipefail`) at the beginning of any +# bash script. For more information on these settings, see `man bash`. +# +# GitHub Actions files can be difficult to modify with confidence, because testing changes often +# requires pushing to a branch and running CI remotely. To make this process easier, consider +# the following: +# +# 1) Use Visual Studio Code with the GitHub Actions Extension (github.vscode-github-actions). +# This allows you to check the validity of your action schema and syntax without pushing to a +# branch. +# 2) Use https://github.com/nektos/act to run your CI steps locally. Note this will only work with +# steps run on Linux platforms, as `act` is implemented with Docker containers. + +on: + workflow_call: + inputs: + build-type: + description: 'The build configuration type' + default: 'debug' + required: false + type: string + +jobs: + # build-devcontainer-linux: + # name: "Build and test: ${{ matrix.host.os }}/${{ inputs.build-type }}" + # strategy: + # fail-fast: false + # matrix: + # host: [ + # { type: linux, os: ubuntu-latest, + # build-options: "-v --build-tests -Xswiftc -enable-testing", + # test-options: "-v --enable-code-coverage" + # } + # ] + # configuration: [ "debug", "release" ] + + # runs-on: ${{ matrix.host.os }} + # steps: + # - uses: actions/checkout@v3 + + # - uses: actions/cache@v3 + # with: + # path: .build + # key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} + # restore-keys: | + # ${{ runner.os }}-spm- + + # - name: Build and Test + # uses: devcontainers/ci@v0.3 + # with: + # runCmd: | + # set -eo pipefail + # swift package resolve + # .build/checkouts/Swifty-LLVM/Tools/make-pkgconfig.sh llvm.pc + # export PKG_CONFIG_PATH=$PWD + # swift build -c ${{ inputs.build-type }} ${{ matrix.host.build-options }} + # BUILD_DIR=$(swift build -c ${{ inputs.build-type }} --show-bin-path) + # echo "BUILD_DIR=$BUILD_DIR" >> $GITHUB_ENV + # # swift test -c ${{ inputs.build-type }} ${{ matrix.host.test-options }} | + # # tee testoutput.txt && ( + # # (grep -q "[.']EndToEndTests[/. ]test_" testoutput.txt && grep -q "[.']HyloTests[/. ]test_" testoutput.txt) || + # # (echo "error: generated tests failed to run; see + # # https://github.com/apple/swift-package-manager/issues/6595" && false) ) + + # # - name: Check code coverage + # # uses: mattpolzin/swift-codecov-action@0.7.3 + # # with: + # # SORT_ORDER: +cov + # # MINIMUM_COVERAGE: 84 + # # CODECOV_JSON: .build/${{ inputs.build-type }}/codecov/*.json + + + # - name: Upload Hylo LSP artifacts (${{ inputs.build-type }}) + # uses: actions/upload-artifact@v3 + # with: + # name: hylo-lsp-artifacts-linux + # path: | + # ${{ env.BUILD_DIR }}/hylo-lsp-client + # ${{ env.BUILD_DIR }}/hylo-lsp-server + + build-native-macos: + name: "Build and test: ${{ matrix.host.os }}/${{ inputs.build-type }}" + strategy: + fail-fast: false + matrix: + host: [ + { + type: macos, os: macos-13, + build-options: "--build-tests -Xswiftc -enable-testing", + # No coverage support on MacOS + test-options: "-v" + } + ] + swift: [ + { version: "5.9" } + ] + # configuration: [ $BUILD_TYPE ] + # configuration: [ "debug", "release" ] + + runs-on: ${{ matrix.host.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: 'true' + + - name: Setup swift + uses: swift-actions/setup-swift@v1 + with: + swift-version: ${{ matrix.swift.version }} + + - run: swift --version + + - name: Setup LLVM + uses: KyleMayes/install-llvm-action@v1 + with: + version: "15.0" + + - run: llvm-config --version + + - name: Generate LLVM pkgconfig file + run: | + set -eo pipefail + cd hylo + swift package resolve + .build/checkouts/Swifty-LLVM/Tools/make-pkgconfig.sh llvm.pc + cat llvm.pc + + - name: Build (${{ inputs.build-type }}) + id: build + run: | + set -eo pipefail + export PKG_CONFIG_PATH=$PWD/hylo + swift build -c ${{ inputs.build-type }} ${{ matrix.host.build-options }} + BUILD_DIR=$(swift build -c ${{ inputs.build-type }} --show-bin-path) + echo "BUILD_DIR=$BUILD_DIR" >> $GITHUB_ENV + # - name: Test (${{ inputs.build-type }}) + # run: | + # set -eo pipefail + # export PKG_CONFIG_PATH=$PWD/hylo + # swift test -c ${{ inputs.build-type }} ${{ matrix.host.test-options }} | + # tee testoutput.txt && ( + # (grep -q "[.']EndToEndTests[/. ]test_" testoutput.txt && grep -q "[.']HyloTests[/. ]test_" testoutput.txt) || + # (echo "error: generated tests failed to run; see + # https://github.com/apple/swift-package-manager/issues/6595" && false) ) + + - name: Upload Hylo LSP artifacts (${{ inputs.build-type }}) + uses: actions/upload-artifact@v3 + with: + name: hylo-lsp-artifacts-mac + path: | + ${{ env.BUILD_DIR }}/hylo-lsp-client + ${{ env.BUILD_DIR }}/hylo-lsp-server + + # build-native-windows: + # name: "Build and test: windows-latest/release" + # strategy: + # fail-fast: false + # runs-on: windows-latest + # steps: + # - name: Setup swift + # uses: compnerd/gha-setup-swift@main + # with: + # branch: swift-5.8.1-release + # tag: 5.8.1-RELEASE + + # - uses: actions/checkout@v3 + + # - name: Swift version + # run: swift --version + + # - name: Set up LLVM 15.0.6 + # run: | + # curl.exe -L -O -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"https://github.com/c3lang/win-llvm/releases/download/llvm_15_0_6/llvm-15.0.6-windows-x86-msvc17-msvcrt.7z + # 7z x llvm-15.0.6-windows-x86-msvc17-msvcrt.7z -oC:\ + # Add-Content $env:GITHUB_PATH 'C:\llvm-15.0.6-windows-x86-msvc17-msvcrt\bin' + + # - name: Copy LLVM's include and lib to include and lib folder of MSVC + # run: | + # xcopy c:\llvm-15.0.6-windows-x86-msvc17-msvcrt\include\*.* c:\program" "files\microsoft" "visual" "studio\2022\enterprise\vc\tools\msvc\${{ env.VCToolsVersion }}\include\ /s /h + # xcopy c:\llvm-15.0.6-windows-x86-msvc17-msvcrt\lib\*.* c:\program" "files\microsoft" "visual" "studio\2022\enterprise\vc\tools\msvc\${{ env.VCToolsVersion }}\lib\x64\ /s /h + + # - run: llvm-config --version + + # - name: Build support library + # run: clang -c ./Library/Hylo/LibC.c -o HyloLibC.lib + + # - name: Copy support library + # run: xcopy HyloLibC.lib c:\program" "files\microsoft" "visual" "studio\2022\enterprise\vc\tools\msvc\${{ env.VCToolsVersion }}\lib\x64\ + + # - name: Build (Release) + # id: build + # continue-on-error: true + # run: swift build -v -c release + + # - name: Retry on failure + # continue-on-error: false + # if: steps.build.outcome != 'success' + # run: swift build -v -c release + diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 0e4722c..387efa4 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -19,15 +19,7 @@ name: Build and test # steps run on Linux platforms, as `act` is implemented with Docker containers. on: - workflow_call: - inputs: - build-type: - description: 'The build configuration type' - default: 'debug' - required: false - type: string push: - # tags: ["v*.*.*"] branches: [ main ] paths-ignore: - "Docs/**" @@ -47,6 +39,11 @@ env: BUILD_TYPE: ${{ inputs.build-type || 'debug' }} jobs: + build: + uses: ./.github/workflows/build-and-test-template.yml + with: + build-type: debug + # upload-common-articats: # name: Upload common artifacts # runs-on: ubuntu-latest @@ -64,169 +61,3 @@ jobs: # LICENSE # hylo/Library/Hylo - # build-devcontainer-linux: - # name: "Build and test: ${{ matrix.host.os }}/${{ env.BUILD_TYPE }}" - # strategy: - # fail-fast: false - # matrix: - # host: [ - # { type: linux, os: ubuntu-latest, - # build-options: "-v --build-tests -Xswiftc -enable-testing", - # test-options: "-v --enable-code-coverage" - # } - # ] - # configuration: [ "debug", "release" ] - - # runs-on: ${{ matrix.host.os }} - # steps: - # - uses: actions/checkout@v3 - - # - uses: actions/cache@v3 - # with: - # path: .build - # key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} - # restore-keys: | - # ${{ runner.os }}-spm- - - # - name: Build and Test - # uses: devcontainers/ci@v0.3 - # with: - # runCmd: | - # set -eo pipefail - # swift package resolve - # .build/checkouts/Swifty-LLVM/Tools/make-pkgconfig.sh llvm.pc - # export PKG_CONFIG_PATH=$PWD - # swift build -c ${{ env.BUILD_TYPE }} ${{ matrix.host.build-options }} - # swift test -c ${{ env.BUILD_TYPE }} ${{ matrix.host.test-options }} | - # tee testoutput.txt && ( - # (grep -q "[.']EndToEndTests[/. ]test_" testoutput.txt && grep -q "[.']HyloTests[/. ]test_" testoutput.txt) || - # (echo "error: generated tests failed to run; see - # https://github.com/apple/swift-package-manager/issues/6595" && false) ) - - # - name: Check code coverage - # uses: mattpolzin/swift-codecov-action@0.7.3 - # with: - # SORT_ORDER: +cov - # MINIMUM_COVERAGE: 84 - # CODECOV_JSON: .build/${{ env.BUILD_TYPE }}/codecov/*.json - - build-native-macos: - name: "Build and test: ${{ matrix.host.os }}/${{ env.BUILD_TYPE }}" - strategy: - fail-fast: false - matrix: - host: [ - { - type: macos, os: macos-13, - build-options: "--build-tests -Xswiftc -enable-testing", - # No coverage support on MacOS - test-options: "-v" - } - ] - swift: [ - { version: "5.9" } - ] - # configuration: [ $BUILD_TYPE ] - # configuration: [ "debug", "release" ] - - runs-on: ${{ matrix.host.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: 'true' - - - name: Setup swift - uses: swift-actions/setup-swift@v1 - with: - swift-version: ${{ matrix.swift.version }} - - - run: swift --version - - - name: Setup LLVM - uses: KyleMayes/install-llvm-action@v1 - with: - version: "15.0" - - - run: llvm-config --version - - - name: Generate LLVM pkgconfig file - run: | - set -eo pipefail - cd hylo - swift package resolve - .build/checkouts/Swifty-LLVM/Tools/make-pkgconfig.sh llvm.pc - cat llvm.pc - - - name: Build (${{ env.BUILD_TYPE }}) - id: build - run: | - set -eo pipefail - export PKG_CONFIG_PATH=$PWD/hylo - swift build -c ${{ env.BUILD_TYPE }} ${{ matrix.host.build-options }} - BUILD_DIR=$(swift build -c ${{ env.BUILD_TYPE }} --show-bin-path) - echo "BUILD_DIR=$BUILD_DIR" >> $GITHUB_ENV - # - name: Test (${{ env.BUILD_TYPE }}) - # run: | - # set -eo pipefail - # export PKG_CONFIG_PATH=$PWD/hylo - # swift test -c ${{ env.BUILD_TYPE }} ${{ matrix.host.test-options }} | - # tee testoutput.txt && ( - # (grep -q "[.']EndToEndTests[/. ]test_" testoutput.txt && grep -q "[.']HyloTests[/. ]test_" testoutput.txt) || - # (echo "error: generated tests failed to run; see - # https://github.com/apple/swift-package-manager/issues/6595" && false) ) - - - name: Upload Hylo LSP artifacts (${{ env.BUILD_TYPE }}) - uses: actions/upload-artifact@v3 - with: - name: hylo-lsp-artifacts-mac - path: | - ${{ env.BUILD_DIR }}/hylo-lsp-client - ${{ env.BUILD_DIR }}/hylo-lsp-server - - # build-native-windows: - # name: "Build and test: windows-latest/release" - # strategy: - # fail-fast: false - # runs-on: windows-latest - # steps: - # - name: Setup swift - # uses: compnerd/gha-setup-swift@main - # with: - # branch: swift-5.8.1-release - # tag: 5.8.1-RELEASE - - # - uses: actions/checkout@v3 - - # - name: Swift version - # run: swift --version - - # - name: Set up LLVM 15.0.6 - # run: | - # curl.exe -L -O -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"https://github.com/c3lang/win-llvm/releases/download/llvm_15_0_6/llvm-15.0.6-windows-x86-msvc17-msvcrt.7z - # 7z x llvm-15.0.6-windows-x86-msvc17-msvcrt.7z -oC:\ - # Add-Content $env:GITHUB_PATH 'C:\llvm-15.0.6-windows-x86-msvc17-msvcrt\bin' - - # - name: Copy LLVM's include and lib to include and lib folder of MSVC - # run: | - # xcopy c:\llvm-15.0.6-windows-x86-msvc17-msvcrt\include\*.* c:\program" "files\microsoft" "visual" "studio\2022\enterprise\vc\tools\msvc\${{ env.VCToolsVersion }}\include\ /s /h - # xcopy c:\llvm-15.0.6-windows-x86-msvc17-msvcrt\lib\*.* c:\program" "files\microsoft" "visual" "studio\2022\enterprise\vc\tools\msvc\${{ env.VCToolsVersion }}\lib\x64\ /s /h - - # - run: llvm-config --version - - # - name: Build support library - # run: clang -c ./Library/Hylo/LibC.c -o HyloLibC.lib - - # - name: Copy support library - # run: xcopy HyloLibC.lib c:\program" "files\microsoft" "visual" "studio\2022\enterprise\vc\tools\msvc\${{ env.VCToolsVersion }}\lib\x64\ - - # - name: Build (Release) - # id: build - # continue-on-error: true - # run: swift build -v -c release - - # - name: Retry on failure - # continue-on-error: false - # if: steps.build.outcome != 'success' - # run: swift build -v -c release - diff --git a/.github/workflows/publish-release-version.yml b/.github/workflows/publish-release-version.yml index 861f1e1..0aedb35 100644 --- a/.github/workflows/publish-release-version.yml +++ b/.github/workflows/publish-release-version.yml @@ -6,7 +6,7 @@ on: jobs: build: - uses: ./.github/workflows/build-and-test.yml + uses: ./.github/workflows/build-and-test-template.yml with: build-type: release publish-release: