-
Notifications
You must be signed in to change notification settings - Fork 464
169 lines (165 loc) · 6.93 KB
/
run-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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://raw.githubusercontent.com/britzl/luacov-cobertura/refs/tags/1.1.0/rockspec -O luacov-cobertura-1.1.0-0.rockspec
sed -i 's/master/1\.1\.0/g' luacov-cobertura-1.1.0-0.rockspec
sed -i 's/1\.0-0/1\.1\.0-0/g' luacov-cobertura-1.1.0-0.rockspec
sudo luarocks install luacov-0.15.0-1.rockspec
sudo luarocks install luacov-cobertura-1.1.0-0.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@v41
with:
dir_names: true
dir_names_max_depth: 3
files: "drivers/**"
safe_output: false
- 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@v3
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