actions-template-sync icon indicating copy to clipboard operation
actions-template-sync copied to clipboard

[Bug]: When syncing private repo to private repo, upstream_branch does nothing and default branch is always used.

Open veroxzik opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I am syncing one private repo to another private repo. I have upstream_branch set to an environment variable (I've also tried with a hardcoded string and a secret variable), but the action will always pull from the default branch of the source repo.

Expected Behavior

I expect the synced branch to match the input given by upstream_branch.

Current Behavior

Trying to include only the relevant logs here.

In the checkout action, we correctly reference the branch release-v1.x (it's the same name on source and target repo):

Run actions/checkout@v4
##[debug]GITHUB_WORKSPACE = '/home/runner/work/[REPO-TO-BE-SYNCED]'
##[debug]qualified repository = '[REPO-TO-BE-SYNCED]'
##[debug]ref = 'release-v1.x'

I see the upstream_branch input being parsed correctly:

Run AndreasAugustin/[email protected]
[snip]
 ##[debug]Evaluating: inputs.upstream_branch
##[debug]Evaluating Index:
##[debug]..Evaluating inputs:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'upstream_branch'
##[debug]=> 'release-v1.x'
##[debug]Result: 'release-v1.x'

It's unclear to me what's exactly going on here. I believe the new branch from default is in reference to the target repo. On the source side, it simply says branch. As I note above, this appears to always be the default branch.

checkout branch and pull
##[debug]create new branch from default branch with name chore/template_sync_8babb5f
##[debug]pull changes from template
::info::pull changes from source repository
From github.com:***
 * branch            HEAD       -> FETCH_HEAD

Steps To Reproduce

.yml is largely just the template: (please don't judge me for perms: write-all, I was at my wits end trying to debug this)

name: actions-template-sync

on:
  # cronjob trigger At 00:00 on day-of-month 1. https://crontab.guru/every-month
  schedule:
    - cron: "0 0 1 * *"
  # manual trigger
  workflow_dispatch:

env:
  RELEASE_BRANCH: release-v1.x

jobs:
  repo-sync:
    runs-on: ubuntu-latest
    permissions: write-all

    steps:
      # To use this repository's private action, you must check out the repository
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ env.RELEASE_BRANCH }}
          token: ${{ secrets.PAT_TOKEN }}
      
      - name: actions-template-sync
        uses: AndreasAugustin/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # <owner/repo>, should be within secrets
          source_repo_ssh_private_key: ${{ secrets.SOURCE_REPO_SSH_PRIVATE_KEY }} # contains the private ssh key of the private repository
          upstream_branch: ${{ env.RELEASE_BRANCH }}
          pr_labels: chore,template-sync
          is_pr_cleanup: true

Possible Solution

No response

Additional Information/Context

Haven't tried using this on public repos to see the behavior is the same.

Template sync version Version

2.2.3

veroxzik avatar Aug 02 '24 14:08 veroxzik

Hi @veroxzik and thank you for the issue report. Just a short question. The upstream_branch is the branch within the target repository where the PR is created to (as states within docs). Reading your description I assume you expect the setting to relate to a branch within the source repo?

AndreasAugustin avatar Aug 02 '24 14:08 AndreasAugustin

You are correct, I expected the upstream_branch to be the branch on the source repo that I wished to pull from.

I admit that this is probably due to the fact that it's wedged between two different source repo options in the chart in the README, so I assumed that it too was related to the source repo. image

This is probably a feature request then - I would like to be able to choose via arguments the branch that I'm pulling from on the source repo.

veroxzik avatar Aug 02 '24 15:08 veroxzik

I was able to achieve what I desired by passing in the branch name via git_remote_pull_params. I still think a dedicated argument would be nice!

Feel free to close, thanks for the quick response.

veroxzik avatar Aug 02 '24 15:08 veroxzik

I was able to achieve what I desired by passing in the branch name via git_remote_pull_params. I still think a dedicated argument would be nice!

Feel free to close, thanks for the quick response.

thanks for the investigation. Will think about adding a parameter. Will close the issue.

AndreasAugustin avatar Aug 15 '24 09:08 AndreasAugustin