-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (91 loc) · 3.48 KB
/
github-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
name: app-pecha-frontend
on: [ push, pull_request,workflow_dispatch ]
jobs:
gitleaks:
name: Gitleaks Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Gitleaks
uses: dhsathiya/gitleaks-action@main
with:
config: .gitleaks.toml # Optional: Use a custom config file if available
fail: true # Fail workflow if secrets are detected
verbose: true # Enable detailed output
- name: Upload Gitleaks Report (Optional)
if: failure()
uses: actions/upload-artifact@v3
with:
name: gitleaks-report
path: gitleaks-report.json
buildDockerImage:
name: Build and Dockerize
runs-on: ubuntu-latest
needs: [ gitleaks ]
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: log in Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.PECHA_REPO }}
- name: Set short git commit SHA
id: vars
run: |
if [[ -n "${{ github.ref }}" && "${{ github.ref }}" =~ ^refs/tags/ ]]; then
tagNumber=$(echo "${{ github.ref }}" | sed 's#refs/tags/##')
echo "IMAGE_TAG=$tagNumber" >> $GITHUB_ENV
else
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "IMAGE_TAG=${{ github.run_id }}-$calculatedSha" >> $GITHUB_ENV
fi
- name: Confirm git commit SHA output
run: echo ${{ env.IMAGE_TAG }}
- name: Build Docker image in Github container registry
run: |
lower_owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker build -t ghcr.io/$lower_owner/pecha-frontend:${{ env.IMAGE_TAG }} .
- name: Push Docker image to GHCR
run: |
lower_owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker push ghcr.io/$lower_owner/pecha-frontend:${{ env.IMAGE_TAG }}
- name: Trigger Render Deployment
run: |
lower_owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
image_url=ghcr.io/$lower_owner/pecha-frontend:${{ env.IMAGE_TAG }}
encoded_url=$(python -c "import urllib.parse; print(urllib.parse.quote('${image_url}'))")
echo "Encoded URL: $encoded_url"
curl -X POST "${{ secrets.RENDER_DEPLOY_HOOK_URL }}?imgURL=${encoded_url}"
sonarQube:
if: github.event_name == 'workflow_dispatch'
name: SonarQube Scan
needs: [buildDockerImage]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python version
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Run tests with coverage
run: poetry run pytest --cov=your_package_name --cov-report=xml
- name: SonarQube Scan
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=your_project_key
-Dsonar.organization=your_organization
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.python.version=3.12