Tagging, and building and uploading a python library

烈酒焚心 提交于 2020-01-05 08:32:30

问题


I have a github action that runs when a branch is merged into master. It should tag the repo with a version number that it obtains from setup.py, and then push the tag. It should then build the package and upload it to a package repository.

Progress so far: Building and uploading works, tagging does not

name: Deploy Library



on [push]



jobs:

  build:

    runs-on: ubuntu latest

    steps:

    - uses: actions/checkout@master

    - name: Set up Python env

       uses: actions/setup-python@v1

         with:

           python-version: '3.6'

    - name: Install Deps

    run: |

      python -m pip install --upgrade pip

      pip install wheel

      pip install twine

    - name: Build

       run: |

         python setup.py build bdist_wheel

    - name: Tag

       env:

         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

        run: |

          VERSION=*sed magic on setup.py*

          git tag v$VERSION

          git push origin v$VERSION

Everything works except for the git push at the end. The logs complain about the need for a username and password (I only have the GITHUB_TOKEN), and anyway, actions/checkout didn't complain...

I've checked the github actions page, and I can't find one relating to tagging.


回答1:


The actions/checkout@v1 action leaves the git repository in a detached HEAD state. So in order to push back to the repository there are a few steps required.

Set git config for the user you want to be the commit author:

git config --global user.name 'My User'
git config --global user.email 'myuser@example.com'

Set the remote:

git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/username/repository

You may also need to checkout. You can extract the branch name from the GITHUB_REF:

git checkout "${GITHUB_REF:11}"

Related questions and answers:

  • Push to origin from GitHub action
  • Unable to commit and push back changes made by github action (invalid user)


来源:https://stackoverflow.com/questions/58338425/tagging-and-building-and-uploading-a-python-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!