fix(config): gracefully fail when repo is in a detached HEAD state #765
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Gracefully handle a TypeError when repository is in a detached HEAD state as occurs naturally in GitLab CI/CD environments.
Rationale
As I was setting up this library to run within GitLab CI/CD, I ran into an unhandled TypeError because of the detached HEAD state that GitLab's Runner Helper image sets up the environment by default. This is problematic due to the branch detection mechanism used in
python-semantic-release
. I opted to have the code gracefully catch this error and display a rationale to the user.I have devised a way to manually resolve this problem in GitLab in the step before
semantic-release
is called but have not implemented an internal correction method (match the detached HEAD SHA to an equivalent branch and checkout). At the current time it will be up to the developer to ensure the state is correct.How I tested
Outside of the manual integration tests I performed on GitLab, I added a test that purposefully mimics a detached HEAD state like GitLab does.