-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (153 loc) · 4.83 KB
/
release.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Semantic Release
permissions:
contents: write
on:
push:
branches:
- main
env:
REGISTRY: docker.io
IMAGE_NAME: rilesdun/peerplays-explorer-api
jobs:
pylint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4.0.0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.7.0
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Upgrade pip and install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)" >> $GITHUB_ENV
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
bandit-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.0.0
- name: Set up Python
uses: actions/setup-python@v4.7.0
with:
python-version: '3.x'
- name: Install Bandit
run: pip install bandit
- name: Create report directory
run: mkdir -p bandit-security-report
- name: Run Bandit and generate report
run: |
bandit -r src/ -f json -o bandit-security-report/bandit-report.json
python json_to_html.py bandit-security-report/bandit-report.json > bandit-security-report/index.html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./bandit-security-report
commit_message: 'Deploy Bandit report to GitHub Pages'
release:
needs: [pylint, bandit-scan]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.0.0
- name: Setup Node.js
uses: actions/setup-node@v3.8.1
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Semantic Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit CHANGELOG.md
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "chore: update CHANGELOG.md" || echo "No changes to commit"
git push
dockerhub_publish:
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.0.0
- name: Fetch all tags
run: git fetch --tags
- name: Get the latest tag
id: get-latest-tag
run: |
TAG=$(git tag --sort=taggerdate | tail -1)
echo "tag=${TAG}" >> $GITHUB_ENV
echo "${TAG}" > "tag-${TAG}.txt"
- name: Upload tag file
uses: actions/upload-artifact@v3.1.3
with:
name: tag-file
path: "tag-${{ env.tag }}.txt"
- name: Log into Docker Hub
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.0.0
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ env.tag }}
- name: Build and push Docker image
uses: docker/build-push-action@v5.0.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Log out from Docker Hub
run: docker logout ${{ env.REGISTRY }}
deploy:
runs-on: ubuntu-latest
needs: [dockerhub_publish]
steps:
- name: SSH Key Setup
env:
PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: |
echo "$PRIVATE_KEY" > deploy_key
chmod 600 deploy_key
- name: Download tag file
uses: actions/download-artifact@v3.0.2
with:
name: tag-file
- name: Read tag from file
id: read-tag
run: |
TAG=$(cat tag-*.txt)
echo "tag=${TAG}" >> $GITHUB_ENV
- name: Deploy on VM
run: |
ssh -o StrictHostKeyChecking=no -i deploy_key ${{ secrets.VM_USER }}@${{ secrets.VM_IP }} << ENDSSH
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }}
docker stop explorer-api || true
docker rm explorer-api || true
docker run -d --network=explorer -p 5000:5000 --name explorer-api ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }}
ENDSSH