|
| 1 | +# Template workflow (Github Workflows). VT example. |
| 2 | + |
| 3 | +# Build and test a project in all available setup configurations provided by DARMA-taking/workflows. |
| 4 | +# See also: Azure Pipelines version at ./azure/pipelines/build-and-test.yml |
| 5 | + |
| 6 | +name: PR tests |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - '*' # master |
| 12 | + pull_request: |
| 13 | + branches: |
| 14 | + - '*' |
| 15 | + |
| 16 | +env: |
| 17 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + CI_REPO: DARMA-tasking/workflows |
| 19 | + CI_BRANCH: 2-implement-common-docker-containers # master |
| 20 | + |
| 21 | +jobs: |
| 22 | + get-matrix: |
| 23 | + name: Get matrix |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Get matrix |
| 27 | + id: get-matrix |
| 28 | + run: | |
| 29 | + wget https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/matrix/github.json |
| 30 | + matrix=$(cat github.json | jq '.matrix') |
| 31 | + echo "runner=$(echo $matrix)" >> $GITHUB_OUTPUT |
| 32 | + outputs: |
| 33 | + matrix: ${{ steps.get-matrix.outputs.runner }} |
| 34 | + |
| 35 | + run: |
| 36 | + name: Run ${{ matrix.runner.name }} |
| 37 | + runs-on: ${{ matrix.runner.runs-on }} |
| 38 | + needs: get-matrix |
| 39 | + strategy: |
| 40 | + fail-fast: false |
| 41 | + matrix: |
| 42 | + runner: ${{ fromJson(needs.get-matrix.outputs.matrix ) }} |
| 43 | + steps: |
| 44 | + - name: Checkout |
| 45 | + uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Display configuration |
| 48 | + run: | |
| 49 | + echo "Environment=${{ matrix.runner.name }}" |
| 50 | + echo "Runner=${{ matrix.runner.runs-on }}" |
| 51 | + if [ "${{ matrix.runner.image }}" != "" ] |
| 52 | + then |
| 53 | + echo "> With Docker Image=${{ matrix.runner.image }}" |
| 54 | + else |
| 55 | + echo "> With Runner Setup=${{ matrix.runner.setup }}" |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Set up dependencies |
| 59 | + run: | |
| 60 | + if [[ "${{ matrix.runner.image }}" == "" ]]; then |
| 61 | + echo "::group::Setup in runner" |
| 62 | + echo "Set setup permissions..." |
| 63 | + sudo mkdir -p /opt |
| 64 | + sudo chown $(whoami) /opt |
| 65 | + wget -O setup.sh https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/scripts/setup-${{ matrix.runner.setup }}.sh |
| 66 | + chmod +x setup.sh |
| 67 | + export WF_SETUP_ID=${{ matrix.runner.setup }} |
| 68 | + ./setup.sh |
| 69 | + echo "::endgroup::" |
| 70 | + elif [[ "${{ matrix.runner.image }}" != "" ]]; then |
| 71 | + echo "::group::Pull Docker image" |
| 72 | + docker image pull ${{ matrix.runner.image }} |
| 73 | + echo "::endgroup::" |
| 74 | + fi |
| 75 | +
|
| 76 | + |
| 77 | + # - name: Run (example) |
| 78 | + # run: | |
| 79 | + # CMD="uname -a" |
| 80 | + # if [[ "${{ matrix.runner.image }}" == "" ]] |
| 81 | + # then |
| 82 | + # $CMD |
| 83 | + # else |
| 84 | + # docker run ${{ matrix.runner.image }} $CMD |
| 85 | + # fi |
| 86 | + |
| 87 | + # - name: Extract timestamps for caching |
| 88 | + # run: | |
| 89 | + # mkdir -p /opt/scripts |
| 90 | + # cd /opt/scripts |
| 91 | + # wget https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/scripts/runner/set-variable.sh && chmod +x set-variable.sh |
| 92 | + # wget https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/scripts/runner/set-timestamps.sh && chmod +x set-timestamps.sh |
| 93 | + # ./set-timestamps.sh |
| 94 | + |
| 95 | + - name: Setup build cache (vt) |
| 96 | + run: | |
| 97 | + echo "TODO: implement cache usage if required by your project" |
| 98 | +
|
| 99 | + - name: PR tests |
| 100 | + run: | |
| 101 | + FOO_SRC_DIR=${{ github.workspace }} |
| 102 | + FOO_BUILD_DIR=/opt/foo/build |
| 103 | + if [[ "${{ matrix.runner.image }}" != "" ]]; then |
| 104 | + FOO_SRC_DIR=opt/foo/src |
| 105 | + fi |
| 106 | + CMD=' |
| 107 | + cd $FOO_SRC_DIR; \ |
| 108 | + chmod +x build.sh; \ |
| 109 | + \ |
| 110 | + FOO_BUILD_DIR=$FOO_BUILD_DIR \ |
| 111 | + FOO_COVERAGE_ENABLED=ON \ |
| 112 | + FOO_RUN_TESTS=ON \ |
| 113 | + build.sh;' |
| 114 | +
|
| 115 | + echo "Running ${CMD}" |
| 116 | +
|
| 117 | + if [[ "${{ matrix.runner.image }}" == "" ]]; then |
| 118 | + bash -c "$CMD"; |
| 119 | + else |
| 120 | + docker run \ |
| 121 | + --name test-container \ |
| 122 | + -w $FOO_SRC_DIR \ |
| 123 | + -v ${{ github.workspace }} :/opt/foo/src \ |
| 124 | + -v /opt/foo/build:/opt/foo/build \ |
| 125 | + -v /opt/foo/output:/opt/foo/output \ |
| 126 | + -e CI="1" \ |
| 127 | + -e CMAKE_CXX_STANDARD="17" \ |
| 128 | + -e CMAKE_BUILD_TYPE="Release" \ |
| 129 | + ${{ matrix.runner.image }} \ |
| 130 | + bash -c "$CMD" |
| 131 | + exit $(docker container inspect --format '{{.State.ExitCode}}' test-container) |
| 132 | + fi |
| 133 | +
|
| 134 | + # - name: Build and test |
| 135 | + # TODO: Build an test step. |
| 136 | + # > Option 1: Docker image (Environment Setup="docker") WIP |
| 137 | + # - pull the docker image |
| 138 | + # - build & Test using `docker exec [container] build_and_test.sh` for example or by using an inner build_and_test docker image |
| 139 | + # - (TODO: copy artifacts using a volume) |
| 140 | + |
| 141 | + # > Option 2: Current runner (Environment Setup="local") (Future for some macos) |
| 142 | + # - setup dependencies here directly |
| 143 | + # (Here a work needs to be done to determine how to get the dependencies script. It might be shared by the workflows repo and put in matrix) |
| 144 | + # - build & Test using build_and_test.sh |
| 145 | + |
| 146 | + # - name: Upload artifacts |
| 147 | + |
| 148 | + # - name: Report test results |
| 149 | + # note: (as in vt-tv or LBAF) |
| 150 | + |
| 151 | + # - name: Report coverage |
0 commit comments