|
| 1 | +name: linux-qe-template |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + trigger-workflow-run-id: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + qe-type: |
| 10 | + description: type of test; allowed values e2e or integration |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + preset: |
| 14 | + description: preset type only required if qe-type is e2e |
| 15 | + type: string |
| 16 | + |
| 17 | +jobs: |
| 18 | + linux-qe: |
| 19 | + runs-on: [self-hosted, linux, testing-farm] |
| 20 | + permissions: |
| 21 | + statuses: write # needed to update commit status (pending/failure/sucess) |
| 22 | + checks: write # as documented in https://github.com/mikepenz/action-junit-report?tab=readme-ov-file#pr-run-permissions |
| 23 | + steps: |
| 24 | + - name: prepare env |
| 25 | + run: | |
| 26 | + sudo yum install podman openssh-server -y |
| 27 | +
|
| 28 | + commit_sha=$(cat gh_context.json | jq -r '.event.after') |
| 29 | + if [[ -z "${commit_sha}" ]] || [[ "${commit_sha}" == null ]]; then |
| 30 | + # on first PR creation .event.after is empty, then .sha is used as commit instead |
| 31 | + commit_sha=$(cat gh_context.json | jq -r '.event.pull_request.head.sha') |
| 32 | + fi |
| 33 | + echo "commit_sha=${commit_sha}" >> "$GITHUB_ENV" |
| 34 | + mkdir ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 35 | + cd ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 36 | +
|
| 37 | + # the target can only be accessed through a bastion (which can only be accessed from self-hosted runner) |
| 38 | + # as so we need to map the ssh-agent from the host to the containers used to access the target host |
| 39 | + ssh-keygen -t rsa -N '' -f id_rsa -q |
| 40 | + eval $(ssh-agent -s) |
| 41 | + echo $SSH_AUTH_SOCK > ssh_auth_sock |
| 42 | + echo $SSH_AGENT_PID > ssh_agent_pid |
| 43 | + ssh-add id_rsa |
| 44 | +
|
| 45 | + - name: reserve machine from testing farm |
| 46 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 47 | + env: |
| 48 | + TESTING_FARM_API_TOKEN: ${{ secrets.TESTING_FARM_API_TOKEN }} |
| 49 | + PULL_SECRET: ${{ secrets.PULL_SECRET }} |
| 50 | + run: | |
| 51 | + echo "${PULL_SECRET}" > pull-secret |
| 52 | + export TESTING_FARM_API_TOKEN=${TESTING_FARM_API_TOKEN} |
| 53 | + testing-farm reserve --compose Fedora-40 --duration 240 --arch aarch64 --hardware memory='>= 12 GB' --hardware virtualization.is-supported='true' --ssh-public-key id_rsa.pub --no-autoconnect | tee info |
| 54 | + machine=`tail -n 1 info` |
| 55 | + echo ${machine##*@} > host |
| 56 | + echo crctest > username |
| 57 | + echo proxy > bastion_username |
| 58 | + echo testing-farm.io > bastion_host |
| 59 | + request=`sed -n '4p' info` |
| 60 | + echo ${request:1} > requestid |
| 61 | +
|
| 62 | + # connect to the reserved machine, create a non-root user for testing |
| 63 | + ${machine:1} |
| 64 | + new_user=crctest |
| 65 | + useradd $new_user |
| 66 | + echo "$new_user:redhat" | chpasswd |
| 67 | + usermod -aG wheel $new_user |
| 68 | + echo "$new_user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/crctest-users |
| 69 | + mkdir -p /home/$new_user/.ssh |
| 70 | + cp /root/.ssh/authorized_keys /home/$new_user/.ssh/ |
| 71 | + chown $new_user /home/$new_user/.ssh/authorized_keys |
| 72 | + exit |
| 73 | + |
| 74 | + - name: Download linux binary |
| 75 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 76 | + uses: actions/download-artifact@v4 |
| 77 | + with: |
| 78 | + name: linux-binary |
| 79 | + run-id: ${{inputs.trigger-workflow-run-id}} |
| 80 | + github-token: ${{ github.token }} |
| 81 | + |
| 82 | + - name: Download qe oci image |
| 83 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 84 | + id: download-qe-oci-image-artifact |
| 85 | + uses: actions/download-artifact@v4 |
| 86 | + with: |
| 87 | + name: crc-${{inputs.qe-type}}-linux-arm64 |
| 88 | + run-id: ${{inputs.trigger-workflow-run-id}} |
| 89 | + github-token: ${{ github.token }} |
| 90 | + |
| 91 | + - name: Add status to the PR check |
| 92 | + run: | |
| 93 | + set -xuo |
| 94 | + # Status msg |
| 95 | + data="{\"state\":\"pending\"" |
| 96 | + data="${data},\"description\":\"Running ${{inputs.qe-type}}-${{inputs.preset}} on Linux ARM64\"" |
| 97 | + data="${data},\"context\":\"${{ env.status_context }}\"" |
| 98 | + data="${data},\"target_url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" |
| 99 | + # Create status by API call |
| 100 | + curl -L -v -X POST \ |
| 101 | + -H "Accept: application/vnd.github+json" \ |
| 102 | + -H "Authorization: Bearer ${{ github.token }}" \ |
| 103 | + https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.commit_sha }} \ |
| 104 | + -d "${data}" |
| 105 | +
|
| 106 | + - name: Install CRC on host |
| 107 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 108 | + run: | |
| 109 | + podman run --rm -d --privileged --name crc-linux-install-${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} \ |
| 110 | + -e TARGET_HOST=$(cat host) \ |
| 111 | + -e TARGET_HOST_USERNAME=$(cat username) \ |
| 112 | + -e TARGET_HOST_KEY_PATH=/data/id_rsa \ |
| 113 | + -e BASTION_HOST_USERNAME=$(cat bastion_username) \ |
| 114 | + -e BASTION_HOST=$(cat bastion_host) \ |
| 115 | + -e TARGET_FOLDER=crc-support \ |
| 116 | + -e TARGET_CLEANUP='false' \ |
| 117 | + -e OUTPUT_FOLDER=/data \ |
| 118 | + -e DEBUG='true' \ |
| 119 | + -e SSH_AUTH_SOCK=$(cat ssh_auth_sock) \ |
| 120 | + -v "$(cat ssh_auth_sock):$(cat ssh_auth_sock)" \ |
| 121 | + -v ${PWD}:/data:z \ |
| 122 | + -v ${PWD}/crc:/opt/crc-support/crc:z \ |
| 123 | + quay.io/crc-org/ci-crc-support:v2.0.0-dev-linux crc-support/run.sh \ |
| 124 | + -targetPath "/root/crc-support" \ |
| 125 | + -install 'true' \ |
| 126 | + -aName 'crc' \ |
| 127 | + -freshEnv 'false' \ |
| 128 | + -download 'false' |
| 129 | + podman logs -f crc-linux-install-${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 130 | +
|
| 131 | + - name: Run CRC ${{inputs.qe-type}} test |
| 132 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 133 | + run: | |
| 134 | + # load image |
| 135 | + podman load -i crc-${{inputs.qe-type}}-linux-arm64.tar |
| 136 | + # run |
| 137 | + cmd="crc-qe/run.sh -junitFilename crc-${{inputs.qe-type}}-junit.xml -targetFolder crc-qe" |
| 138 | + if [[ "${{inputs.qe-type}}" == "e2e" ]]; then |
| 139 | + if [[ "${{inputs.preset}}" == "microshift" ]]; then |
| 140 | + cmd="${cmd} -e2eTagExpression '@story_microshift'" |
| 141 | + else |
| 142 | + cmd="${cmd} -e2eTagExpression '~@minimal && ~@story_microshift'" |
| 143 | + fi |
| 144 | + fi |
| 145 | + podman run --rm -d --privileged --name crc-${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} \ |
| 146 | + -e TARGET_HOST=$(cat host) \ |
| 147 | + -e TARGET_HOST_USERNAME=$(cat username) \ |
| 148 | + -e TARGET_HOST_KEY_PATH=/data/id_rsa \ |
| 149 | + -e BASTION_HOST_USERNAME=$(cat bastion_username) \ |
| 150 | + -e BASTION_HOST=$(cat bastion_host) \ |
| 151 | + -e TARGET_FOLDER=crc-qe \ |
| 152 | + -e TARGET_RESULTS=results \ |
| 153 | + -e OUTPUT_FOLDER=/data \ |
| 154 | + -e DEBUG=true \ |
| 155 | + -e SSH_AUTH_SOCK=$(cat ssh_auth_sock) \ |
| 156 | + -v "$(cat ssh_auth_sock):$(cat ssh_auth_sock)" \ |
| 157 | + -v $PWD/pull-secret:/opt/crc/pull-secret:z \ |
| 158 | + -v $PWD:/data:z \ |
| 159 | + quay.io/crcont/crc-${{inputs.qe-type}}:gh-linux-arm64 \ |
| 160 | + ${cmd} |
| 161 | + podman logs -f crc-${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 162 | +
|
| 163 | + - name: Test Report |
| 164 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 165 | + id: test-report |
| 166 | + uses: mikepenz/action-junit-report@v4 |
| 167 | + if: always() |
| 168 | + with: |
| 169 | + fail_on_failure: true |
| 170 | + include_passed: true |
| 171 | + detailed_summary: true |
| 172 | + require_tests: true |
| 173 | + report_paths: '**/*.xml' |
| 174 | + |
| 175 | + - name: Upload e2e results |
| 176 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 177 | + uses: actions/upload-artifact@v4 |
| 178 | + if: always() |
| 179 | + with: |
| 180 | + name: linux-${{inputs.qe-type}}-${{inputs.preset}} |
| 181 | + path: | |
| 182 | + **/*.xml |
| 183 | + **/*.results |
| 184 | + **/*.log |
| 185 | +
|
| 186 | + - name: Update status of the PR check |
| 187 | + if: always() |
| 188 | + run: | |
| 189 | + set -xuo |
| 190 | + # Status msg |
| 191 | + data="{\"state\":\"success\"" |
| 192 | + if [[ ${{steps.test-report.outcome}} != "success" ]]; then |
| 193 | + data="{\"state\":\"failure\"" |
| 194 | + fi |
| 195 | + data="${data},\"description\":\"Finished ${{inputs.qe-type}}-${{inputs.preset}} on Linux ARM64\"" |
| 196 | + data="${data},\"context\":\"${{ env.status_context }}\"" |
| 197 | + data="${data},\"target_url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" |
| 198 | + # Create status by API call |
| 199 | + curl -L -v -X POST \ |
| 200 | + -H "Accept: application/vnd.github+json" \ |
| 201 | + -H "Authorization: Bearer ${{ github.token }}" \ |
| 202 | + https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.commit_sha }} \ |
| 203 | + -d "${data}" |
| 204 | +
|
| 205 | + - name: Return machine and clear env |
| 206 | + env: |
| 207 | + TESTING_FARM_API_TOKEN: ${{ secrets.TESTING_FARM_API_TOKEN }} |
| 208 | + working-directory: ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 209 | + run: | |
| 210 | + export TESTING_FARM_API_TOKEN=${TESTING_FARM_API_TOKEN} |
| 211 | + testing-farm cancel $(cat requestid) |
| 212 | + kill $(cat ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}}/ssh_agent_pid) |
| 213 | + cd .. |
| 214 | + rm -r ${{ env.commit_sha }}-${{inputs.qe-type}}-${{inputs.preset}} |
| 215 | + |
| 216 | +
|
| 217 | +
|
0 commit comments