googleapis / release-please-action

automated releases based on conventional commits
Apache License 2.0
1.61k stars 207 forks source link

"Error: release-please failed: Error adding to tree" when target-branch isn't set #935

Closed cwaldren-ld closed 6 months ago

cwaldren-ld commented 6 months ago

TL;DR

I merged a PR branch to main which triggered a release-please workflow run. The run failed with this ambiguous error:

Error: release-please failed: Error adding to tree [commit SHA]

I'm hoping by putting this string in the issue title, others may find the solution easily (set target-branch).

Expected behavior

I expected the workflow to succeed, or at least indicate some way to fix the failure in the case of an error. Perhaps this is just a documentation issue vs a real bug - it's not clear to me. Or I might be doing something fundamentally wrong.

Observed behavior

The workflow failed with an ambiguous error message.

Upon searching for this error, I found one issue with that error string. This lead me to believe that the Github Token permission was somehow incorrect, but that doesn't make much sense since we're running it via this action, with the correct permissions: block.

We eventually realized that the error probably had something to do with the actual git operations, leading us to try adding in target-branch which fixed the workflow.

Action YAML

name: Run Release Please

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  rockspec-info:
    uses: ./.github/workflows/rockspec-info.yml

  release-please:
    runs-on: ubuntu-latest

    permissions:
      contents: write
      pull-requests: write

    outputs:
      release_created: ${{ steps.release.outputs.release_created }}
      prs_created: ${{ steps.release.outputs.prs_created }}
      pr_branch_name: ${{ steps.release.outputs.prs_created == 'true' && fromJSON(steps.release.outputs.pr).headBranchName || '' }}
    steps:
      - uses: google-github-actions/release-please-action@v4
        id: release
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          # <-- need to add target-branch: ${{ github.ref_name }} here! The default doesn't seem to work.

  update-release-pr:
    needs: release-please
    if: ${{ needs.release-please.outputs.prs_created == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Update launchdarkly-server-sdk rockspec
        uses: ./.github/actions/update-versions
        with:
          package: launchdarkly-server-sdk
          branch: ${{ needs.release-please.outputs.pr_branch_name }}

      - name: Update launchdarkly-server-sdk-redis rockspec
        uses: ./.github/actions/update-versions
        with:
          package: launchdarkly-server-sdk-redis
          branch: ${{ needs.release-please.outputs.pr_branch_name }}

  publish-docs:
    needs: release-please
    if: ${{ needs.release-please.outputs.release_created == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build documentation
        uses: ./.github/actions/build-docs

      - name: Publish docs
        uses: ./.github/actions/publish-docs
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  publish-server:
    needs: [release-please, rockspec-info]
    if: ${{ needs.release-please.outputs.release_created == 'true' }}
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.2
      name: 'Get LuaRocks token'
      with:
        aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
        ssm_parameter_pairs: '/production/common/releasing/luarocks/token = LUAROCKS_API_TOKEN'
    - uses: ./.github/actions/publish
      name: Publish server package
      with:
        dry_run: 'false'
        rockspec: ${{ fromJSON(needs.rockspec-info.outputs.info).server }}

  publish-redis:
    needs: [ publish-server, rockspec-info ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1.0.2
        name: 'Get LuaRocks token'
        with:
          aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
          ssm_parameter_pairs: '/production/common/releasing/luarocks/token = LUAROCKS_API_TOKEN'
      - uses: ./.github/actions/publish
        name: Publish redis package
        with:
          dry_run: 'false'
          rockspec: ${{ fromJSON(needs.rockspec-info.outputs.info).redis }}

Log output

https://github.com/launchdarkly/lua-server-sdk/actions/runs/7760226255/job/21165990569

Additional information

We fixed the workflow by adding target-branch: ${{ github.ref_name }} to the release-please action parameter list.

The workflow failed under these conditions: 1) When a PR was merged from a feature branch to main 2) When a workflow_dispatch event was used to manually trigger the release-please action via Github UI, with the "Use workflow from:" branch set to a feature branch. 3) The same as (2), but "Use workflow from:" set to main.

cwaldren-ld commented 6 months ago

Update: my solution doesn't actually appear to work. I think it was just a coincidence that it succeeded. Still investigating this.

cwaldren-ld commented 6 months ago

Closing this and filing a more accurate bug.