|
6 | 6 | - 'drivers/**' |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - trigger-driver-test: |
10 | | - strategy: |
11 | | - matrix: |
12 | | - version: |
13 | | - [ 60 ] |
| 9 | + # Two separate jobs for finding the right artifact to run tests with |
| 10 | + get-latest-release-artifact: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: ${{ !contains(join(github.event.pull_request.labels.*.name), 'release') }} |
| 13 | + outputs: |
| 14 | + cache_key: ${{ steps.cache_key.outputs.CACHE_KEY }} |
| 15 | + steps: |
| 16 | + - name: Find the lua lib release version |
| 17 | + id: lib-version |
| 18 | + run: | |
| 19 | + curl "https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases/latest" -s -L -I -o /dev/null -w '%{url_effective}' > test.log |
| 20 | + echo "url=$(cat test.log)" >> $GITHUB_OUTPUT |
| 21 | + - name: Try to retrieve cache |
| 22 | + id: cached-libs |
| 23 | + uses: actions/cache@v3 |
| 24 | + with: |
| 25 | + path: '/home/runner/work/lua_libs' |
| 26 | + key: ${{ steps.lib-version.outputs.url }}-v1 |
| 27 | + - name: Get the latest release artifact |
| 28 | + if: steps.cached-libs.outputs.cache-hit != 'true' |
| 29 | + uses: dsaltares/fetch-gh-release-asset@master |
| 30 | + with: |
| 31 | + file: 'lua_libs.*' |
| 32 | + regex: true |
| 33 | + target: '/home/runner/work/lua_libs/' |
| 34 | + - name: Extract the lua libraries |
| 35 | + if: steps.cached-libs.outputs.cache-hit != 'true' |
| 36 | + working-directory: '/home/runner/work/lua_libs' |
| 37 | + run: tar -xf *.tar.gz --wildcards -C . --strip-components=1 '*.lua' |
| 38 | + - name: Set output |
| 39 | + id: cache_key |
| 40 | + run: echo "CACHE_KEY=${{ steps.lib-version.outputs.url }}-v1" >> $GITHUB_OUTPUT |
14 | 41 |
|
| 42 | + run-driver-tests: |
15 | 43 | runs-on: ubuntu-latest |
| 44 | + needs: |
| 45 | + [ get-latest-release-artifact, get-dev-artifact ] |
| 46 | + if: ${{ always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure') }} |
16 | 47 | steps: |
17 | | - |
18 | | - - name: Create Commit Status (Pending) |
19 | | - id: status |
20 | | - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd |
| 48 | + - name: Set cache key |
| 49 | + id: cache_key |
| 50 | + run: echo "CACHE_KEY=${{ join(needs.*.outputs.cache_key) }}" >> $GITHUB_OUTPUT |
| 51 | + - name: Try to retrieve cache |
| 52 | + id: cached_libs |
| 53 | + uses: actions/cache@v3 |
| 54 | + with: |
| 55 | + path: '/home/runner/work/lua_libs' |
| 56 | + key: ${{ steps.cache_key.outputs.CACHE_KEY }} |
| 57 | + - name: Fail if cache missed |
| 58 | + if: steps.cached_libs.outputs.cache-hit != 'true' |
| 59 | + uses: actions/github-script@v3 |
21 | 60 | with: |
22 | 61 | script: | |
23 | | - core.setOutput('status_url', (await github.rest.repos.createCommitStatus({ |
24 | | - owner: context.repo.owner, |
25 | | - repo: context.repo.repo, |
26 | | - sha: context.sha, |
27 | | - state: 'pending', |
28 | | - description: 'Jenkins job triggered...', |
29 | | - context: 'Driver Tests (${{ matrix.version }})' |
30 | | - })).data.url); |
31 | | - - name: Trigger Jenkins Generic Webhook |
| 62 | + core.setFailed('Library cache missed. ${{steps.cached_libs.outputs.cache-hit}} ') |
| 63 | + - name: Install lua |
| 64 | + run: | |
| 65 | + sudo apt-get update |
| 66 | + sudo apt-get install lua5.3 liblua5.3-dev luarocks |
| 67 | + - name: Install lua rocks |
| 68 | + run: | |
| 69 | + wget https://luarocks.org/manifests/hisham/luacov-0.15.0-1.rockspec |
| 70 | + wget https://raw.githubusercontent.com/britzl/luacov-cobertura/refs/tags/1.1.0/rockspec -O luacov-cobertura-1.1.0-0.rockspec |
| 71 | + sed -i 's/master/1\.1\.0/g' luacov-cobertura-1.1.0-0.rockspec |
| 72 | + sed -i 's/1\.0-0/1\.1\.0-0/g' luacov-cobertura-1.1.0-0.rockspec |
| 73 | + sudo luarocks install luacov-0.15.0-1.rockspec |
| 74 | + sudo luarocks install luacov-cobertura-1.1.0-0.rockspec |
| 75 | + - name: Set LUA_PATH |
| 76 | + id: lua_path |
32 | 77 | env: |
33 | | - JENKINS_WEBHOOK_TOKEN: ${{ secrets.JENKINS_WEBHOOK_TOKEN }} |
34 | | - JENKINS_WEBHOOK_URL: ${{ secrets.JENKINS_WEBHOOK_URL }} |
35 | | - STATUS_URL: ${{ steps.status.outputs.status_url }} |
| 78 | + LUA_PATH_APPEND: /home/runner/work/lua_libs/?.lua;./?.lua;/home/runner/work/lua_libs/?/init.lua;./?/init.lua |
36 | 79 | run: | |
37 | | - set +x |
38 | | - curl -s -o /dev/null -X POST \ |
39 | | - -H "Content-Type: application/json" \ |
40 | | - -H "Authorization: Bearer ${JENKINS_WEBHOOK_TOKEN}" \ |
41 | | - -d "{\"status_url\": \"$STATUS_URL\", |
42 | | - \"version\": ${{ matrix.version }}, |
43 | | - \"commit\": ${{ github.event.pull_request.head.sha }} }" \ |
44 | | - "${JENKINS_WEBHOOK_URL}" |
45 | | - set -x |
| 80 | + eval "$(luarocks path --bin)" |
| 81 | + echo "lua_path=$LUA_PATH_APPEND;$LUA_PATH" >> $GITHUB_OUTPUT |
| 82 | + - uses: actions/checkout@v3 |
| 83 | + - name: get changed drivers |
| 84 | + id: changed-drivers |
| 85 | + uses: tj-actions/changed-files@v41 |
| 86 | + with: |
| 87 | + dir_names: true |
| 88 | + dir_names_max_depth: 3 |
| 89 | + files: "drivers/**" |
| 90 | + safe_output: false |
| 91 | + - run: echo ${{ steps.changed-drivers.outputs.all_modified_files }} |
| 92 | + - name: Install Python requirements |
| 93 | + run: pip install -r tools/requirements.txt |
| 94 | + - name: Run the tests |
| 95 | + id: run-tests |
| 96 | + run: python tools/run_driver_tests_p.py ${{ steps.changed-drivers.outputs.all_modified_files }} |
| 97 | + env: |
| 98 | + LUA_PATH: ${{ steps.lua_path.outputs.lua_path }} |
| 99 | + - name: Upload test artifact |
| 100 | + if: always() |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: tests |
| 104 | + path: | |
| 105 | + tools/test_output/*.xml |
| 106 | + - name: Upload coverage artifact |
| 107 | + if: always() |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: coverage |
| 111 | + path: | |
| 112 | + tools/coverage_output/*_coverage.xml |
46 | 113 |
|
47 | 114 | event-file: |
48 | 115 | runs-on: ubuntu-latest |
|
0 commit comments