Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release fails with ReleaseFailedException: Status: Optional[REJECTED_OTHER_REASON] #878

Open
marcindabrowski opened this issue Dec 19, 2024 · 14 comments

Comments

@marcindabrowski
Copy link

I'm using plugin v1.18.16 with Gradle 8.11.1 and run release task with --stacktrace option. But the exception message do not show nothing helpful. I'm getting:

Release fails with

Caused by: pl.allegro.tech.build.axion.release.ReleaseFailedException: Status: Optional[REJECTED_OTHER_REASON]
Message: 

Message is empty, nothing else can be found.

on some runs it is:

Caused by: org.eclipse.jgit.api.errors.ConcurrentRefUpdateException: Could not lock HEAD. RefUpdate return code was: LOCK_FAILURE
 	at org.eclipse.jgit.api.TagCommand.updateTagRef(TagCommand.java:172)
 	at org.eclipse.jgit.api.TagCommand.call(TagCommand.java:147)
	at pl.allegro.tech.build.axion.release.infrastructure.git.GitRepository.tag(GitRepository.java:124)
	... 152 more

On other projects it is working, the gradle configuration is the same.
The only difference is that I changed the repository name.

Any thought what it can be?

@bgalek
Copy link
Member

bgalek commented Dec 19, 2024

hi! without your whole workflow/setup it's hard to help, is it reproducable locally? whats the origin git repo?

@marcindabrowski
Copy link
Author

I was running it in GitHub Action, and it was failing.
Locally it is also failing.
I'm using this command:

./gradlew \
    -Prelease.forceVersion=0.3.0 \
    -Prelease.customUsername=$GH_USER \
    -Prelease.customPassword=$GH_TOKEN \
    release --stacktrace 

Locally with the same command I got above errors, and also this error:

Caused by: pl.allegro.tech.build.axion.release.ReleaseFailedException: Status: Optional[REJECTED_NONFASTFORWARD]
Message: 

The problem is that the message is to verbose. I can't find what is wrong.

But the wired thing is, that if I run it again, it is not failing.

My workaround for that is run this command localy, and than publish it using ./gradlew publish from GitHub action.

For the record, my GitHub workflow looks like this:

name: Release version

on:
  workflow_dispatch:
    inputs:
      new-release-version:
        description: Release version
        required: false
        type: string

jobs:
  library-release:
    name: Run release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          ref: ${{ github.head_ref }}

      - name: Set up JDK
        uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0
        with:
          distribution: temurin
          java-version: 21
          check-latest: true

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@0bdd871935719febd78681f197cd39af5b6e16a6 # v4.2.2
        with:
          add-job-summary-as-pr-comment: never
          gradle-version: wrapper
          validate-wrappers: true

      - name: Version to release
        shell: bash
        run: |
          if [ "${{ inputs.new-release-version }}" = "" ];
          then
            echo "Release will increase PATCH version";
          else
            echo "Release version provided by user: ${{ inputs.new-release-version }}";
          fi

      - name: Release version
        shell: bash
        run: |
          ./gradlew \
            -Prelease.forceVersion=${{ inputs.new-release-version }} \
            -Prelease.customUsername=${{ github.actor }} \
            -Prelease.customPassword=${{ github.token }} \
            release --stacktrace

      - name: Released version
        shell: bash
        run: |
          ./gradlew currentVersion

      - name: Publish package
        shell: bash
        run: |
          ./gradlew publish

@bgalek
Copy link
Member

bgalek commented Dec 20, 2024

can you check if running this before the release step helps?

git fetch origin
git merge origin ${{ github.head_ref }}

other things I noticed:

  workflow_dispatch:
    inputs:
      new-release-version:
        description: Release version
        required: false
        type: string

I would recommend using github releases, you'll have cleaner workflow and ability to actually write release notes why you're releasing new version

instead of:

        with:
          fetch-depth: 0
          ref: ${{ github.head_ref }}

jest enable repo unshallow https://github.com/allegro/axion-release-plugin/releases/tag/v1.18.4

Running

./gradlew currentVersion

is not needed, since it triggers another build run, instead use step outputs https://axion-release-plugin.readthedocs.io/en/latest/configuration/ci_servers/#github-outputs

@marcindabrowski
Copy link
Author

I will try with this fetch. But I found that the error is only when I force the version. When I'm not passing the version, and patch number is increased it is working.

But can you do something to add more data from plugin exception?

Thanks for your tips about fetch and Gradle current version, I can't apply it now, because we are using this workflow as reusable, and not every project is using latest version the plugin.

But can you share a link with me about github releases you are talking about?
What I'm using, is just automatic Release notes generation, but don't know how to trigger release workflow in other way.

@bgalek
Copy link
Member

bgalek commented Dec 20, 2024

But can you do something to add more data from plugin exception?
Dunno yet, I would need to know whats wrong to reproduce it so I can debug it ;)

You can trigger maven publication after release https://github.com/bgalek/safe-svg/blob/main/.github/workflows/publish.yml
https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release

Having reusable workflow with so many things and steps seems very fragile and hard to work with, I would recommend using init-script instead:

https://www.linkedin.com/events/7211676201914904578/about/

You can than remove axion dependency from all other repositories ;)

@marcindabrowski
Copy link
Author

marcindabrowski commented Dec 20, 2024

Dunno yet, I would need to know whats wrong to reproduce it so I can debug it ;)

Hmm, the problem is that I also don't know. And thought that --stacktrace parameter will help, but it didn't.
The stacktrace do not contains root cause stacktrace. Maybe if you can add cause to the ReleaseFailedException and pass it there, I will give us more info about the problem.

You can trigger maven publication after release https://github.com/bgalek/safe-svg/blob/main/.github/workflows/publish.yml https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release

