question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Release in GitLab fails due to can't push to master from detached state

See original GitHub issue

Projen version: 0.56.13 CDK Version: 2.24.1 Typescript version: 4.6.4

I’ve recently upgraded to the newest version of projen from 0.19.x. I use it to define CDK constructs in a GitLab monorepo where the root project and .gitlab-ci.yml are manually created (not via projen). I used to use the bump task to update version, then manually tag and commit changes back to the repo, but am trying to switch to using projen release command. I’m running into an issue when the release task tries to commit back to the repo where it throws the error

👾 release » publish:git | git push --follow-tags origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://gitlab.com/####/devops/cdkconstructs'

It does look like the commit is being created, so it’s not that there’s no commit, but it’s in a detached state.

[detached HEAD dc08d87] chore(release): 0.1.1
 1 file changed, 2 insertions(+)

It is my understanding that due to being in a detached state, you can’t just push to master with git push --follow-tags origin master which is what the default gitPushCommand is, but rather need git push --follow-tags origin HEAD:master. I have seen that you can override the publisher.gitPushCommand, but have not figured out how to do this with the AwsCdkConstructLibrary class. I can’t edit the task with project.release.publish.publishToGit(gitPushCommand: git push --follow-tags origin HEAD:master}). It tries to create a new task, but one with that name already exists. If I try to first remove the publish:git task, it fails because the release task is dependent on it.

So 1, why does the gitPushCommand try to push directly to the main|master branch if it’s in a detached state? Won’t that always error? And 2, how do configure the override for the gitPushCommand? I can’t find any docs to help.

Thanks

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jwsomiscommented, May 27, 2022

One other thing, if you’re able to answer here. I haven’t run into this yet, but since I have a monorepo where CI release steps are run in each constructs directory. I suspect that if I have releases triggered for multiple constructs at once I could hit a race condition where the first construct to push changes back wins and subsequent ones fail. Previously, when I did all these steps manually did pull --rebase right before the push to make sure I had the latest. It is a bit weird, but is there anyway to insert this task via projenrc.js in the release steps? Just realized I could prepend this to push command. There’s also the option to set it to ‘’ and then run additional steps manually/ use gitlab CI variables.

1reaction
Chriscbrcommented, May 26, 2022

Is it possible to customize the git push command by specifying the release trigger like this perhaps?

const project = new CustomProject({
  ...
  releaseTrigger: ReleaseTrigger.manual({
    gitPushCommand: "command",
  }),
});

I’m not too familiar with this component. If changing master to HEAD:master wouldn’t break any existing users, then I’d be okay accepting a pull request that updates the default command directly in projen’s source code.

cc @gradybarrett

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gitlab: Can't push to master only - Stack Overflow
It appears that GitLab does not allow you to push directly to master . This is a common practice.
Read more >
How to avoid broken master with Pipelines for Merged Results ...
GitLab creates a pipeline on the merge commit, but this pipeline fails because the latest master changed a lint rule. A maintainer sees...
Read more >
Git Detached Head: What Is It & How to Recover
Git detached head might be a weird error message, but don't despair. Learn what this means and how to fix it!
Read more >
Common Issues with GitKraken Client | Integration Error ...
This usually indicates that there is a casing difference between the local branch and the upstream remote branch. You can rename the local...
Read more >
What's a "detached HEAD" in Git? | Learn Version Control with ...
When in a detached HEAD state, it's terribly easy to lose valuable data. Find out when this state is triggered and what you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found