python开源系列文章
自动集成CI/CD
首先确保手工打包没问题, 参照之前文章
自动发布是利用GitHub action自动触发
熟悉需要注册pypi:
- https://pypi.org/manage/projects/
利用github action自动发布 - 填写pypi用户和密码作为repo secrets
问题
曾遇到一次,设置了workflow之后,发现没有触发action,啥也没跑
后来发现是因为master分支后来改成了main分支,所以yml设置的时候,也要注意是main分支
travis CI
除了github actions,也可以选择travis,配置文件为travis.yml
自动发布
右下角的release,可以设置release自动发布到pypi,这里采用的setup.py的方法打包。如果是poetry,则相应修改
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: PyPi Release
on:
push:
branches: [master]
release:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload --skip-existing dist/*
codeql
- https://github.com/github/codeql-action
结果会在Security tab
# This action runs GitHub's industry-leading static analysis engine, CodeQL, against a repository's source code to find security vulnerabilities.
# https://github.com/github/codeql-action
name: "CodeQL"
on:
push:
branches: [master, main, dev]
pull_request:
branches: [master, main, dev]
schedule:
- cron: '0 0 1 * *' # Runs at 00:00 UTC on the 1st of every month
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: ['python']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
生产项目工具
- https://github.com/harness/drone
- https://goharbor.io/
参考
- https://qiita.com/mykysyk@github/items/b681a6d0d1e58ca860fe
- 10 个你该了解的 GitHub Actions 进阶技巧
- https://zhuanlan.zhihu.com/p/78293527