-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (128 loc) · 4.45 KB
/
ci-code-approval.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
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: "Code Approval"
on:
merge_group:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types:
- opened
- reopened
- synchronize # source branch updated
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
issues: write
jobs:
golang-ci-lint:
name: Golangci-lint
runs-on: ubuntu-latest
steps:
# Sets up golang
- uses: actions/setup-go@v5
with:
go-version: ${{ vars.GO_VERSION }}
cache-dependency-path: "**/*.sum"
- name: Checkout repository
uses: actions/checkout@v4
- name: "Configure git for private modules"
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
only-new-issues: true
args: --verbose --timeout 5m
openapi-lint:
name: OpenAPI Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Hide any previous plan comments from the Pull Request to keep things tidy
- id: hide_previous_plan
name: Hide previous plan
if: github.event_name == 'pull_request'
uses: kanga333/comment-hider@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
hide_user_name: "github-actions[bot]"
hide_reason: "OUTDATED"
leave_visible: 0 # leave the last 0 comments visible
- name: Install IBM OpenAPI Validator
run: |
npm install -g ibm-openapi-validator
npm install @ibm-cloud/openapi-ruleset
- name: Install Dependencies
run: |
sudo apt-get install jq
- name: Install GUM
run: |
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum
- name: Lint OpenAPI
shell: bash
run: |
chmod +x openapi-lint.sh
./openapi-lint.sh
- name: Upload the report
# Run this step on all PR's even if the linting fails
if: ${{ failure() && github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@v3
with:
# Full file path to the plan output
file-path: ${{ github.workspace }}/pr-report.md
pr-number: ${{ github.event.pull_request.number }}
create-if-not-exists: true
code-approval:
name: "Code Approval"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ vars.GO_VERSION }}
cache-dependency-path: "**/*.sum"
- name: "Configure git for private modules"
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com"
- name: Make
run: make pr-approval
code-generation:
name: "Code Generation"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ vars.GO_VERSION }}
cache-dependency-path: "**/*.sum"
- name: "Configure git for private modules"
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com"
- name: "Install dependencies"
run: make deps
- name: "Run Code Generation"
run: make codegen
env:
GS_SILENT: true
- name: "fmt"
run: go fmt ./...
- name: "Fail if code generation changes files"
run: git diff --exit-code