Skip to content

Allow using ssh-key to push version while using token to publish to hvcs - #419

Merged
danth merged 5 commits into
python-semantic-release:masterfrom
sp-ricard-valverde:master
May 25, 2022
Merged

danth merged 5 commits into
python-semantic-release:masterfrom
sp-ricard-valverde:master

Conversation

@sp-ricard-valverde

Copy link
Copy Markdown
Contributor

Scenario

In GH Actions I want to use a ssh Deploy Key to push changes to a protected branch because not every user's GITHUB_TOKEN is allowed to push to protected branches but Deploy Keys are.

Problematic

If I specify a GH_TOKEN such as GITHUB_TOKEN in a GitHub Action with enough permission to publish a GitHub Release, python-semantic-releases will also use that user's token to push version and tag changes to the repository.
The user running the action though might not have enough permission to push to a protected branch even if grating some degree of permission to its GITHUB_TOKEN. Only Deploy Keys or Admin user's GITHUB_TOKEN(or Personal Access Tokens) can.

Solution

Add an option that will allow to use the token to submit GitHub Releases while will avoid using that token for pushing changes to the repository, relying on the underlying git authentication mechanism. In the case of GitHub Actions it can be combined with ssh-agent action to allow using Deploy Keys for this purpose.

@sp-ricard-valverde

Copy link
Copy Markdown
Contributor Author

Anyone ?

@danth danth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the new option to the documentation in docs/configuration.rst.

Other than that, this looks good to me.

@danth

danth commented Apr 13, 2022

Copy link
Copy Markdown
Contributor

Looks like some tests need to be fixed.

@sp-ricard-valverde

Copy link
Copy Markdown
Contributor Author

I'll look into it, thanks @danth

Add ignore_token_for_push parameter that allows using the underlying
git authentication mechanism for pushing a new version commit and tags
while also using an specified token to upload dists
Test push_new_version with token while ignore_token_for_push is True
and False
push_new_version is using GITHUB_ACTOR env var but we did not
contemplate in our new tests that actually Github actions running the
tests will populate that var and change the test outcome

Now we control the value of that env var and test for it being present
or not
@sp-ricard-valverde

Copy link
Copy Markdown
Contributor Author

Sorry for the late fix @danth. I've figured out the problem which had to do with the GITHUB_ACTOR env var set by the GH runners altering the test outcome(thus why locally the tests were ok)

@danth

danth commented May 25, 2022

Copy link
Copy Markdown
Contributor

One of the tests is still broken 🤔 Perhaps there is still some interference from the test environment.

@sp-ricard-valverde

Copy link
Copy Markdown
Contributor Author

Hope this one works. I explicitly added the GITHUB_ACTOR env var to my test execution to emulate the runner behaviour

@danth
danth merged commit 7b2dffa into python-semantic-release:master May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants