-
Notifications
You must be signed in to change notification settings - Fork 5
265 lines (219 loc) · 8.22 KB
/
release-agent.yml
File metadata and controls
265 lines (219 loc) · 8.22 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Release Agent
on:
push:
tags:
- 'agent-*.*.*'
jobs:
extract-version:
name: Extract version from tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Extract version from tag
id: version
run: |
# Remove refs/tags/ prefix
VERSION=${GITHUB_REF#refs/tags/}
# Remove 'agent-' prefix
VERSION=${VERSION#agent-}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
test:
name: Run tests
runs-on: ubuntu-latest
container:
image: ghcr.io/opensecflow/netdriver/python-poetry
permissions:
contents: read
packages: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Verify Poetry installation
run: |
poetry --version
poetry self show plugins
- name: Install dependencies
run: poetry install --no-interaction
- name: Run pylint
run: |
echo "Running pylint checks..."
poetry run pylint bases/netdriver/agent components/ --exit-zero --output-format=colorized || true
continue-on-error: true
- name: Run pytest for agent
run: |
echo "Running pytest for agent..."
poetry run pytest -v --tb=short --mock-dev
build-and-publish:
name: Build and Publish Agent to PyPI
needs: [extract-version, test]
runs-on: ubuntu-latest
container:
image: ghcr.io/opensecflow/netdriver/python-poetry
permissions:
contents: write
packages: read
id-token: write # Required for trusted publishing
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Verify Poetry installation
run: |
poetry --version
poetry self show plugins
- name: Install dependencies
run: poetry install --no-interaction
- name: Update agent version
run: |
VERSION=${{ needs.extract-version.outputs.version }}
echo "Updating netdriver-agent version to $VERSION"
poetry version $VERSION -C projects/agent
- name: Build agent
run: |
echo "Building netdriver-agent..."
poetry build-project -C projects/agent --format wheel
- name: Check package metadata
run: |
pip install twine
twine check projects/agent/dist/*.whl
- name: Publish to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry config pypi-token.pypi "$PYPI_TOKEN"
echo "Publishing netdriver-agent to PyPI..."
poetry publish -C projects/agent --skip-existing
- name: Upload wheel artifact
uses: actions/upload-artifact@v4
with:
name: agent-wheel
path: projects/agent/dist/*.whl
retention-days: 1
build-docker-image:
name: Build and Push Agent Docker Image
needs: [extract-version, test]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/netdriver-agent
tags: |
type=semver,pattern={{version}},value=${{ needs.extract-version.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.extract-version.outputs.version }}
type=semver,pattern={{major}},value=${{ needs.extract-version.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./projects/agent/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
create-release:
name: Create GitHub Release with Assets
needs: [extract-version, build-and-publish, build-docker-image]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download wheel artifact
uses: actions/download-artifact@v4
with:
name: agent-wheel
path: ./dist
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: NetDriver Agent ${{ needs.extract-version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
files: ./dist/*.whl
body: |
## netdriver-agent ${{ needs.extract-version.outputs.version }}
### 📦 Package
**netdriver-agent** - FastAPI-based REST API service for network device automation
### 🛠️ Preparation
```bash
# Create directories
mkdir -p config/agent logs
# Download default configuration
curl -o config/agent/agent.yml https://raw.githubusercontent.com/${{ github.repository }}/master/config/agent/agent.yml
```
### 📥 Installation
**PyPI:**
```bash
pip install netdriver-agent==${{ needs.extract-version.outputs.version }}
```
**Docker:**
```bash
# Pull the image
docker pull ghcr.io/opensecflow/netdriver-agent:${{ needs.extract-version.outputs.version }}
# Run the agent
docker run -d -p 8000:8000 \
-v $(pwd)/config:/app/config \
-v $(pwd)/logs:/app/logs \
ghcr.io/opensecflow/netdriver-agent:${{ needs.extract-version.outputs.version }}
```
**Available tags:** `${{ needs.extract-version.outputs.version }}`, `latest`
**Platforms:** `linux/amd64`, `linux/arm64`
### 📝 Changes
See [CHANGELOG](https://github.com/OpenSecFlow/netdriver/blob/master/CHANGELOG.md) for detailed changes.
verify:
name: Verify publication
needs: [extract-version, build-and-publish, build-docker-image, create-release]
runs-on: ubuntu-latest
steps:
- name: Wait for PyPI to process
run: sleep 60
- name: Verify package on PyPI
run: |
echo "Checking netdriver-agent on PyPI..."
curl -s https://pypi.org/pypi/netdriver-agent/json | jq -r '.info.version' || echo "Package not found yet"
- name: Verify Docker image
run: |
echo "Docker image published:"
echo "- ghcr.io/${{ github.repository }}/netdriver-agent:${{ needs.extract-version.outputs.version }}"
- name: Generate summary
run: |
VERSION=${{ needs.extract-version.outputs.version }}
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Agent release created successfully" >> $GITHUB_STEP_SUMMARY
echo "✅ Package published to PyPI" >> $GITHUB_STEP_SUMMARY
echo "✅ Docker image published to GHCR" >> $GITHUB_STEP_SUMMARY
echo "✅ Wheel file attached to release" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Installation" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**PyPI:**" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install netdriver-agent" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Docker:**" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "docker pull ghcr.io/${{ github.repository }}/netdriver-agent:${VERSION}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY