-
-
Notifications
You must be signed in to change notification settings - Fork 15
156 lines (135 loc) · 4.33 KB
/
continuous-integration.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
name: "Continuous Integration"
on:
pull_request:
push:
branches:
- '[0-9]+.[0-9]+.x'
- 'refs/pull/*'
tags:
env:
TEST_TAG: laminas/ci-matrix-action:test
jobs:
matrix:
name: Generate job matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Checkout sourcecode
uses: actions/checkout@v4
- name: Gather integration test directory names
id: matrix
# This provides a dedicated "check" to asynchronously test all integration tests within the tests/ directory
# The project name from the tests/ directory is then re-used within the "qa" job to run the generated "container"
# within that directory.
run: cd tests; echo "matrix=[\"$(ls -d * | tr '\n' ' ' | sed 's/ $//' | sed 's/ /\",\"/g')\"]" >> $GITHUB_OUTPUT
container:
name: Prepare docker container
runs-on: "ubuntu-latest"
strategy:
fail-fast: true
steps:
- name: Checkout sourcecode
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build container for CI pipeline
uses: docker/build-push-action@v4
with:
context: .
load: true
push: false
tags: ${{ env.TEST_TAG }}
outputs: type=docker,dest=/tmp/container.tar
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Upload container artifact
uses: actions/upload-artifact@v3
with:
name: container
path: /tmp/container.tar
qa:
name: QA Checks
needs: [matrix, container]
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
projectName: ${{ fromJSON(needs.matrix.outputs.matrix) }}
steps:
- name: Checkout sourcecode
uses: actions/checkout@v4
- name: Download container artifact
uses: actions/download-artifact@v3
with:
name: container
path: /tmp
- name: Load image
run: docker load --input /tmp/container.tar
- name: "Generating matrix for project: ${{ matrix.projectName }}"
id: matrix_generation
env:
PROJECT_NAME_TO_TEST: ${{ matrix.projectName }}
run: |
cd tests/${PROJECT_NAME_TO_TEST} && \
docker run \
-i \
--entrypoint "/action/main.js" \
-v $(realpath .):/github/workspace \
--env-file=test.env \
-w=/github/workspace \
${TEST_TAG} $(test -r diff && cat diff || echo -n "")
- name: "Output generated matrix"
uses: sergeysova/jq-action@v2
with:
multiline: true
cmd: "jq . < <(echo '${{ steps.matrix_generation.outputs.matrix }}')"
- name: Minify matrix from test directory
uses: sergeysova/jq-action@v2
id: expected_matrix
env:
PROJECT_NAME_TO_TEST: ${{ matrix.projectName }}
with:
multiline: true
cmd: 'jq -c . < tests/${PROJECT_NAME_TO_TEST}/matrix.json'
- name: "verify output of generated matrix for project: ${{ matrix.projectName }}"
run: diff --color <(echo '${{ steps.expected_matrix.outputs.value }}' | jq --sort-keys) <(echo '${{ steps.matrix_generation.outputs.matrix }}' | jq --sort-keys)
docker-build:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build
uses: docker/build-push-action@v4
with:
push: false
linting:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- uses: "actions/setup-node@v3"
with:
check-latest: true
node-version: 20
- name: "Install node modules"
run: "npm ci"
- name: Run ESLint
run: "npm run lint"
testing:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- uses: "actions/setup-node@v3"
with:
check-latest: true
node-version: 20
- name: "Install node modules"
run: "npm ci"
- name: Run Jest
run: "npm run test"