-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (114 loc) · 4.2 KB
/
main.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
name: CI test
on:
pull_request:
permissions:
contents: read
env:
working-directory: "${{ github.workspace }}"
workflow-directory: "${{ github.workspace }}/.github/workflows"
sonar-url: https://sonarqube.tom.takeoff.com
jobs:
code-analysis:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
go-version: [ 1.19 ]
steps:
- name: checkout repo
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Configure access to download dependencies in Go
shell: bash
run: git config --global url."https://${{ secrets.TAKEOFFBOT_TOKEN }}:@github.com/TakeoffTech/".insteadOf "https://github.com/TakeoffTech/"
- name: Load Cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
path: |
~/go/pkg/mod
~/Library/Caches/go-build
key: go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-${{ matrix.go-version }}-
- name: Test with untidy Go module
id: bad
continue-on-error: true
run: |
go mod tidy
- name: Check build
run: |
go build ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
id: lint
with:
go-version: ${{ matrix.go-version }}
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.50.1
# hack for files and lines viewing
skip-cache: true
args: "-v --out-${NO_FUTURE}format colored-line-number"
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
with:
project_id: "project-id"
install_components: 'beta,cloud-firestore-emulator,pubsub-emulator'
- name: 'Use gcloud CLI'
run: 'gcloud info'
- name: 'Use gcloud emulator'
run: |
gcloud beta emulators firestore start --quiet --project "project-id" --host-port=localhost:8040 &
gcloud beta emulators pubsub start --quiet --project "project-id" --host-port=localhost:8041 &
- name: Test
run: |
export FIRESTORE_EMULATOR_HOST=localhost:8040
export PUBSUB_EMULATOR_HOST=localhost:8041
go test -v ./... -coverpkg=./... -race -covermode=atomic -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage_badge.out
- name: Upload coverage file
uses: actions/upload-artifact@v3
with:
name: site_info_svc_coverage
if-no-files-found: error
path: coverage_badge.out
- name: "SonarQube scan (PR)"
if: github.ref != 'refs/heads/main'
uses: sonarsource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: ./
args: >
-Dsonar.pullrequest.key=${{ github.event.number }}
-Dsonar.pullrequest.branch=${{ github.HEAD_REF }}
-Dsonar.pullrequest.base=${{ github.BASE_REF }}
-Dsonar.pullrequest.github.repository=${{ github.repository }}
-Dsonar.scm.provider=git
- name: "SonarQube scan (master)"
id: sonar-scan-main
if: github.ref == 'refs/heads/main'
uses: sonarsource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: ./
args: >
-Dsonar.scm.provider=git
# Check the Quality Gate status.
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time.
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} #OPTIONAL