|
| 1 | +# This workflow tests the PiWind expected results from 'tests/ci/expected' |
| 2 | +# its tested using 'tests/test_piwind_integration.py' which runs a set of |
| 3 | +# checks using the OasisLMF API client |
| 4 | +# vs the docker-compose file `docker-compose.yml` and ENV variables |
| 5 | +# SERVER_IMG: server image name "coreoasis/api_server" |
| 6 | +# SERVER_TAG: server image tag "latest" |
| 7 | +# WORKER_IMG: worker image name "coreoasis/model_worker" |
| 8 | +# WORKER_TAG: worker image tag ""latest |
| 9 | +# |
| 10 | + |
| 11 | +name: PiWind Integration |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + server_image: |
| 17 | + description: 'Server image [coreoasis/api_server]' |
| 18 | + required: false |
| 19 | + default: 'coreoasis/model_worker' |
| 20 | + server_tag: |
| 21 | + description: 'Server tag [semvar]' |
| 22 | + required: false |
| 23 | + default: 'latest' |
| 24 | + worker_image: |
| 25 | + description: 'Worker image [coreoasis/model_worker]' |
| 26 | + required: false |
| 27 | + default: 'coreoasis/model_worker' |
| 28 | + worker_tag: |
| 29 | + description: 'Worker image [semvar]' |
| 30 | + required: false |
| 31 | + default: 'latest' |
| 32 | + debug_mode: |
| 33 | + description: 'Enable verbose logging for containers [0, 1]' |
| 34 | + required: false |
| 35 | + default: '0' |
| 36 | + |
| 37 | + # If set build a piwind worker with / branch package |
| 38 | + # otherwise use the default worker image |
| 39 | + oasislmf_branch: |
| 40 | + description: "Branch from oasislmf to test piwind with [git ref]" |
| 41 | + required: false |
| 42 | + oasislmf_package: |
| 43 | + description: "Oasislmf package build to test [pkg_filename]" |
| 44 | + required: false |
| 45 | + |
| 46 | + workflow_call: |
| 47 | + inputs: |
| 48 | + piwind_branch: |
| 49 | + description: 'PiWind branch to test' |
| 50 | + type: string |
| 51 | + server_image: |
| 52 | + description: 'Server image [coreoasis/api_server]' |
| 53 | + required: false |
| 54 | + type: string |
| 55 | + server_tag: |
| 56 | + description: 'Server tag [semvar]' |
| 57 | + required: false |
| 58 | + type: string |
| 59 | + worker_image: |
| 60 | + description: 'Worker image [coreoasis/model_worker]' |
| 61 | + required: false |
| 62 | + type: string |
| 63 | + worker_tag: |
| 64 | + description: 'Worker image [semvar]' |
| 65 | + required: false |
| 66 | + type: string |
| 67 | + debug_mode: |
| 68 | + description: 'Enable verbose logging for containers [0, 1]' |
| 69 | + required: false |
| 70 | + type: string |
| 71 | + |
| 72 | + # If set build a piwind worker with / branch package |
| 73 | + # otherwise use the default worker image |
| 74 | + oasislmf_branch: |
| 75 | + description: "Branch from oasislmf to test piwind with [git ref]" |
| 76 | + required: false |
| 77 | + type: string |
| 78 | + oasislmf_package: |
| 79 | + description: "Oasislmf package build to test [pkg_filename]" |
| 80 | + required: false |
| 81 | + type: string |
| 82 | + |
| 83 | +jobs: |
| 84 | + check_results: |
| 85 | + runs-on: ubuntu-latest |
| 86 | + env: |
| 87 | + DOCKERFILE: 'docker/Dockerfile.piwind_worker' |
| 88 | + PIWIND_BRANCH: ${{ github.ref_name }} |
| 89 | + SERVER_IMG: 'coreoasis/api_server' |
| 90 | + SERVER_TAG: 'latest' |
| 91 | + WORKER_IMG: 'coreoasis/model_worker' |
| 92 | + WORKER_TAG: 'latest' |
| 93 | + DEBUG: 0 |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Set inputs |
| 97 | + run: | |
| 98 | + [[ -z "${{ inputs.piwind_branch }}" ]] || echo "PIWIND_BRANCH=${{ inputs.piwind_branch }}" >> $GITHUB_ENV |
| 99 | + [[ -z "${{ inputs.server_image }}" ]] || echo "SERVER_IMG=${{ inputs.server_image }}" >> $GITHUB_ENV |
| 100 | + [[ -z "${{ inputs.server_tag }}" ]] || echo "SERVER_TAG=${{ inputs.server_tag }}" >> $GITHUB_ENV |
| 101 | + [[ -z "${{ inputs.worker_image }}" ]] || echo "WORKER_IMG=${{ inputs.worker_image }}" >> $GITHUB_ENV |
| 102 | + [[ -z "${{ inputs.worker_tag }}" ]] || echo "WORKER_TAG=${{ inputs.worker_tag }}" >> $GITHUB_ENV |
| 103 | + [[ -z "${{ inputs.debug_mode }}" ]] || echo "DEBUG=${{ inputs.debug_mode }}" >> $GITHUB_ENV |
| 104 | +
|
| 105 | + - name: clone PiWind repository |
| 106 | + uses: actions/checkout@v3 |
| 107 | + with: |
| 108 | + repository: OasisLMF/OasisPiWind |
| 109 | + ref: ${{ env.PIWIND_BRANCH }} |
| 110 | + |
| 111 | + - name: Set build arg |
| 112 | + if: inputs.oasislmf_package != '' || inputs.oasislmf_branch != '' |
| 113 | + run: | |
| 114 | + if [[ -n "${{ inputs.oasislmf_package }}" && -n "${{ inputs.oasislmf_branch }}" ]]; then |
| 115 | + echo "set either 'oasislmf_package' or 'oasislmf_branch' not both" |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: Set up Docker Buildx |
| 120 | + if: inputs.oasislmf_package != '' || inputs.oasislmf_branch != '' |
| 121 | + uses: docker/setup-buildx-action@v2 |
| 122 | + |
| 123 | + - name: replace default image with input |
| 124 | + if: inputs.oasislmf_package != '' || inputs.oasislmf_branch != '' |
| 125 | + run: sed -i "/FROM /c\FROM ${{ env.WORKER_IMG }}:${{ env.WORKER_TAG }}" ${{ env.DOCKERFILE }} |
| 126 | + |
| 127 | + - name: Build and push |
| 128 | + if: inputs.oasislmf_package != '' || inputs.oasislmf_branch != '' |
| 129 | + uses: docker/build-push-action@v3 |
| 130 | + with: |
| 131 | + file: ${{ env.DOCKERFILE }} |
| 132 | + context: . |
| 133 | + load: true # needed for local testing |
| 134 | + push: false |
| 135 | + tags: "${{ env.WORKER_IMG }}:piwind-test-${{ github.sha }}" |
| 136 | + build-args: | |
| 137 | + oasislmf_package=${{ inputs.oasislmf_package }} |
| 138 | + oasislmf_branch=${{ inputs.oasislmf_branch }} |
| 139 | +
|
| 140 | + - name: Override Worker image env |
| 141 | + if: inputs.oasislmf_package != '' || inputs.oasislmf_branch != '' |
| 142 | + run: echo "WORKER_TAG=piwind-test-${{ github.sha }}" >> $GITHUB_ENV |
| 143 | + |
| 144 | + - name: Setup Python |
| 145 | + uses: actions/setup-python@v4 |
| 146 | + with: |
| 147 | + python-version: '3.10' |
| 148 | + |
| 149 | + - name: install test deps |
| 150 | + run: | |
| 151 | + python -m pip install --upgrade pip |
| 152 | + pip install pip-tools |
| 153 | + pip-compile tests/requirements.in -o tests/requirements.txt |
| 154 | + pip install -r tests/requirements.txt |
| 155 | +
|
| 156 | + - name: Run Checks |
| 157 | + run: pytest -v --use-running-containers |
| 158 | + |
| 159 | + - name: Create docker logs |
| 160 | + if: always() |
| 161 | + run: | |
| 162 | + mkdir -p docker_logs |
| 163 | + docker-compose ps | tail -n +3 | awk '{print $1}' | xargs -I CONTAINER bash -c "docker logs CONTAINER > docker_logs/CONTAINER.log" |
| 164 | + docker-compose down |
| 165 | +
|
| 166 | + - name: Store docker logs |
| 167 | + if: always() |
| 168 | + uses: actions/upload-artifact@v3 |
| 169 | + with: |
| 170 | + name: docker-logs |
| 171 | + path: ./docker_logs |
| 172 | + retention-days: 3 |
| 173 | + |
| 174 | + - name: Store result data |
| 175 | + if: always() |
| 176 | + uses: actions/upload-artifact@v3 |
| 177 | + with: |
| 178 | + name: output-tars |
| 179 | + path: ./tests/result/ |
| 180 | + retention-days: 3 |
0 commit comments