-
Notifications
You must be signed in to change notification settings - Fork 5
246 lines (201 loc) · 7.74 KB
/
release-simunet.yml
File metadata and controls
246 lines (201 loc) · 7.74 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
name: Release Simunet
on:
push:
tags:
- 'simunet-*.*.*'
jobs:
create-release:
name: Create GitHub Release for Simunet
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: |
# Remove refs/tags/ prefix
VERSION=${GITHUB_REF#refs/tags/}
# Remove 'simunet-' prefix
VERSION=${VERSION#simunet-}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: NetDriver Simunet ${{ steps.version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
body: |
## netdriver-simunet ${{ steps.version.outputs.version }}
### 📦 Package
**netdriver-simunet** - SSH server simulation for testing network device terminals
### 🛠️ Preparation
```bash
# Create directories
mkdir -p config/simunet logs
# Download default configuration
curl -o config/simunet/simunet.yml https://raw.githubusercontent.com/${{ github.repository }}/master/config/simunet/simunet.yml
```
### 📥 Installation
**PyPI:**
```bash
pip install netdriver-simunet==${{ steps.version.outputs.version }}
```
**Docker:**
```bash
# Pull the image
docker pull ghcr.io/opensecflow/netdriver-simunet:${{ steps.version.outputs.version }}
# Run with host network mode
docker run -d --network host \
-v $(pwd)/config:/app/config \
-v $(pwd)/logs:/app/logs \
ghcr.io/opensecflow/netdriver-simunet:${{ steps.version.outputs.version }}
```
**Available tags:** `${{ steps.version.outputs.version }}`, `latest`
**Platforms:** `linux/amd64`, `linux/arm64`
### 📝 Changes
See [CHANGELOG](https://github.com/OpenSecFlow/netdriver/blob/master/CHANGELOG.md) for detailed changes.
test:
name: Run tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install
- name: Install dependencies
run: uv sync
- name: Run pylint
run: |
echo "Running pylint checks..."
uv run pylint bases/netdriver/simunet components/ --exit-zero --output-format=colorized || true
continue-on-error: true
- name: Run pytest for simunet
run: |
echo "Running pytest for simunet..."
uv run pytest -v --tb=short --mock-dev
build-and-publish:
name: Build and Publish Simunet to PyPI
needs: [create-release, test]
runs-on: ubuntu-latest
permissions:
contents: write
packages: read
id-token: write # Required for trusted publishing
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
run: uv sync --all-packages
- name: Update simunet version
run: |
VERSION=${{ needs.create-release.outputs.version }}
echo "Updating netdriver-simunet version to $VERSION"
sed -i 's/^version = ".*"/version = "'$VERSION'"/' packages/simunet/pyproject.toml
- name: Build simunet
run: |
echo "Building netdriver-simunet..."
uv build --directory packages/simunet
- name: Check package metadata
run: |
uv run twine check packages/simunet/dist/*.whl
- name: Publish to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
echo "Publishing netdriver-simunet to PyPI..."
uv publish --directory packages/simunet --token "$PYPI_TOKEN"
- name: Upload wheel to release
uses: softprops/action-gh-release@v1
with:
tag_name: simunet-${{ needs.create-release.outputs.version }}
files: packages/simunet/dist/*.whl
build-docker-image:
name: Build and Push Simunet Docker Image
needs: [create-release, 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-simunet
tags: |
type=semver,pattern={{version}},value=${{ needs.create-release.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.create-release.outputs.version }}
type=semver,pattern={{major}},value=${{ needs.create-release.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./packages/simunet/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
verify:
name: Verify publication
needs: [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-simunet on PyPI..."
curl -s https://pypi.org/pypi/netdriver-simunet/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-simunet:${{ needs.create-release.outputs.version }}"
- name: Generate summary
run: |
VERSION=${{ needs.create-release.outputs.version }}
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Simunet 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-simunet" >> $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-simunet:${VERSION}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY