Skip to content

Commit b6b0772

Browse files
chord: update workflows for more efficient build.
1 parent 43577dd commit b6b0772

File tree

9 files changed

+364
-260
lines changed

9 files changed

+364
-260
lines changed

.github/workflows/QUICKSTART.md

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ This guide will help you quickly set up and publish your packages to PyPI.
55
## Prerequisites
66

77
- GitHub repository with the workflows
8-
- PyPI account (https://pypi.org/account/register/)
9-
- TestPyPI account (https://test.pypi.org/account/register/) - optional but recommended
8+
- PyPI account (<https://pypi.org/account/register/>)
9+
- TestPyPI account (<https://test.pypi.org/account/register/>) - optional but recommended
1010

1111
## Step 1: Get PyPI Tokens
1212

1313
### For PyPI
1414

15-
1. Visit https://pypi.org/manage/account/token/
15+
1. Visit <https://pypi.org/manage/account/token/>
1616
2. Click "Add API token"
1717
3. Fill in:
1818
- Token name: `GitHub Actions - NetDriver`
@@ -22,7 +22,7 @@ This guide will help you quickly set up and publish your packages to PyPI.
2222

2323
### For TestPyPI (Recommended for testing)
2424

25-
1. Visit https://test.pypi.org/manage/account/token/
25+
1. Visit <https://test.pypi.org/manage/account/token/>
2626
2. Follow same steps as above
2727
3. Copy the token
2828

@@ -41,29 +41,25 @@ This guide will help you quickly set up and publish your packages to PyPI.
4141
- Name: `TEST_PYPI_API_TOKEN`
4242
- Secret: Paste your TestPyPI token
4343

44-
## Step 3: Choose Your Workflow
44+
## Step 3: Build CI Docker Image
4545

46-
### Option A: Standard Workflow (Recommended for first-time)
46+
The `publish-pypi.yml` workflow uses a pre-built Docker image for faster execution.
4747

48-
Use `publish-pypi.yml` - installs everything on-the-fly
48+
**Build the image:**
4949

50-
**No additional setup needed!**
51-
52-
### Option B: Docker-based Workflow (Faster)
53-
54-
Use `publish-pypi-docker.yml` - uses pre-built image
50+
1. Go to **Actions****"Build CI Image"**
51+
2. Click **"Run workflow"**
52+
3. Select branch: `master`
53+
4. Click **"Run workflow"**
5554

56-
**Additional setup:**
55+
**Or build locally:**
5756

58-
1. Build the CI image first:
59-
```bash
60-
# Go to Actions → "Build CI Image" → Run workflow
61-
# Or build locally and push
62-
docker build -t ghcr.io/opensecflow/netdriver/ci:latest -f .github/Dockerfile.ci .
63-
docker push ghcr.io/opensecflow/netdriver/ci:latest
64-
```
57+
```bash
58+
docker build -t ghcr.io/opensecflow/netdriver/python-poetry:3.12 -f .github/Dockerfile.ci .
59+
docker push ghcr.io/opensecflow/netdriver/python-poetry:3.12
60+
```
6561

66-
2. Update your workflow to use the image (already configured in `publish-pypi-docker.yml`)
62+
**Note**: This only needs to be done once. The image will be cached and reused.
6763

6864
## Step 4: Test Publishing (Recommended)
6965

@@ -82,10 +78,11 @@ Before publishing to production PyPI, test with TestPyPI:
8278
### Verify on TestPyPI
8379

8480
1. Check your packages:
85-
- https://test.pypi.org/project/netdriver-agent/
86-
- https://test.pypi.org/project/netdriver-simunet/
81+
- <https://test.pypi.org/project/netdriver-agent/>
82+
- <https://test.pypi.org/project/netdriver-simunet/>
8783

8884
2. Test installation:
85+
8986
```bash
9087
pip install --index-url https://test.pypi.org/simple/ netdriver-agent
9188
```
@@ -114,12 +111,15 @@ git add projects/*/pyproject.toml
114111
git commit -m "chore: bump version to 0.3.1"
115112
git push
116113

117-
# 3. Create and push tag
118-
git tag v0.3.1
119-
git push origin v0.3.1
114+
# 3. Create and push tag (without 'v' prefix)
115+
git tag 0.3.1
116+
git push origin 0.3.1
120117
```
121118

119+
**Note**: Both `0.3.1` and `v0.3.1` tag formats are supported.
120+
122121
The `release.yml` workflow will automatically:
122+
123123
- ✅ Create a GitHub Release
124124
- ✅ Build both packages
125125
- ✅ Publish to PyPI
@@ -128,10 +128,11 @@ The `release.yml` workflow will automatically:
128128
## Step 6: Verify Publication
129129

130130
1. Check on PyPI:
131-
- https://pypi.org/project/netdriver-agent/
132-
- https://pypi.org/project/netdriver-simunet/
131+
- <https://pypi.org/project/netdriver-agent/>
132+
- <https://pypi.org/project/netdriver-simunet/>
133133

134134
2. Test installation:
135+
135136
```bash
136137
pip install netdriver-agent
137138
pip install netdriver-simunet
@@ -160,11 +161,15 @@ poetry version -P projects/simunet patch
160161
# Then rebuild and publish
161162
```
162163

163-
### Workflow fails with "Poetry not found"
164+
### Workflow fails with "Poetry not found" or image pull error
164165

165-
**Solution:**
166-
- If using standard workflow: Check Poetry installation step
167-
- If using Docker workflow: Build the CI image first
166+
**Solution:** Build the CI Docker image first
167+
168+
```bash
169+
# Go to Actions → "Build CI Image" → Run workflow
170+
```
171+
172+
Or check the image name matches: `ghcr.io/opensecflow/netdriver/python-poetry:3.12`
168173

169174
### Package shows as "0 B" or malformed
170175

@@ -179,11 +184,13 @@ unzip -l projects/agent/dist/netdriver_agent-*.whl
179184
### Version Management
180185

181186
**DO:**
187+
182188
- Keep version numbers in sync across `projects/agent/pyproject.toml` and `projects/simunet/pyproject.toml`
183189
- Use semantic versioning: `MAJOR.MINOR.PATCH`
184190
- Test on TestPyPI before production
185191

186192
**DON'T:**
193+
187194
- Publish the same version twice
188195
- Skip testing on TestPyPI
189196
- Use local version identifiers for production (e.g., `0.3.0+local`)
@@ -214,6 +221,6 @@ unzip -l projects/agent/dist/netdriver_agent-*.whl
214221
## Need Help?
215222

216223
- 📖 Full documentation: `.github/workflows/README.md`
217-
- 🐛 Report issues: https://github.com/OpenSecFlow/netdriver/issues
218-
- 📝 PyPI Help: https://pypi.org/help/
219-
- 🎯 GitHub Actions: https://docs.github.com/en/actions
224+
- 🐛 Report issues: <https://github.com/OpenSecFlow/netdriver/issues>
225+
- 📝 PyPI Help: <https://pypi.org/help/>
226+
- 🎯 GitHub Actions: <https://docs.github.com/en/actions>

.github/workflows/README.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This directory contains GitHub Actions workflows for automated building, testing
1919

2020
**Usage**: Automatically runs on PR creation and commits
2121

22-
### 2. Publish to PyPI (`publish-pypi.yml` / `publish-pypi-docker.yml`)
22+
### 2. Publish to PyPI (`publish-pypi.yml`)
2323

2424
**Trigger**:
2525

@@ -30,6 +30,7 @@ This directory contains GitHub Actions workflows for automated building, testing
3030

3131
**What it does**:
3232

33+
- Uses pre-built Docker container with Poetry installed
3334
- Builds wheel packages for selected projects
3435
- Publishes to PyPI or TestPyPI
3536
- Uploads build artifacts
@@ -43,10 +44,7 @@ This directory contains GitHub Actions workflows for automated building, testing
4344
- **Projects**: `all`, `agent`, `simunet`, or `agent,simunet`
4445
4. Click "Run workflow"
4546

46-
**Two versions available**:
47-
48-
- **`publish-pypi.yml`**: Standard workflow, installs Poetry and Python on-the-fly
49-
- **`publish-pypi-docker.yml`**: Uses pre-built Docker container (faster)
47+
**Note**: Requires the CI Docker image to be built first (see section 4 below)
5048

5149
### 3. Release and Publish (`release.yml`)
5250

@@ -71,10 +69,12 @@ poetry version patch # or minor, major
7169
git add projects/*/pyproject.toml
7270
git commit -m "chore: bump version to 0.3.1"
7371

74-
# Create and push tag
75-
git tag v0.3.1
72+
# Create and push tag (without 'v' prefix)
73+
git tag 0.3.1
7674
git push origin master
77-
git push origin v0.3.1
75+
git push origin 0.3.1
76+
77+
# Note: Both '0.3.1' and 'v0.3.1' formats are supported
7878
```
7979

8080
## Setup Requirements
@@ -152,8 +152,8 @@ GitHub Actions supports PyPI's trusted publishing (no token needed):
152152
4. **Create and push tag**:
153153

154154
```bash
155-
git tag v0.3.1
156-
git push origin v0.3.1
155+
git tag 0.3.1
156+
git push origin 0.3.1
157157
```
158158

159159
5. **Workflow will automatically**:
@@ -239,14 +239,14 @@ docker build -t netdriver-ci -f .github/Dockerfile.ci .
239239

240240
**Using the custom image in workflows**:
241241

242-
The `publish-pypi-docker.yml` workflow demonstrates usage:
242+
The `publish-pypi.yml` workflow uses this approach:
243243

244244
```yaml
245245
jobs:
246246
publish:
247247
runs-on: ubuntu-latest
248248
container:
249-
image: ghcr.io/opensecflow/netdriver/ci:latest
249+
image: ghcr.io/${{ github.repository }}/python-poetry:3.12
250250
steps:
251251
- uses: actions/checkout@v4
252252
# Poetry and plugins are already installed!
@@ -262,18 +262,15 @@ jobs:
262262
263263
**Image locations**:
264264
265-
- GitHub Container Registry: `ghcr.io/opensecflow/netdriver/ci:latest`
265+
- GitHub Container Registry: `ghcr.io/opensecflow/netdriver/python-poetry:3.12`
266266
- Available tags: `latest`, `master`, `<branch>-<sha>`
267267

268-
### Workflow Comparison
268+
**Benefits**:
269269

270-
| Feature | Standard (`publish-pypi.yml`) | Docker (`publish-pypi-docker.yml`) |
271-
|---------|------------------------------|-----------------------------------|
272-
| Setup time | ~2-3 minutes | ~30 seconds |
273-
| Python/Poetry | Installed each run | Pre-installed in image |
274-
| Cache | Uses GitHub Actions cache | Uses Docker layer cache |
275-
| Flexibility | More flexible | Faster but less flexible |
276-
| Best for | Development/testing | Production releases |
270+
- ⚡ **Faster**: Setup in ~30 seconds vs ~2-3 minutes
271+
- 🔒 **Consistent**: Same environment across all workflows
272+
- 💾 **Cacheable**: Docker layer caching
273+
- 🎯 **Reproducible**: Exact versions every time
277274

278275
## Project Structure
279276

@@ -284,8 +281,7 @@ netdriver/
284281
│ └── workflows/
285282
│ ├── build-ci-image.yml # Build Docker image
286283
│ ├── build-test.yml # PR/push build validation
287-
│ ├── publish-pypi.yml # Standard publishing
288-
│ ├── publish-pypi-docker.yml # Docker-based publishing
284+
│ ├── publish-pypi.yml # Docker-based publishing
289285
│ └── release.yml # Tag-based release
290286
├── bases/
291287
│ └── netdriver/
@@ -315,7 +311,7 @@ docker push your-registry/netdriver-ci:latest
315311

316312
### 2. Update workflow file
317313

318-
Edit `publish-pypi-docker.yml`:
314+
Edit `publish-pypi.yml`:
319315

320316
```yaml
321317
container:
@@ -325,13 +321,15 @@ container:
325321
password: ${{ secrets.DOCKER_PASSWORD }}
326322
```
327323

328-
### 3. Skip Poetry installation
324+
### 3. Verify Poetry is available
329325

330-
Since Poetry is pre-installed, remove or comment out:
326+
Poetry and plugins are pre-installed, so you can use them directly:
331327

332328
```yaml
333-
# - name: Install Poetry and plugins # Already in image
334-
# run: pip install poetry ...
329+
- name: Verify Poetry installation
330+
run: |
331+
poetry --version
332+
poetry self show plugins
335333
```
336334

337335
## References

.github/workflows/build-ci-image.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ on:
88
- main
99
paths:
1010
- '.github/Dockerfile.ci'
11-
schedule:
12-
# Rebuild weekly to get security updates
13-
- cron: '0 0 * * 0'
1411

1512
env:
1613
REGISTRY: ghcr.io
17-
IMAGE_NAME: ${{ github.repository }}/ci
14+
IMAGE_NAME: ${{ github.repository }}/python-poetry:3.12
1815

1916
jobs:
2017
build:

0 commit comments

Comments
 (0)