- Go to https://pypi.org/manage/account/tokens/
- Create new token with scope "Entire account"
- Copy token
- Go to repository Settings
- Secrets and variables → Actions
- New repository secret
- Name:
PYPI_API_TOKEN - Value: Paste token from step 1
- Go to Settings → Environments
- New environment
- Name:
pypi - (Optional) Add deployment branch restrictions
- Go to Settings → Branches
- Add branch protection rule
- Branch name pattern:
main - Require status checks:
linttest (Python 3.12)build
- Runs on: Push to main/develop, PRs, manual trigger
- Jobs: Lint, Test (3.11/3.12/3.13), Security, Build
- Time: ~5-10 minutes
- Runs on: Push, PRs, daily schedule, manual trigger
- Jobs: CodeQL, Dependency check, Secret scan, SBOM
- Time: ~10-15 minutes
- Runs on: Tag push (v*..), manual trigger
- Jobs: Verify CI, Build, Publish to PyPI, Create Release
- Time: ~5 minutes
# Install act
brew install act
# Run CI workflow
act push -j lint
act push -j test
# Run with specific Python version
act push -j test --matrix python-version:3.12# Test linting
ruff check src tests
ruff format --check src tests
# Test type checking
pyright src
# Test with coverage
pytest --cov=src/ai_project --cov-fail-under=80
# Test security
bandit -r src
pip-auditSolution: Check for compatibility issues, update dependencies
Solution: Add tests for uncovered code, check coverage report
Solution: Run ruff check --fix src tests to auto-fix
Solution: Add type hints, check pyproject.toml Pyright config
Solution: Verify tag format (v*..), check PyPI token
# List recent runs
gh run list
# View specific run
gh run view <run-id>
# View logs
gh run view <run-id> --log- GitHub UI: Actions tab
- Status badges in README
- Email notifications
Add to workflow:
- name: Notify Slack
if: failure()
uses: slackapi/slack-github-action@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
payload: |
{
"text": "Workflow failed: ${{ github.workflow }}"
}Edit python-ci.yml to add:
- Additional linters
- Custom tests
- Performance benchmarks
- Documentation builds
Edit matrix in python-ci.yml:
matrix:
python-version: ["3.11", "3.12", "3.13"]# Create tag
git tag v1.0.0
# Push tag
git push origin v1.0.0
# Or use GitHub UI
# Releases → Draft a new release- Check Actions tab for workflow run
- Verify PyPI package: https://pypi.org/project/ai-project/
- Check GitHub Release page
- Verify package installation:
pip install ai-project==1.0.0
# Update all dependencies
pip install --upgrade -e ".[dev]"
# Update specific package
pip install --upgrade ruff pyright
# Commit changes
git add pyproject.toml
git commit -m "chore: update dependencies"- Review GitHub Actions updates
- Update action versions
- Test changes in branch first
- Merge to main when verified
-
Rotate Tokens Regularly
- Update PyPI token every 6 months
- Revoke old tokens
-
Use Least Privilege
- PyPI token: Entire account (can be scoped to project)
- GitHub token: Auto-generated, limited scope
-
Monitor Secrets
- Check secret usage in logs
- Audit access patterns
- Rotate if compromised
-
Review Workflows
- Check for hardcoded secrets
- Verify external actions
- Review permissions