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

[Bug]: Empty pr_branch output variable #476

Closed
1 task done
kdeldycke opened this issue Mar 2, 2024 · 2 comments · Fixed by #479
Closed
1 task done

[Bug]: Empty pr_branch output variable #476

kdeldycke opened this issue Mar 2, 2024 · 2 comments · Fixed by #479
Assignees
Labels
bug Something isn't working

Comments

@kdeldycke
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

It looks like the new pr_branch variable output (implemented by #472 / #473) is not set if there is already a PR previously created by actions-template-sync.

Expected Behavior

I expect the pr_branch variable to always be set to the active / unmerged PR that is tracked an maintained by actions-template-sync.

Current Behavior

I have a workflow that essentially looks like this:

(...)

jobs:

  awesome-template-sync:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4.1.1

      - name: Sync from template repo
        id: template_sync
        uses: AndreasAugustin/actions-template-sync@v1.8.0
        with:
          # We need custom PAT with workflows permissions so we can update all the boilerplate .github files from
          # awesome-template.
          github_token: ${{ secrets.WORKFLOW_UPDATE_GITHUB_PAT || secrets.GITHUB_TOKEN }}
          source_repo_path: kdeldycke/awesome-template
          pr_title: "[sync] Updates from `awesome-template` repository"
          pr_commit_msg: "[sync] Updates from `awesome-template` repository"
          pr_branch_name_prefix: "sync-awesome-template"
          pr_labels: "📚 documentation"
          is_pr_cleanup: true

      - name: Print PR branch ID
        run: |
          echo "PR branch ID: ${{ steps.template_sync.outputs.pr_branch }}"

      (...)

The full workflow code is available at: https://github.com/kdeldycke/awesome-billing/blob/b4686574a1a328f001ca1410f65b6137f990763d/.github/workflows/docs.yaml#L16-L59

Its execution log is available at: https://github.com/kdeldycke/awesome-billing/actions/runs/8113301740/job/22199139632

On execution, you can find that the step printing the pr_branch variable returns nothing:

Screenshot 2024-03-02 at 11 14 28

This is probably an edge-case because there is already an unmerged (and conflicting) PR that was previously created by actions-template-sync:

Screenshot 2024-03-02 at 11 15 05

I expect here actions-template-sync should identify the already existing sync-awesome-template_d48d756 PR and branch, update it, and return its ID in pr_branch variable.

Note that the behavior is the same wether is_pr_cleanup parameter is true or false.

Steps To Reproduce

No response

Possible Solution

No response

Additional Information/Context

This was encounter while playing with 1.8.0 to implement a temporary workaround for #467.

Template sync version Version

1.8.0

@AndreasAugustin
Copy link
Owner

AndreasAugustin commented Mar 2, 2024

@kdeldycke thanks for the report. Indeed I forgot to handle some 'edge-cases' (thanks for the hint within the description).
Sorry for that 🥷

The edge-case in your case is the following:

  • The action is checking if the branch is already available remotely (the prefix is the commit short ID) and exiting.
  • The output definition is with v1.8.0 at the end of the action and not done for exit cases

Your action log part:

::info::Missing env variable 'UPSTREAM_BRANCH' setting to remote default main
::info::current git hash: b4686574a1a328f001ca1410f65b6137f990763d
Check new changes
  a5d4c1b6d368ba257[28](https://github.com/kdeldycke/awesome-billing/actions/runs/8113301740/job/22199139632#step:4:30)94b0e93ac16cd65a6f02e	refs/heads/sync-awesome-template_d48d756
  ::warn::Git branch 'sync-awesome-template_d48d756' exists in the remote repository

related code part src/sync_template.sh line 51

function check_branch_remote_existing() {
  git ls-remote --exit-code --heads origin "${NEW_BRANCH}" || BRANCH_DOES_NOT_EXIST=true

  if [[ "${BRANCH_DOES_NOT_EXIST}" != true ]]; then
    warn "Git branch '${NEW_BRANCH}' exists in the remote repository"
# following line will be added with v1.8.1    
# set_github_action_outputs
    exit 0
  fi
}

With v1.8.1 Your case should be fixed (at least my tests are green).

@kdeldycke
Copy link
Contributor Author

Wow, thanks @AndreasAugustin for the incredibly fast investigation and fix! I can confirm v1.8.1 fix the issue and pr_branch is properly set.

You can check the proof here: https://github.com/kdeldycke/awesome-billing/actions/runs/8122438292/job/22201872306#step:5:5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants