-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (150 loc) · 5.13 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
name: CI
on: push
env:
IMAGE_NAME: ${{ github.repository }}
NODE_VERSION: '16'
jobs:
check-image:
name: Check for existing image
runs-on: 'ubuntu-latest'
outputs:
exists: ${{ steps.request-image-info.outputs.exists }}
steps:
- id: request-image-info
run: |
response_code=$(curl -s -o /dev/null -I -L -w "%{http_code}" https://hub.docker.com/v2/repositories/${{ env.IMAGE_NAME }}/tags/${{ github.sha }}/)
echo $response_code
if [ $response_code -eq 200 ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "::notice ::Found existing image ${{ github.repository }}:${{ github.sha }}"
elif [ $response_code -eq 404 ]; then
echo "exists=false" >> $GITHUB_OUTPUT
else
echo "::error ::Got unexpected HTTP code $response_code"
exit 22
fi
build-image:
name: Build image
runs-on: 'ubuntu-latest'
needs: check-image
if: ${{ needs.check-image.outputs.exists == 'false' }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build the project
run: npm run build
- name: Build Docker image
run: docker build --tag ${{ github.repository }}:${{ github.sha }} .
- name: Publish to DockerHub
run: |
docker push ${{ github.repository }}:${{ github.sha }}
echo "::notice ::Published as ${{ github.repository }}:${{ github.sha }}"
tag-image-ref:
name: Publish image
runs-on: 'ubuntu-latest'
needs: build-image
if: ${{ success() || needs.build-image.result == 'skipped' }}
steps:
- uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: rlespinasse/github-slug-action@v4
- name: Pull Docker image
run: docker pull ${{ github.repository }}:${{ github.sha }}
- name: Tag Docker image
run: docker tag ${{ github.repository }}:${{ github.sha }} ${{ github.repository }}:${{ env.GITHUB_REF_SLUG }}
- name: Publish to DockerHub
run: |
docker push ${{ github.repository }}:${{ env.GITHUB_REF_SLUG }}
echo "::notice ::Published as ${{ github.repository }}:${{ env.GITHUB_REF_SLUG }}"
lint:
name: Lint
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: Lint
run: npm run lint
cypress-tests:
name: Cypress tests
runs-on: ubuntu-latest
needs: build-image
if: ${{ success() || needs.build-image.result == 'skipped' }}
services:
frontend:
image: ${{ github.repository }}:${{ github.sha }}
env:
EDU_SHARING_API_URL: https://redaktion.openeduhub.net/edu-sharing/rest
ports:
- 8080:80
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cypress run
uses: cypress-io/github-action@v4
env:
CYPRESS_baseUrl: http://localhost:8080
# We cannot guarantee that the given Edu-Sharing instance allows localhost with
# 'Access-Control-Allow-Origin'.
CYPRESS_chromeWebSecurity: false
with:
working-directory: e2e-cypress
- uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: e2e-cypress/cypress/screenshots
build-web-components:
name: Build web components
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build web components
run: npm run build:web-components
- uses: actions/upload-artifact@v1
with:
name: web-components
path: dist/web-components