Replies: 1 comment
-
|
You can solve this without Here is a workflow snippet that does exactly what you describe: - name: Resolve ref for external repo
id: resolve-ref
env:
BRANCH: ${{ github.head_ref }} # the PR branch name
run: |
# Check if this branch exists in the external repo
MATCH=$(git ls-remote --heads https://github.com/your-org/external-repo.git "refs/heads/$BRANCH" | wc -l)
if [ "$MATCH" -gt "0" ]; then
echo "ref=$BRANCH" >> $GITHUB_OUTPUT
else
echo "ref=main" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
with:
repository: your-org/external-repo
ref: ${{ steps.resolve-ref.outputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
If the external repo is private, replace the HTTPS URL with the SSH form and make sure your runner has the appropriate deploy key or PAT configured. For the pattern you described (test repo branch mirrors the frontend branch), this is the standard approach most teams use. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a use case where we are running a pipeline that runs QA testing automation but sometimes, based on new requirements, I want the ref to change if there is an existing branch out there with the same name as the current repo

Workflow goes as follow:
I saw there was a fetch-depth property but looking at the documentation, I don't exactly see how I can list this history or access the list
Beta Was this translation helpful? Give feedback.
All reactions