-
Notifications
You must be signed in to change notification settings - Fork 6
162 lines (143 loc) · 5.01 KB
/
ci.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
155
156
157
158
159
160
161
162
############################################################################
# Bitbucket CLI (bb): Work seamlessly with Bitbucket from the command line
#
# Copyright (C) 2022 P S, Adithya (psadi) ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
############################################################################
name: Continuous Integration
on:
workflow_dispatch: {}
push:
branches: ["main"]
pull_request:
types: [opened, synchronize, reopened]
branches: ["main"]
release:
types: [published]
jobs:
build:
runs-on: ${{ matrix.os }}
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
language: ["python"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: Prepare Environment, Sync Dependences and Run Tox
run: |
mkdir -p ~/.config/bb
cp config.ini ~/.config/bb
pdm fix
pdm sync
pdm run tox
- name: SonarCloud Scan
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.projectKey=psadi_bbcli
-Dsonar.organization=psadi
-Dsonar.python.version=3
-Dsonar.sources=bb
-Dsonar.tests=tests
-Dsonar.python.coverage.reportPaths=coverage.xml
-Dsonar.exclusions=tests
- name: Initialize CodeQL
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name == 'release' }}
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Autobuild
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name == 'release' }}
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name == 'release' }}
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
- name: Run build and generate artifacts
run: |
pdm build
- uses: actions/upload-artifact@v4
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
name: workspace
path: .
upload_binaries_to_release:
name: "Upload binaries to current release"
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs: "build"
steps:
- uses: actions/download-artifact@v4
with:
name: workspace
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/bb-*
tag: ${{ github.ref }}
overwrite: true
file_glob: true
push_to_registry:
name: Build, Scan & Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: "build"
steps:
- uses: actions/download-artifact@v4
with:
name: workspace
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: |
docker build -t docker.io/psadi/bbcli:${{ steps.meta.outputs.tags || github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: docker.io/psadi/bbcli:${{ steps.meta.outputs.tags || github.sha }}
format: "sarif"
output: "trivy-results.sarif"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
- name: Push Docker Image
if: ${{ github.event_name == 'release' }}
run: |
docker push docker.io/psadi/bbcli:${{ steps.meta.outputs.tags || github.sha }}