summaryrefslogtreecommitdiff
path: root/.github/workflows/package-smoketest.yml
blob: e558a4fa74a54e1fc30de22a99f779c6ffa247fd (plain)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
name: VyOS ISO Integration Test

on:
  workflow_dispatch:
  push:
    branches:
      - rolling
      - circinus
      - sagitta
    paths:
      - '**'
      - '!.github/**'
      - '!**/*.md'
  pull_request_target:
    branches:
      - rolling
      - circinus
      - sagitta
    paths:
      - '**'
      - '!.github/**'
      - '!**/*.md'

permissions:
  pull-requests: write
  contents: read

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  BUILD_BY: autobuild@vyos.net
  DEBIAN_MIRROR: http://deb.debian.org/debian/
  DEBIAN_SECURITY_MIRROR: http://deb.debian.org/debian-security

jobs:
  set_config:
    runs-on: ubuntu-latest
    outputs:
      branch: ${{ steps.config.outputs.branch }}
      vyos_mirror: ${{ steps.config.outputs.vyos_mirror }}
      container_image: ${{ steps.config.outputs.container_image }}
      vyos_build_repo: ${{ steps.config.outputs.vyos_build_repo }}
      build_version_format: ${{ steps.config.outputs.build_version_format }}
      build_runner: ${{ steps.config.outputs.build_runner }}
      use_pat: ${{ steps.config.outputs.use_pat }}
      test_cli_command: ${{ steps.config.outputs.test_cli_command }}
      test_tpm_tests: ${{ steps.config.outputs.test_tpm_tests }}
      test_vpp: ${{ steps.config.outputs.test_vpp }}
      test_vpp_runner: ${{ steps.config.outputs.test_vpp_runner }}
      install_build_deps: ${{ steps.config.outputs.install_build_deps }}
      mirror_enabled: ${{ steps.config.outputs.mirror_enabled }}
      vyos_build_ref: ${{ steps.determine-ref.outputs.vyos_build_ref }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Set branch-specific configuration
        id: config
        run: |
          if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
            BRANCH="${{ github.event.pull_request.base.ref }}"
          else
            BRANCH="${{ github.ref_name }}"
          fi

          CONFIG=$(jq ".branches[\"${BRANCH}\"]" .github/config/smoketest-branches.json)

          if [ "$CONFIG" = "null" ] || [ -z "$CONFIG" ]; then
            echo "::error::No smoketest configuration found for branch '${BRANCH}' in .github/config/smoketest-branches.json"
            exit 1
          fi

          echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
          echo "vyos_mirror=$(echo $CONFIG | jq -r .vyos_mirror)" >> $GITHUB_OUTPUT
          echo "container_image=$(echo $CONFIG | jq -r .container_image)" >> $GITHUB_OUTPUT
          echo "vyos_build_repo=$(echo $CONFIG | jq -r .vyos_build_repo)" >> $GITHUB_OUTPUT
          echo "build_version_format=$(echo $CONFIG | jq -r .build_version_format)" >> $GITHUB_OUTPUT
          echo "build_runner=$(echo $CONFIG | jq -c .build_runner)" >> $GITHUB_OUTPUT
          echo "use_pat=$(echo $CONFIG | jq -r .use_pat)" >> $GITHUB_OUTPUT
          echo "test_cli_command=$(echo $CONFIG | jq -r .test_cli_command)" >> $GITHUB_OUTPUT
          echo "test_tpm_tests=$(echo $CONFIG | jq -r .test_tpm_tests)" >> $GITHUB_OUTPUT
          echo "test_vpp=$(echo $CONFIG | jq -r .test_vpp)" >> $GITHUB_OUTPUT
          echo "test_vpp_runner=$(echo $CONFIG | jq -c .test_vpp_runner)" >> $GITHUB_OUTPUT
          echo "install_build_deps=$(echo $CONFIG | jq -r .install_build_deps)" >> $GITHUB_OUTPUT
          echo "mirror_enabled=$(echo $CONFIG | jq -r .mirror_enabled)" >> $GITHUB_OUTPUT

      - name: Determine vyos-build ref
        id: determine-ref
        env:
          GH_TOKEN: ${{ steps.config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
        run: |
          BRANCH="${{ steps.config.outputs.branch }}"
          VYOS_BUILD_REPO="${{ steps.config.outputs.vyos_build_repo }}"

          if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
            PR_HEAD_REF="${{ github.event.pull_request.head.ref }}"

            # VYOS_BUILD_REPO is in owner/repo format from config
            REPO_PATH="$VYOS_BUILD_REPO"

            # Get creation date from 90 days ago
            CREATED_AFTER=$(date -u -d "90 days ago" +"%Y-%m-%dT%H:%M:%SZ")

            echo "Looking for PR in $REPO_PATH with branch '$PR_HEAD_REF' created after $CREATED_AFTER"

            # Query GitHub API for matching PR with merge commit SHA
            MATCHING_PR_MERGE_SHA=$(gh api repos/$REPO_PATH/pulls \
              --jq ".[] | select(.created_at > \"$CREATED_AFTER\" and .head.ref == \"$PR_HEAD_REF\") | .merge_commit_sha" 2>&1 | grep -v '^{' | head -1)

            echo "Merge commit SHA: $MATCHING_PR_MERGE_SHA"

            # Check if response is a valid SHA (40-char hex) or an error
            if [[ $MATCHING_PR_MERGE_SHA =~ ^[a-f0-9]{40}$ ]]; then
              # Use the merge commit SHA - this is what the code would look like if merged
              echo "vyos_build_ref=$MATCHING_PR_MERGE_SHA" >> $GITHUB_OUTPUT
              echo "Found matching open PR in vyos-build with branch '$PR_HEAD_REF', using merge commit: $MATCHING_PR_MERGE_SHA"
            else
              echo "vyos_build_ref=$BRANCH" >> $GITHUB_OUTPUT
              echo "No matching open PR found in vyos-build for branch '$PR_HEAD_REF', falling back to '$BRANCH'"
            fi
          else
            echo "vyos_build_ref=$BRANCH" >> $GITHUB_OUTPUT
            echo "Using configured branch '$BRANCH'"
          fi

  build_iso:
    needs: set_config
    runs-on: ${{ fromJson(needs.set_config.outputs.build_runner) }}
    timeout-minutes: 45
    if: ${{ needs.set_config.outputs.mirror_enabled == 'false' || (needs.set_config.outputs.mirror_enabled == 'true' && github.repository_owner == 'vyos') }}
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      build_version: ${{ steps.version.outputs.build_version }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - name: Clone vyos-1x source code into the build directory
        uses: actions/checkout@v6
        with:
          path: build/vyos-1x
          repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}
          persist-credentials: false

      - name: Clone vyos-1x source code
        uses: actions/checkout@v6
        with:
          path: packages/vyos-1x
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          submodules: true

      - name: Build vyos-1x package
        run: |
          cd packages/vyos-1x
          if [[ "${{ needs.set_config.outputs.install_build_deps }}" == "true" ]]; then
            sudo apt-get update
            sudo apt-get build-dep -y .
          fi
          dpkg-buildpackage -uc -us -tc -b

      - name: Generate ISO version string
        id: version
        run: |
          echo "build_version=$(date -u +'${{ needs.set_config.outputs.build_version_format }}')" >> $GITHUB_OUTPUT

      - name: Build custom ISO image
        shell: bash
        run: |
          sudo --preserve-env ./build-vyos-image \
          --architecture amd64 \
          --build-by $BUILD_BY \
          --build-type release \
          --custom-package vyos-1x-smoketest \
          --debian-mirror $DEBIAN_MIRROR \
          --debian-security-mirror $DEBIAN_SECURITY_MIRROR \
          --version ${{ steps.version.outputs.build_version }} \
          --vyos-mirror ${{ needs.set_config.outputs.vyos_mirror }} \
          generic

      - uses: actions/upload-artifact@v7
        with:
          retention-days: 2
          name: vyos-${{ steps.version.outputs.build_version }}
          path: |
            build/live-image-amd64.hybrid.iso
            build/manifest.json

      - uses: atos-actions/clean-self-hosted-runner@v1.4.10
        if: ${{ always() && contains(needs.set_config.outputs.build_runner, 'self-hosted') }}

  test_smoketest_cli:
    needs: [build_iso, set_config]
    runs-on: ubuntu-24.04
    timeout-minutes: 180
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS CLI smoketests (no interfaces)
        id: test
        shell: bash
        run: |
          if sudo make ${{ needs.set_config.outputs.test_cli_command }}; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  test_smoketest_cli_vpp:
    needs: [build_iso, set_config]
    if: needs.set_config.outputs.test_vpp == 'true'
    runs-on: ${{ fromJson(needs.set_config.outputs.test_vpp_runner) }}
    timeout-minutes: 90
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS CLI smoketests VPP
        id: test
        shell: bash
        run: |
          if sudo make test-vpp; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  test_interfaces_cli:
    needs: [build_iso, set_config]
    runs-on: ubuntu-24.04
    timeout-minutes: 180
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS CLI smoketests (interfaces only)
        id: test
        shell: bash
        run: |
          if sudo make test-interfaces; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  test_config_load:
    needs: [build_iso, set_config]
    runs-on: ubuntu-24.04
    timeout-minutes: 90
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS config load tests
        id: test
        shell: bash
        run: |
          if sudo make testc; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  test_config_load_vpp:
    needs: [build_iso, set_config]
    if: needs.set_config.outputs.test_vpp == 'true'
    runs-on: ${{ fromJson(needs.set_config.outputs.test_vpp_runner) }}
    timeout-minutes: 90
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS config load tests VPP
        id: test
        shell: bash
        run: |
          if sudo make testcvpp; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  test_raid1_install:
    needs: [build_iso, set_config]
    runs-on: ubuntu-24.04
    timeout-minutes: 20
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS RAID1 installation tests
        id: test
        shell: bash
        run: |
          if sudo make testraid; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  test_encrypted_config_tpm:
    needs: [build_iso, set_config]
    if: needs.set_config.outputs.test_tpm_tests == 'true'
    runs-on: ubuntu-24.04
    timeout-minutes: 30
    container:
      image: ${{ needs.set_config.outputs.container_image }}
      options: --sysctl net.ipv6.conf.lo.disable_ipv6=0 --privileged
    outputs:
      exit_code: ${{ steps.test.outputs.exit_code }}
    steps:
      - name: Clone vyos-build source code
        uses: actions/checkout@v6
        with:
          repository: ${{ needs.set_config.outputs.vyos_build_repo }}
          token: ${{ needs.set_config.outputs.use_pat == 'true' && secrets.PAT || secrets.GITHUB_TOKEN }}
          ref: ${{ needs.set_config.outputs.vyos_build_ref }}

      - uses: actions/download-artifact@v8
        with:
          name: vyos-${{ needs.build_iso.outputs.build_version }}
          path: build

      - name: VyOS TPM encryption tests
        id: test
        shell: bash
        run: |
          if sudo make testtpm; then
            echo "exit_code=success" >> $GITHUB_OUTPUT
          else
            echo "exit_code=fail" >> $GITHUB_OUTPUT
            exit 1
          fi

  result:
    needs:
      - set_config
      - test_smoketest_cli
      - test_smoketest_cli_vpp
      - test_interfaces_cli
      - test_config_load
      - test_config_load_vpp
      - test_raid1_install
      - test_encrypted_config_tpm
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    if: always()
    steps:
      - name: Add PR comment
        if: always() && github.event_name == 'pull_request_target'
        uses: mshick/add-pr-comment@v2
        with:
          message: |
            CI integration ${{ (needs.test_smoketest_cli.outputs.exit_code == 'success' && needs.test_interfaces_cli.outputs.exit_code == 'success' && needs.test_config_load.outputs.exit_code == 'success' && needs.test_raid1_install.outputs.exit_code == 'success' && (needs.test_smoketest_cli_vpp.outputs.exit_code != 'fail') && (needs.test_config_load_vpp.outputs.exit_code != 'fail') && (needs.test_encrypted_config_tpm.outputs.exit_code != 'fail')) && '👍 passed!' || '❌ failed!' }}

            ### Details

            [CI logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})

            * CLI Smoketests ${{ needs.test_smoketest_cli.outputs.exit_code == 'success' && '👍 passed' || '❌ failed' }}
            * CLI Smoketests (interfaces only) ${{ needs.test_interfaces_cli.outputs.exit_code == 'success' && '👍 passed' || '❌ failed' }}
            * Config tests ${{ needs.test_config_load.outputs.exit_code == 'success' && '👍 passed' || '❌ failed' }}
            * RAID1 tests ${{ needs.test_raid1_install.outputs.exit_code == 'success' && '👍 passed' || '❌ failed' }}
            * CLI Smoketests VPP ${{ needs.test_smoketest_cli_vpp.outputs.exit_code == 'success' && '👍 passed' || needs.test_smoketest_cli_vpp.outputs.exit_code == 'fail' && '❌ failed' || '⏭️ skipped' }}
            * Config tests VPP ${{ needs.test_config_load_vpp.outputs.exit_code == 'success' && '👍 passed' || needs.test_config_load_vpp.outputs.exit_code == 'fail' && '❌ failed' || '⏭️ skipped' }}
            * TPM tests ${{ needs.test_encrypted_config_tpm.outputs.exit_code == 'success' && '👍 passed' || needs.test_encrypted_config_tpm.outputs.exit_code == 'fail' && '❌ failed' || '⏭️ skipped' }}

          message-id: "SMOKETEST_RESULTS"
          allow-repeats: false
          refresh-message-position: true