-
Notifications
You must be signed in to change notification settings - Fork 2
196 lines (158 loc) · 5.83 KB
/
ci.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
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
name: CI
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'examples/react-dapp/**'
- 'examples/react-signer/**'
- 'packages/identitykit/**'
- 'packages/postmessage-rpc/**'
- 'docker-for-e2e/**'
pull_request:
types:
- opened
- synchronize
env:
IMAGE_NAME: nfid-public-test
jobs:
check-formatting:
name: Check Formatting
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repo.
uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache Node Modules
uses: actions/cache@v4
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: npm
- name: Install dependencies
run: npm install --frozen-lockfile
- name: Lint
run: npm run lint:check
- name: Check Formatting
run: npm run format:check
- name: Build
run: npm run build-ci
docker-for-e2e:
name: Docker Image Build
runs-on: ubuntu-latest
needs: check-formatting
permissions:
packages: write
contents: read
steps:
- name: Checkout repo.
uses: actions/checkout@v4
- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Pull Build Push Image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}
# Change all uppercase to lowercase
IMAGE_ID=$(echo ${IMAGE_ID} | tr '[A-Z]' '[a-z]')
# Check is this pull request
if [ -z "${{ github.head_ref }}" ]; then
# If NOT
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
else
# If YES
# Strip git ref prefix from version and left pull-request number
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\([0-9]\+\)/\(.*\),\1-\2,')
fi
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo ${VERSION} | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "${VERSION}" == "main" ] && VERSION=latest
echo "[INFO] IMAGE_ID: ${IMAGE_ID}" >&2
echo "[INFO] VERSION : ${VERSION}" >&2
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect ${IMAGE_ID}:${VERSION} >/dev/null; then
echo "[INFO] Docker image '${IMAGE_ID}:${VERSION}' was found" >&2
DOCKER_REBUILD="false"
else
echo "[WARN] Image '${IMAGE_ID}:${VERSION}' was not found" >&2
DOCKER_REBUILD="true"
fi
if git log -1 --name-only --pretty='' | grep -q docker-for-e2e; then
echo "[WARN] Files in docker-for-e2e folder was changed" >&2
DOCKER_REBUILD="true"
fi
if [ "${DOCKER_REBUILD}" == "true" ] || [ "${{ github.event.inputs.docker_rebuild }}" == "true" ]; then
echo "[WARN] Will try to build the Docker Image." >&2
pushd ./docker-for-e2e
docker build . \
--build-arg USER_ID=$(id -u) \
--build-arg GROUP_ID=$(id -g) \
--file Dockerfile \
--tag ${IMAGE_NAME} \
--label "runnumber=${GITHUB_RUN_ID}"
docker tag ${IMAGE_NAME} ${IMAGE_ID}:${VERSION}
docker push ${IMAGE_ID}:${VERSION}
fi
e2e-tests:
name: Tests
needs: docker-for-e2e
runs-on: ubuntu-latest
steps:
- name: Checkout repo.
uses: actions/checkout@v4
- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Pull Image and preparing Env Vars
id: pull_image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}
# Change all uppercase to lowercase
IMAGE_ID=$(echo ${IMAGE_ID} | tr '[A-Z]' '[a-z]')
# Check is this pull request
if [ -z "${{ github.head_ref }}" ]; then
# If NOT
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
else
# If YES
# Strip git ref prefix from version and left pull-request number
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\([0-9]\+\)/\(.*\),\1-\2,')
fi
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo ${VERSION} | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "${VERSION}" == "main" ] && VERSION=latest
echo "[INFO] IMAGE_ID: ${IMAGE_ID}" >&2
echo "[INFO] VERSION : ${VERSION}" >&2
docker pull ${IMAGE_ID}:${VERSION}
TEST_ADD_PARAMS=""
echo "IMAGE_ID=${IMAGE_ID}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "CI_DEBUG=${CI_DEBUG}" >> $GITHUB_ENV
echo "TEST_ADD_PARAMS="${TEST_ADD_PARAMS}"" >> $GITHUB_ENV
- name: Cache Node Modules
uses: actions/cache@v4
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: npm
- name: Run tests
env:
CI_DEBUG: true
run: |
docker run --rm \
-v $(pwd):/home/user/workdir \
-e CI_DEBUG="${CI_DEBUG}" \
${IMAGE_ID}:${VERSION} \
"${TEST_ADD_PARAMS}"