Yeah, but first I need to trigger it. So you are suggesting that I should split it into two workflows - one for releasing, and second for publishing, and I think you are right.

Having reusable workflow with so many things and steps seems very fragile and hard to work with, I would recommend using init-script instead:

https://www.linkedin.com/events/7211676201914904578/about/

Thanks for the link, I will watch it soon.

You can than remove axion dependency from all other repositories ;)

So, you are saying that in Allegro you are not using it anymore?
As I remember it was used everywhere :).

Or you meant Gradle Conventional plugin, and put it there?

@marcindabrowski
Copy link
Author

Here is log from GH Action:

> Task :my-project:verifyRelease
Looking for uncommitted changes.. 
Checking if branch is ahead of remote.. 
Checking for snapshot versions.. 

> Task :verifyRelease
Looking for uncommitted changes.. 
Checking if branch is ahead of remote.. 
Checking for snapshot versions.. 
remote status: Optional[REJECTED_OTHER_REASON]

remote message: 

> Task :release FAILED
Creating tag: v0.3.6
Pushing all to remote: origin
Removing tag: v0.3.6
Tag v0.3.6 removed

> Task :my-project
Creating tag: v0.3.6
Pushing all to remote: origin
Written GitHub output: released-version=0.3.6-SNAPSHOT

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':release'.
> Status: Optional[REJECTED_OTHER_REASON]
  Message: 

And actually the tag v0.3.6 was not removed.

@marcindabrowski
Copy link
Author

I tried to add:

git fetch origin
git merge origin ${{ github.head_ref }}

and found that github.head_ref is defined only for PRs. And I'm not running it from PR.

So I added this instead:

git fetch origin
git merge origin/${{ github.ref_name }}

And after that I got more info in stack trace:

> Task :verifyRelease
Looking for uncommitted changes.. 
Checking if branch is ahead of remote.. 
Checking for snapshot versions.. 
> Task :my-project:verifyRelease
Looking for uncommitted changes.. 
Checking if branch is ahead of remote.. 
Checking for snapshot versions.. 
> Task :my-project:release FAILED
Creating tag: v0.3.7
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':my-project:release'.
> Task :release
Creating tag: v0.3.7
Pushing all to remote: origin

Caused by: pl.allegro.tech.build.axion.release.domain.scm.ScmException: org.eclipse.jgit.api.errors.ConcurrentRefUpdateException: Could not lock HEAD. RefUpdate return code was: LOCK_FAILURE
	at pl.allegro.tech.build.axion.release.infrastructure.git.GitRepository.tag(GitRepository.java:129)
	at pl.allegro.tech.build.axion.release.domain.scm.ScmService.tag(ScmService.java:26)
	at pl.allegro.tech.build.axion.release.domain.Releaser.release(Releaser.java:41)
	at pl.allegro.tech.build.axion.release.domain.Releaser.releaseAndPush(Releaser.java:52)
	at pl.allegro.tech.build.axion.release.domain.Releaser$releaseAndPush.call(Unknown Source)
	at pl.allegro.tech.build.axion.release.ReleaseTask.release(ReleaseTask.groovy:26)
...
Caused by: org.eclipse.jgit.api.errors.ConcurrentRefUpdateException: Could not lock HEAD. RefUpdate return code was: LOCK_FAILURE
	at org.eclipse.jgit.api.TagCommand.updateTagRef(TagCommand.java:172)
	at org.eclipse.jgit.api.TagCommand.call(TagCommand.java:147)
	at pl.allegro.tech.build.axion.release.infrastructure.git.GitRepository.tag(GitRepository.java:124)
	... 123 more

And again tag was created.
And why it is pushing thing after failure?

@bgalek
Copy link
Member

bgalek commented Dec 20, 2024

So, you are saying that in Allegro you are not using it anymore? As I remember it was used everywhere :).

Or you meant Gradle Conventional plugin, and put it there?

We use it once in our init.gradle script, so nobody needs to depend on it and simple gradle publish just works ;)

@bgalek
Copy link
Member

bgalek commented Dec 20, 2024

github.head_ref is not avaiable during workflow_dispatch.

I would recommend sticking to standard library flow
github release -> (tag is created automatically) -> publish (maven publication) - if you want to do it manually
or standard service flow
github on pull_request and push to main branch -> gradle release (won't do anything on branch) -> gradle publish (snapshot on branch release on main branch)

@bgalek
Copy link
Member

bgalek commented Dec 20, 2024

assiming: releaseOnlyOnReleaseBranches.set(true) and unshallowRepoOnCI.set(true)

name: Service Release

on:
  pull_request:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      released-version: ${{ steps.release.outputs.released-version }} # optional if you want to log it or smth
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '23'
          distribution: 'temurin'
      - uses: gradle/actions/setup-gradle@v4
      - run: ./gradlew build
      - run: ./gradlew release
        id: release
      - run: ./gradlew publish
name: Library Release

on:
  release:
    types: [ created ]

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '23'
          distribution: 'temurin'
      - uses: gradle/actions/setup-gradle@v4
      - run: ./gradlew publish

@marcindabrowski
Copy link
Author

@bgalek thanks for the tips with workflow. But I would like to try to find the cause.

  1. Is there anything I can do to increase the logging from the plugin?
  2. Is there something you can do to increase the logging from the plugin?
  3. Why plugin is doing push to the remote, in case of failure - I think it is a bug.

@marcindabrowski
Copy link
Author

@bgalek do you have any thought on it?

@bgalek
Copy link
Member

bgalek commented Jan 12, 2025

If adding --stracktrace or --debug to Gradle task isn't enough - fork the repository and try to add more logging. I'll be happy to help if you provide me a repository that shows the problem. Could you prepare that?

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

No branches or pull requests

2 participants