Skip to content

aqara-security-demo #2294

aqara-security-demo

aqara-security-demo #2294

Workflow file for this run

name: Run driver tests
on:
pull_request:
types: [opened, synchronize, labeled, unlabeled]
paths:
- 'drivers/**'
jobs:
# Two separate jobs for finding the right artifact to run tests with
get-latest-release-artifact:
runs-on: ubuntu-latest
if: ${{ !contains(join(github.event.pull_request.labels.*.name), 'release') }}
outputs:
cache_key: ${{ steps.cache_key.outputs.CACHE_KEY }}
steps:
- name: Find the lua lib release version
id: lib-version
run: |
curl "https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases/latest" -s -L -I -o /dev/null -w '%{url_effective}' > test.log
echo "url=$(cat test.log)" >> $GITHUB_OUTPUT
- name: Try to retrieve cache
id: cached-libs
uses: actions/cache@v3
with:
path: '/home/runner/work/lua_libs'
key: ${{ steps.lib-version.outputs.url }}-v1
- name: Get the latest release artifact
if: steps.cached-libs.outputs.cache-hit != 'true'
uses: dsaltares/fetch-gh-release-asset@master
with:
file: 'lua_libs.*'
regex: true
target: '/home/runner/work/lua_libs/'
- name: Extract the lua libraries
if: steps.cached-libs.outputs.cache-hit != 'true'
working-directory: '/home/runner/work/lua_libs'
run: tar -xf *.tar.gz --wildcards -C . --strip-components=1 '*.lua'
- name: Set output
id: cache_key
run: echo "CACHE_KEY=${{ steps.lib-version.outputs.url }}-v1" >> $GITHUB_OUTPUT
get-dev-artifact:
runs-on: ubuntu-latest
outputs:
cache_key: ${{ steps.cache_key.outputs.CACHE_KEY }}
if: ${{ contains(join(github.event.pull_request.labels.*.name), 'release-') && github.event.pull_request.head.repo.fork != 'true' }}
steps:
- name: Get the version from the label
id: label-version
run: |
echo "${{ join(github.event.pull_request.labels.*.name) }}" | grep -oP "release-\d+.\d+" | xargs > out
echo "LIBRARY_VERSION=$(cat out)" >> $GITHUB_OUTPUT
mkdir /home/runner/work/lua_libs
- name: Find latest artifact
id: latest
env:
ARTIFACTORY_URL: ${{ format('https://smartthings.jfrog.io/artifactory/edge-driver-libs/{0}/', steps.label-version.outputs.LIBRARY_VERSION) }}
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
run: |
wget --user=$ARTIFACTORY_USERNAME --password=$ARTIFACTORY_PASSWORD $ARTIFACTORY_URL -q -O - | grep '.zip' | awk -F' ' '{print $3"-"$4"\t"$2}' | sort -t - -k3n -k2M -k1n -k4n | tail -1 | grep -o 'lua_libs_[a-z0-9_]*.zip' | head -1 > out
echo "ZIP_FILE=$(cat out)" >> $GITHUB_OUTPUT
- name: Try to retrieve cache
id: cached-libs
uses: actions/cache@v3
with:
path: '/home/runner/work/lua_libs'
key: ${{ steps.latest.outputs.ZIP_FILE }}-v1
- name: Download and unpack specified version
if: steps.cached-libs.outputs.cache-hit != 'true'
env:
ARTIFACTORY_URL: ${{ format('https://smartthings.jfrog.io/artifactory/edge-driver-libs/{0}/{1}', steps.label-version.outputs.LIBRARY_VERSION, steps.latest.outputs.ZIP_FILE) }}
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
working-directory: '/home/runner/work/lua_libs'
run: |
wget --user=$ARTIFACTORY_USERNAME --password=$ARTIFACTORY_PASSWORD $ARTIFACTORY_URL -O lua_libs.zip
unzip lua_libs.zip
- name: Set output
id: cache_key
run: echo "CACHE_KEY=${{ steps.latest.outputs.ZIP_FILE }}-v1" >> $GITHUB_OUTPUT
run-driver-tests:
runs-on: ubuntu-latest
needs:
[ get-latest-release-artifact, get-dev-artifact ]
if: ${{ always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure') }}
steps:
- name: Set cache key
id: cache_key
run: echo "CACHE_KEY=${{ join(needs.*.outputs.cache_key) }}" >> $GITHUB_OUTPUT
- name: Try to retrieve cache
id: cached_libs
uses: actions/cache@v3
with:
path: '/home/runner/work/lua_libs'
key: ${{ steps.cache_key.outputs.CACHE_KEY }}
- name: Fail if cache missed
if: steps.cached_libs.outputs.cache-hit != 'true'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Library cache missed. ${{steps.cached_libs.outputs.cache-hit}} ')
- name: Install lua
run: |
sudo apt-get update
sudo apt-get install lua5.3 liblua5.3-dev luarocks
- name: Install lua rocks
run: |
wget https://luarocks.org/manifests/hisham/luacov-0.15.0-1.rockspec
wget https://luarocks.org/manifests/ssharma/luacov-cobertura-0.2-1.rockspec
sudo luarocks install luacov-0.15.0-1.rockspec
sudo luarocks install luacov-cobertura-0.2-1.rockspec
- name: Set LUA_PATH
id: lua_path
env:
LUA_PATH_APPEND: /home/runner/work/lua_libs/?.lua;./?.lua;/home/runner/work/lua_libs/?/init.lua;./?/init.lua
run: |
eval "$(luarocks path --bin)"
echo "lua_path=$LUA_PATH_APPEND;$LUA_PATH" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- name: get changed drivers
id: changed-drivers
uses: tj-actions/changed-files@v35
with:
dir_names: true
dir_names_max_depth: 3
files: "drivers"
- run: echo ${{ steps.changed-drivers.outputs.all_modified_files }}
- name: Install Python requirements
run: pip install -r tools/requirements.txt
- name: Run the tests
id: run-tests
run: python tools/run_driver_tests_p.py ${{ steps.changed-drivers.outputs.all_modified_files }}
env:
LUA_PATH: ${{ steps.lua_path.outputs.lua_path }}
- name: Upload test artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: tests
path: |
tools/test_output/*.xml
- name: Upload coverage artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage
path: |
tools/coverage_output/*_coverage.xml
event-file:
runs-on: ubuntu-latest
steps:
- name: Upload event file artifact
uses: actions/upload-artifact@v2
with:
name: event-file
path: ${{ github.event_path }}
- run: echo ${{ github.event.number }} > pr_number.txt
- name: Upload pr number artifact
uses: actions/upload-artifact@v3
with:
name: pr_number
path: |
pr_number.txt