-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (122 loc) · 5.39 KB
/
test.yaml
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
# yamllint disable rule:comments
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Run all the tests
'on': workflow_call
env:
IMAGE_REGISTRY: ghcr.io
jobs:
prepare-matrix:
uses: deedee-ops/containers/.github/workflows/prepare-matrix.yaml@master
secrets: inherit
test:
needs: prepare-matrix
name: Test
runs-on: ubuntu-latest
if: ${{ needs.prepare-matrix.outputs.matrix != '' && needs.prepare-matrix.outputs.matrix != '[]' }}
strategy:
matrix:
apps: ["${{ fromJson(needs.prepare-matrix.outputs.matrix) }}"]
fail-fast: false
# yamllint disable rule:line-length
steps:
- name: Generate Token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
id: generate-token
with:
app_id: "${{ secrets.BOT_APP_ID }}"
private_key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
token: "${{ steps.generate-token.outputs.token }}"
fetch-depth: 1
- name: Setup workflow Variables
id: vars
shell: bash
run: |-
insecure=$(jq '.insecure' --raw-output apps/${{ matrix.apps.app }}/metadata.json)
test_mute_cmd=$(jq '.testMuteCmd' --raw-output apps/${{ matrix.apps.app }}/metadata.json)
build_version=$(jq --arg chan ${{ matrix.apps.channel }} --raw-output '(.channels | .[] | select(.name == $chan)) | .version' ./apps/${{ matrix.apps.app }}/metadata.json)
baseimg_build_version=$(jq --arg chan ${{ matrix.apps.channel }} --raw-output '(.channels | .[] | select(.name == $chan)) | .baseimgversion' ./apps/${{ matrix.apps.app }}/metadata.json)
metavar=$(jq --arg chan ${{ matrix.apps.channel }} --raw-output '(.channels | .[] | select(.name == $chan)) | .metavar' ./apps/${{ matrix.apps.app }}/metadata.json)
{
echo "build_version=${build_version}"
echo "baseimg_build_version=${baseimg_build_version}"
echo "metavar=${metavar}"
echo "goss_file=./apps/${{ matrix.apps.app }}/ci/goss.yaml"
} >> "$GITHUB_OUTPUT"
if [[ "${test_mute_cmd}" == true ]]; then
echo "goss_args=tail -f /dev/null" >> "$GITHUB_OUTPUT"
echo "goss_entrypoint=--entrypoint ''" >> "$GITHUB_OUTPUT"
fi
if [[ "${insecure}" != true ]]; then
echo "goss_secure=--read-only -u 65000:65000" >> "$GITHUB_OUTPUT"
fi
if [ -d ./apps/${{ matrix.apps.app }}/ci/secrets ]; then
echo "goss_run_env=-v $(pwd)/apps/${{ matrix.apps.app }}/ci/secrets:/secrets" >> "$GITHUB_OUTPUT"
fi
- name: Setup Goss
uses: e1himself/goss-installation-action@fbb6fb55d3e59c96045b2500eeb8ce0995d99ac1 # v1.2.1
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
with:
version: latest
driver-opts: |
image=public.ecr.aws/vend/moby/buildkit:buildx-stable-1
- name: Check tests existence
id: check_ci
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
with:
files: apps/${{ matrix.apps.app }}/ci
fail: false
- name: Build container image for testing
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
with:
build-args: |-
BASEIMGVERSION=${{ steps.vars.outputs.baseimg_build_version }}
METAVAR=${{ steps.vars.outputs.metavar }}
VERSION=${{ steps.vars.outputs.build_version }}
CHANNEL=${{ matrix.apps.channel }}
context: apps/${{ matrix.apps.app }}
platforms: linux/amd64 # load does not support muti-arch https://github.com/docker/buildx/issues/290
file: apps/${{ matrix.apps.app }}/Dockerfile
load: true
no-cache: true
tags: |-
${{ env.IMAGE_REGISTRY }}/${{ github.repository_owner }}/${{ matrix.apps.app }}:testing
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Goss tests
id: dgoss
shell: bash
if: steps.check_ci.outputs.files_exists == 'true'
env:
CONTAINER_RUNTIME: docker
GOSS_FILE: ${{ steps.vars.outputs.goss_file }}
GOSS_OPTS: |-
--retry-timeout 60s --sleep 2s --color --format documentation
GOSS_SLEEP: 2
CONTAINER_LOG_OUTPUT: goss_container_log_output
run: >-
dgoss run
${{ steps.vars.outputs.goss_secure }}
--cap-drop=all
${{ steps.vars.outputs.goss_run_env }}
${{ steps.vars.outputs.goss_entrypoint }}
${{ env.IMAGE_REGISTRY }}/${{ github.repository_owner }}/${{ matrix.apps.app }}:testing
${{ steps.vars.outputs.goss_args }}
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
build-success:
name: Build matrix success
runs-on: ubuntu-latest
needs:
- prepare-matrix
- test
if: ${{ needs.prepare-matrix.outputs.matrix != '' && needs.prepare-matrix.outputs.matrix != '[]' }}
steps:
- name: Check build matrix status
if: ${{ needs.test.result != 'success' }}
run: exit 1
# yamllint enable rule:comments