-
Notifications
You must be signed in to change notification settings - Fork 1
117 lines (96 loc) · 3.47 KB
/
Copy pathpull_request.yml
File metadata and controls
117 lines (96 loc) · 3.47 KB
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
name: Pull Request
on:
pull_request:
branches:
- "main"
env:
AZURE_CONTAINER_REGISTRY: ${{ secrets.AZURE_CONTAINER_REGISTRY }}
CONTAINER_NAME: "sensor-dashboard"
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }}
IMAGE_PULL_SECRET_NAME: ${{ secrets.IMAGE_PULL_SECRET_NAME }}
DEPLOYMENT_MANIFEST_PATH: "deployment.yml"
jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12
# ESLint must be in `package.json`
- name: Install Node.js dependencies
run: npm ci
- name: Run linters
run: npm run lint
run-tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Install Node.js dependencies
run: npm ci
- name: Test
run: npm test -- --ci --coverage --maxWorkers=2
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
needs: [run-tests, run-linters]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate Tag
id: generate_tag
run: |
sha=${{ github.event.pull_request.head.sha }}
tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}"
echo "##[set-output name=GIT_TAG;]$(echo ${tag})"
- name: Generate image repository path
id: image_repository_op
run: |
echo IMAGE_REPOSITORY=$(echo ${{ secrets.REGISTRY_LOGIN_SERVER }}/${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Set environment variables
run: |
touch .env && echo "REACT_APP_EVENTPROCESSOR_URL=${{ secrets.EVENTPROCESSOR_URL }}" >> .env
- name: Login to Docker Hub
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Comment on PR
uses: mshick/add-pr-comment@v1
env:
GITHUB_TOKEN: ${{ secrets.ECM3440_GITHUB_TOKEN }}
with:
message: "@${{ github.actor }} Image is available for testing. `docker pull ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}`"
allow-repeats: false
- name: Notify Failure
if: failure()
uses: mshick/add-pr-comment@v1
env:
GITHUB_TOKEN: ${{ secrets.ECM3440_GITHUB_TOKEN }}
with:
message: "@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!"
allow-repeats: false