接外包,有相关需求的可以联系我:Telegram | Email

如何配置当某个文件更改时才执行Github Actions?

该文章创建(更新)于01/24/2023,请注意文章的时效性!

这两天了解了一点python打包发布到PyPi上,同时最好是通过CI来进行自动化配置,了解过only和except操作,搞了半天也没了解配置规则一堆Error报错,最后发现通过on来进行指定就行了。

包目录情况

|-- .github
|   |-- workflows
|      |-- publish.yml     : actions文件
|-- config                     : 配置文件
|-- XmlRpc                   : 需要发布的包
|-- setup.py                 : 发布需要用到的setup.py配置文件

注册Pypi

注册

https://test.pypi.org/
https://pypi.org/

获取token

  • 验证邮箱后直接去Account Settings生成即可,注意保存,这东西只会出现一次。

  • 其次注意权限的控制。

  • 获取到TOKEN后注意去项目设置中的secret配置PYPI_API_TOKEN,脚本中通过环境变量来设定保护密钥安全性。

发布

  • 第一种是直接去搜索市场就能找到相关的,这个没啥说的。改一下就行了,主要是配置一下paths和账户秘密。
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Upload Python Package

on: 
  push:
    branches: [ "master" ]
    paths:
      - 'XmlRpc/__init__.py'
  pull_request:
    branches: [ "master" ]
    paths:
      - 'XmlRpc/__init__.py'

permissions:
  contents: read

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up Python
      uses: actions/setup-python@v3
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install build
    - name: Build package
      run: python -m build
    - name: Publish package
      uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
      with:
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}
  • 自定义脚本
name: Upload Python Package

on: 
  push:
    branches: [ "master" ]
    paths:
      - 'XmlRpc/__init__.py'
  pull_request:
    branches: [ "master" ]
    paths:
      - 'XmlRpc/__init__.py'

permissions:
  contents: read

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: '3.x'
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel twine
      - name: Build package
        run: python setup.py sdist bdist_wheel
      - name: Publish package
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
        run: |
            twine check dist/*
            twine upload dist/*

要不赞赏一下?

微信
支付宝
PayPal
Bitcoin

版权声明 | Copyright

除非特别说明,本博客所有作品均采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。转载请注明转自-
https://www.emperinter.info/2023/01/24/how-do-i-configure-github-actions-to-run-only-when-a-file-changes/


要不聊聊?

我相信你准备留下的内容是经过思考的!【勾选防爬虫,未勾选无法留言】

*

*



YouTube | B站

微信公众号

👉 NewsLetter ❤️ 邮箱订阅 👈

优惠码

阿里云国际版20美元
Vultr10美元
搬瓦工 | Bandwagon应该有折扣吧?
Just My SocksJMS9272283 【注意手动复制去跳转】
域名 | namesiloemperinter(1美元)
币安 币安