Skip to content

Commit 42d92d2

Browse files
committed
Revert run tets and add Jenkins driver tests
1 parent ba4e424 commit 42d92d2

File tree

3 files changed

+171
-30
lines changed

3 files changed

+171
-30
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Run Jenkins driver tests
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, labeled, unlabeled]
5+
paths:
6+
- 'drivers/**'
7+
8+
trigger-driver-test:
9+
strategy:
10+
matrix:
11+
version:
12+
[ 60 ]
13+
14+
runs-on: ubuntu-latest
15+
steps:
16+
17+
- name: Create Commit Status (Pending)
18+
id: status
19+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
20+
with:
21+
script: |
22+
core.setOutput('status_url', (await github.rest.repos.createCommitStatus({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
sha: context.sha,
26+
state: 'pending',
27+
description: 'Jenkins job triggered...',
28+
context: 'Driver Tests (${{ matrix.version }})'
29+
})).data.url);
30+
- name: Trigger Jenkins Generic Webhook
31+
env:
32+
JENKINS_WEBHOOK_TOKEN: ${{ secrets.JENKINS_WEBHOOK_TOKEN }}
33+
JENKINS_WEBHOOK_URL: ${{ secrets.JENKINS_WEBHOOK_URL }}
34+
STATUS_URL: ${{ steps.status.outputs.status_url }}
35+
run: |
36+
set +x
37+
curl -s -o /dev/null -X POST \
38+
-H "Content-Type: application/json" \
39+
-H "Authorization: Bearer ${JENKINS_WEBHOOK_TOKEN}" \
40+
-d "{\"status_url\": \"$STATUS_URL\",
41+
\"version\": ${{ matrix.version }},
42+
\"commit\": ${{ github.event.pull_request.head.sha }} }" \
43+
"${JENKINS_WEBHOOK_URL}"
44+
set -x
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish test results
2+
on:
3+
workflow_run:
4+
workflows: [Run driver tests]
5+
types:
6+
- completed
7+
8+
jobs:
9+
publish-test-results:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Download artifacts
13+
uses: dawidd6/action-download-artifact@v6
14+
with:
15+
workflow: run-tests.yml
16+
run_id: ${{ github.event.workflow_run.id }}
17+
- run: echo "pr_number=$(cat pr_number/pr_number.txt)" >> $GITHUB_ENV
18+
- name: Publish test results
19+
uses: EnricoMi/publish-unit-test-result-action@v2
20+
with:
21+
commit: ${{ github.event.workflow_run.head_sha }}
22+
event_file: event-file/event.json
23+
event_name: ${{ github.event.workflow_run.event }}
24+
files: "tests/*.xml"
25+
- name: Publish coverage results
26+
uses: 5monkeys/cobertura-action@master
27+
with:
28+
pull_request_number: ${{ env.pr_number }}
29+
path: "coverage/*.xml"
30+
minimum_coverage: 90

.github/workflows/run-tests.yml

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,110 @@ on:
66
- 'drivers/**'
77

88
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
1441

42+
run-driver-tests:
1543
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') }}
1647
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
2160
with:
2261
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
3277
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
3679
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
46113
47114
event-file:
48115
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)