-
Notifications
You must be signed in to change notification settings - Fork 48
163 lines (139 loc) · 6.87 KB
/
Copy pathmain.yml
File metadata and controls
163 lines (139 loc) · 6.87 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
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
name: CI/CD GreenCityClient
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the dev branch
push:
branches: [prod-branch, dev]
pull_request:
branches: [prod-branch, dev]
workflow_dispatch:
permissions:
contents: read
checks: write
pull-requests: write
env:
repository: client
dockerRepoName: skyere/greencity-front
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
# Steps
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
# - name: Set up Go
# uses: actions/setup-go@v3
# with:
# go-version: 1.18
# Runs a set of commands using the runners shell
- name: Install
run: |
npm install
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt-get install ./google-chrome-stable_current_amd64.deb -y --allow-downgrades
- name: Build Test Environment
run: npx ts-node ./scripts/setenv.ts
- name: JS Linter
run: npm run lint
- name: CSS Linter
run: npm run stylelint
- name: Unit Tests
run: npx ng test --watch=false --progress=false --code-coverage=true --browsers=ChromeHeadless
- name: Normalize lcov paths
run: |
IN=coverage/GreenCityClient/lcov.info
if [ -f "$IN" ]; then
sed -E 's|SF:.*/(src/.*)|SF:\1|' "$IN" > "$IN.tmp" && mv "$IN.tmp" "$IN"
else
echo "Missing lcov: $IN" >&2
exit 1
fi
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v5.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.organization=ita-social-projects
-Dsonar.projectKey=ita-social-projects-green-city-client
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.sources=src
-Dsonar.exclusions=**/node_modules/**,src/app/component/user/components/profile/calendar/calendar-image.*,src/app/component/user/components/profile/calendar/calendar-week/calendar-image.*,src/environments/environment.prod.*,src/app/image-pathes/auth-images.*,src/app/image-pathes/profile-icons.*,src/app/image-pathes/profile-images.*,src/app/image-pathes/single-news-images.*,src/app/image-pathes/sign-in-icons.*,src/app/component/about/about-routing.module.*,src/app/component/about/about.module.*,src/app/component/eco-news/eco-news-routing.module.*,src/app/component/eco-news/eco-news.module.*,src/app/component/map/map-routing.module.*,src/app/component/map/map.module.*,src/app/component/user/user-routing.module.*,src/app/component/user/user.module.*,src/app/app-routing.module.*,src/app/component/shared/shared.module.*,src/app/component/admin/admin-routing.module.*,src/app/component/admin/admin.module.*,src/app/app.module.*,src/app/component/auth/auth.module.*,src/app/component/core/core.module.*,src/app/component/home/home.module.*,src/app/component/layout/layout.module.*,src/app/model/weekDays.model.*,src/app/model/achievement/AchievementDto.*,src/app/model/advice/AdviceDto.*,src/app/model/filtering/filter-discount-dto.model.*,src/app/model/filtering/filter-distance-dto.model.*,src/app/model/filtering/filter-place-dto.model.*,src/app/model/habit-fact/HabitFactDto.*,src/app/model/habit/HabitStatisticLogDto.*,src/app/model/habit/HabitStatisticMapDto.*,src/app/model/habit/HabitStatisticsDto.*,src/app/model/habit/NewHabitDto.*,src/app/component/home/models/NewsDto.*,src/app/service/subscription/SubscriptionDto.*,src/app/model/user/userFilterDto.model.*,src/app/store/effects/ecoEvents.effects.*,src/app/ubs/ubs-admin/components/ubs-admin-certificate/ubs-admin-certificate.component.*,src/app/shared/interceptors/interceptor.service.*,src/app/store/reducers/ecoEvents.reducer.*,**/*.mock.ts,**/greencity.routing.module.*,**/*.model.ts
-Dsonar.test.inclusions=**/*.spec.ts
-Dsonar.javascript.lcov.reportPaths=coverage/GreenCityClient/lcov.info
# - name: E2E Tests
# run: npx ng e2e --protractor-config=e2e/protractor-ci.conf.js
- name: Build Environment
env:
PROD_SECRET: ${{ secrets.ENV_PROD }}
STAGE_SECRET: ${{ secrets.ENV_STAGE }}
run: |
if [[ "${{ github.ref }}" == "refs/heads/prod-branch" ]]; then
echo "${{ env.PROD_SECRET }}" > .env.prod
npx ts-node ./scripts/setenv.ts prod
else
echo "${{ env.STAGE_SECRET }}" > .env.stage
npx ts-node ./scripts/setenv.ts stage
fi
- name: Build
run: |
if [[ "${{ github.ref }}" == "refs/heads/prod-branch" ]]; then
npx ng build --configuration production --base-href=/GreenCityClient/
else
npx ng build --configuration=stage --base-href=/GreenCityClient/
fi
- name: Set outputs
run: echo "GITHUB_SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Docker Login
uses: docker/login-action@v2.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v3.0.0
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.dockerRepoName }}:test-${{ env.GITHUB_SHA_SHORT }}
- name: Docker Login
uses: docker/login-action@v2.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v3.0.0
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.dockerRepoName }}:test-${{ env.GITHUB_SHA_SHORT }}
# - name: Kubernetes Set Context
# uses: Azure/k8s-set-context@v3.0
# with:
# kubeconfig: ${{ secrets.KUBE_CONFIG }}
# - name: Kubernetes tests
# run: |
# cd chart-test
# go test -v ./...
# - name: Deploy 🚀
# if: ${{ github.event_name == 'push' }}
# uses: JamesIves/github-pages-deploy-action@3.7.1
# with:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# BRANCH: gh-pages
# FOLDER: dist/GreenCityClient
# CLEAN: true