1

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.

Alex
  • 2,270
  • 3
  • 33
  • 65
  • I posted the full steps for making the local git repository completely usable, but in your case you might only need to set the remote with the `GITHUB_TOKEN` – peterevans Oct 11 '19 at 10:05

1 Answers1

0

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:

peterevans
  • 34,297
  • 7
  • 84
  • 83