-
Notifications
You must be signed in to change notification settings - Fork 4
163 lines (140 loc) · 5.66 KB
/
Copy pathtest.yaml
File metadata and controls
163 lines (140 loc) · 5.66 KB
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
name: Test
on:
workflow_dispatch:
# Use a manual approval process before PR's are given access to
# the secrets which are required to run the integration tests.
# The PR code should be manually approved to see if it can be trusted.
# When in doubt, do not approve the test run.
# Reference: https://dev.to/petrsvihlik/using-environment-protection-rules-to-secure-secrets-when-building-external-forks-with-pullrequesttarget-hci
pull_request_target:
branches: [ main ]
merge_group:
permissions:
contents: read
jobs:
approve:
name: Approve
environment:
# For security reasons, all pull requests need to be approved first before granting access to secrets
# So the environment should be set to have a reviewer/s inspect it before approving it
name: ${{ github.event_name == 'pull_request_target' && 'Test Pull Request' || 'Test Auto' }}
runs-on: ubuntu-latest
steps:
- name: Wait for approval
run: echo "Approved"
test:
name: Test ${{ matrix.job.target }} ${{ matrix.job.channel }}
runs-on: ubuntu-24.04
needs: approve
permissions:
# Required to publish system test results to the PR
issues: write
pull-requests: write
contents: read
environment:
name: Test Auto
env:
COMPOSE_PROJECT_NAME: ci_${{ matrix.job.target }}_${{ matrix.job.channel }}_${{github.run_id}}_${{github.run_attempt || '1'}}
DEVICE_ID: ci_${{ matrix.job.target }}_${{ matrix.job.channel }}_${{github.run_id}}_${{github.run_attempt || '1'}}
strategy:
fail-fast: false
matrix:
job:
- { target: debian-systemd, bootstrap: "script", channel: "release" }
- { target: debian-systemd, bootstrap: "script", channel: "main" }
- { target: alpine-s6, bootstrap: "bootstrap-container-mapper", channel: "release" }
- { target: tedge, bootstrap: "container", channel: "release" }
- { target: tedge-containermgmt, bootstrap: "container", channel: "release" }
steps:
# Checkout either the PR or the branch
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}
fetch-depth: 0
- uses: reubenmiller/setup-go-c8y-cli@main
- name: install c8y-tedge extension
run: c8y extension install thin-edge/c8y-tedge
- name: create .env file
run: |
touch .env
echo "DEVICE_ID=$DEVICE_ID" >> .env
echo 'C8Y_BASEURL="${{ secrets.C8Y_BASEURL }}"' >> .env
C8Y_DOMAIN=$(echo "${{ secrets.C8Y_BASEURL }}" | sed -E 's|^https?://||g')
echo "C8Y_DOMAIN=$C8Y_DOMAIN" >> .env
echo 'C8Y_USER="${{ secrets.C8Y_USER }}"' >> .env
echo 'C8Y_PASSWORD="${{ secrets.C8Y_PASSWORD }}"' >> .env
cat .env
- name: Detect host architecture
run: |
arch=$(uname -m)
case "$arch" in
arm64|aarch64) NORMALIZED_ARCH=arm64; ;;
amd64|x86_64) NORMALIZED_ARCH=amd64; ;;
*) NORMALIZED_ARCH="$arch"; ;;
esac
echo "ARCH=$NORMALIZED_ARCH" >> "$GITHUB_ENV"
- uses: actions/setup-python@v6
with:
python-version-file: tests/.python-version
cache: 'pip'
cache-dependency-path: |
tests/requirements.txt
- uses: taiki-e/install-action@just
- name: Install dependencies
run: |
just venv
- name: Start demo
env:
TEDGE_CHANNEL: ${{ matrix.job.channel || 'release' }}
run: |
case "${{matrix.job.bootstrap}}" in
script)
just IMAGE=${{matrix.job.target}} prepare-up
just IMAGE=${{matrix.job.target}} up --build=false
just IMAGE=${{matrix.job.target}} bootstrap --no-prompt
;;
container)
just IMAGE=${{matrix.job.target}} prepare-up
# Wait for container to startup before doing bootstrapping
just IMAGE=${{matrix.job.target}} up --build=false >/dev/null 2>&1 &
UP_PID=$!
sleep 5
just IMAGE=${{matrix.job.target}} bootstrap-container "$DEVICE_ID" </dev/null
# Wait until bootstrap is ready
wait "$UP_PID"
echo "docker compose up is ready"
sleep 5
;;
bootstrap-container-mapper)
just IMAGE=${{matrix.job.target}} up --build=false
just IMAGE=${{matrix.job.target}} bootstrap-container-mapper
;;
*)
just IMAGE=${{matrix.job.target}} prepare-up
just IMAGE=${{matrix.job.target}} up --build=false
echo "Skipping bootstrapping"
;;
esac
- name: Run tests
run: just IMAGE=${{matrix.job.target}} test
- name: Stop demo
if: always()
run: just IMAGE=${{matrix.job.target}} down-all
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: reports-${{matrix.job.target}}-${{ matrix.job.channel }}
path: output
- name: Cleanup Devices
if: always()
run: |
just cleanup "$DEVICE_ID"
- name: Send report to commit
uses: joonvena/robotframework-reporter-action@v2.5
if: always() && github.event_name == 'pull_request_target'
with:
gh_access_token: ${{ secrets.GITHUB_TOKEN }}
report_path: 'output'
show_passed_tests: 'false'