forked from ganatan/angular-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (82 loc) · 3.23 KB
/
build.yml
File metadata and controls
97 lines (82 loc) · 3.23 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
name: Build
env:
GH_TOKEN: ${{ secrets.token }}
on:
push:
branches: master
pull_request:
branches: master
jobs:
## Main job
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
# Setup environment
- name: Setup node
uses: actions/setup-node@v3
with:
cache-dependency-path: angular/package-lock.json
# Installing dependencies
- name: Installing dependencies
run: cd ${{ github.workspace }}/angular && npm install
# Run tests
- name: test
id: test
uses: GabrielBB/xvfb-action@v1
with:
run: cd ${{ github.workspace }}/angular && npm run test
- name: Pass or fail
if: failure()
run: exit 1
# Build app
- name: build app
run: cd ${{ github.workspace }}/angular && npm run build
# Build docker image
- name: docker image build
run: docker build -t ghcr.io/awameg/nginx-angular:latest -t ghcr.io/awameg/nginx-angular:${GITHUB_SHA::8} .
- name: docker login
run: docker login ghcr.io -u $GITHUB_ACTOR -p ${{secrets.GITHUB_TOKEN}}
- name: Publish docker image
run: docker push ghcr.io/awameg/nginx-angular:latest && docker push ghcr.io/awameg/nginx-angular:${GITHUB_SHA::8}
## Notification job - it starts after the main
notification:
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Check out repository code
uses: actions/checkout@v3
# Get email from git log
- name: get email
id: get-email
run: echo "::set-output name=email::$(git log -n 1 --pretty=format:%ae)"
# Get execution time for notification
- name: get time
id: get-time
run: echo "::set-output name=time::$(gh run list --workflow build.yml | head -n 1 | awk -F'\t' '{print $8}')"
# Notifications
- name: Send mail success
if: success()
uses: dawidd6/action-send-mail@v2
with:
server_address: smtp.yandex.ru
server_port: 465
username: ${{ secrets.EMAIL_NOTIFY }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
body: "${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}. \nExecution time: ${{ steps.get-time.outputs.time }}"
to: ${{ steps.get-email.outputs.email }}
from: GitHub ${{ github.repository }}
- name: Send mail failure
if: failure()
uses: dawidd6/action-send-mail@v2
with:
server_address: smtp.yandex.ru
server_port: 465
username: ${{ secrets.EMAIL_NOTIFY }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: ${{ github.job }} job of ${{ github.repository }} has FAILED!!!
body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has FAILED!!!
to: ${{ steps.get-email.outputs.email }}
from: GitHub ${{ github.repository }}