Test #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: bCat Prototype | |
on: | |
pull_request: | |
types: [opened, synchronize, closed] | |
branches: | |
- master | |
env: | |
BALENA_CLI_URL: https://github.com/balena-io/balena-cli/releases/download | |
BALENA_CLI_VERSION: 13.1.11 | |
DEVICE_TYPE: raspberrypi3 | |
FLEET: gh_vipulgupta2048/bcat-proto | |
ENVIRONMENT: balena-cloud.com | |
RELEASES: 50 | |
RETRY: 3 | |
SUT_RESULT_TAG_KEY: test_result | |
VERBOSE: "silent" | |
jobs: | |
balena-automated-testing: | |
strategy: | |
fail-fast: true | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install additional dependencies | |
id: extra-dependencies | |
run: | | |
set -ue | |
if ! [[ "$(${RUNNER_TEMP}/balena-cli/balena version)" =~ "${BALENA_CLI_VERSION}" ]]; then | |
release_zip="balena-cli-v${BALENA_CLI_VERSION}-linux-x64-standalone.zip" | |
wget -q "${BALENA_CLI_URL}/v${BALENA_CLI_VERSION}/${release_zip}" \ | |
&& unzip -q "${release_zip}" -d "${RUNNER_TEMP}" \ | |
&& rm "${release_zip}" | |
fi | |
"${RUNNER_TEMP}/balena-cli/balena" version | |
grep -q "${RUNNER_TEMP}/balena-cli" "${GITHUB_PATH}" \ | |
|| echo "${RUNNER_TEMP}/balena-cli" >> "${GITHUB_PATH}" | |
- name: Produce docker-compose containing SUT container | |
id: generate-compose | |
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed'}} | |
run: yq '. *= load("docker-compose.test.yml")' docker-compose.yml > docker-new.yml; cat docker-new.yml > docker-compose.yml; rm docker-new.yml | |
- name: Push release to balenaCloud (draft/final) | |
id: push-release | |
uses: balena-io/deploy-to-balena-action@v0.10.7 | |
with: | |
balena_token: ${{ secrets.BALENACLOUD_API_KEY }} | |
environment: ${{ env.ENVIRONMENT }} | |
fleet: ${{ env.FLEET }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Find viable DUT device to run our tests | |
id: find-test-device | |
run: | | |
set -uae | |
[[ '${{ env.VERBOSE }}' =~ on|On|Yes|yes|true|True ]] && set -x | |
balena login --token '${{ secrets.BALENACLOUD_API_KEY }}' | |
app_id="$(balena fleet ${{ env.FLEET }} | grep ^ID: | cut -c14-)" | |
echo "::set-output name=balena_app_id::${app_id}" | |
dut_id=$(curl --silent --retry ${{ env.RETRY }} \ | |
'https://api.${{ env.ENVIRONMENT }}/v6/device?$top=1&$select=id&$filter=belongs_to__application%20eq%20('${app_id}')%20and%20device_tag/any(dt:dt/tag_key%20eq%20%27DUT%27%20and%20value%20eq%20%27${{ env.DEVICE_TYPE }}%27)' \ | |
-H 'authorization: Bearer ${{ secrets.BALENACLOUD_API_KEY }}' \ | |
-H 'content-type: application/json' \ | |
| jq -r '.d[].id') | |
echo "::set-output name=balena_dut_id::${dut_id}" | |
dut_uuid=$(curl --silent --retry ${{ env.RETRY }} \ | |
'https://api.${{ env.ENVIRONMENT }}/v6/device?$top=1&$select=uuid&$filter=belongs_to__application%20eq%20('${app_id}')%20and%20device_tag/any(dt:dt/tag_key%20eq%20%27DUT%27%20and%20value%20eq%20%27${{ env.DEVICE_TYPE }}%27)' \ | |
-H 'authorization: Bearer ${{ secrets.BALENACLOUD_API_KEY }}' \ | |
-H 'content-type: application/json' \ | |
| jq -r '.d[].uuid') | |
echo "::set-output name=balena_dut_uuid::${dut_uuid}" | |
# https://github.com/balena-io/balena-cli/issues/1543 | |
- name: Pin DUT device to our recently created draft release | |
id: pin-device | |
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed'}} | |
run: | | |
set -uae | |
[[ '${{ env.VERBOSE }}' =~ on|On|Yes|yes|true|True ]] && set -x | |
# pin DUT to draft release | |
curl -X PATCH --retry ${{ env.RETRY }} --fail -o /dev/null \ | |
'https://api.${{ env.ENVIRONMENT }}/v6/device?$filter=id%20in%20(${{ steps.find-test-device.outputs.balena_dut_id }})' \ | |
-H 'authorization: Bearer ${{ secrets.BALENACLOUD_API_KEY }}' \ | |
-H 'content-type: application/json' \ | |
--data-raw "{\"should_be_running__release\":${{ steps.push-release.outputs.release_id }}}" \ | |
--compressed | |
- name: Wait for SUT result | |
id: wait-test-result | |
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed'}} | |
run: | | |
set -uae | |
[[ '${{ env.VERBOSE }}' =~ on|On|Yes|yes|true|True ]] && set -x | |
max_retries=100 | |
retry_count=1 | |
while [ $retry_count -lt $max_retries ]; do | |
result=$(curl -X GET --silent --retry ${{ env.RETRY }} --fail \ | |
'https://api.balena-cloud.com/v6/release_tag?$select=id,value&$filter=release%20eq%20${{ steps.push-release.outputs.release_id }}%20and%20tag_key%20eq%20%27${{ env.SUT_RESULT_TAG_KEY }}%27' \ | |
-H 'authorization: Bearer ${{ secrets.BALENACLOUD_API_KEY }}' \ | |
-H 'content-type: application/json' \ | |
| jq -r '.d[].value?') | |
if [ -n "$result" ]; then | |
balena login --token '${{ secrets.BALENACLOUD_API_KEY }}' | |
balena whoami | |
balena logs ${{ steps.find-test-device.outputs.balena_dut_uuid }} --service sut | tail -100 | |
echo "::set-output name=sut_container_status::${result}" | |
# curl -X DELETE --silent --retry ${{ env.RETRY }} --fail -o /dev/null \ | |
# 'https://api.balena-cloud.com/v6/release_tag?$select=id,value&$filter=release%20eq%20${{ steps.push-release.outputs.release_id }}%20and%20tag_key%20eq%20%27${{ env.SUT_RESULT_TAG_KEY }}%27' \ | |
# -H 'authorization: Bearer ${{ secrets.BALENACLOUD_API_KEY }}' \ | |
# -H 'content-type: application/json' | |
exit 0 | |
else | |
sleep 10 | |
((retry_count++)) | |
fi | |
done | |
exit 1 | |
# (TBC) additional overrides for testing (i.e. DB_USER, DB_PASSWORD, etc.) |