current branch not pushed when `PUSH_ALL_REFS=false`
Closed this issue ยท 7 comments
hi ๐
first of all thanks for maintaining really cool Github Action!
I wanted to use your action to push just the main
branch and tags to the mirror repo with the following action:
---
name: mirror repository
'on':
push:
branches:
- main
tags:
- '**'
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: mirror to bitbucket
uses: spyoungtech/mirror-action@v0.4.3
with:
REMOTE: git@bitbucket.org:my-org/my-repo.git
GIT_SSH_PRIVATE_KEY: >-
${{ secrets.BITBUCKET_SSH_PRIVATE_KEY }}
GIT_SSH_NO_VERIFY_HOST: true
PUSH_ALL_REFS: false
The problem is that this workflow run pushes only tags
to bitbucket repo, the current branch (main
) is not pushed at all like suggested in PUSH_ALL_REFS
docs in action.yml
:
Push all refs instead of just the current branch
@skarzi I'm guessing this is because you're using checkout@v2 -- in my experience you must use actions/checkout@v1
for proper functionality. IIRC checkout@v2 does not populate remote refs from origin.
Could you let me know if this works using checkout@v1
?
If you could provide the output of the action log, that would also be helpful.
Thanks for your really quick response ๐
I have run the above-listed workflow using actions/checkout@v1
and nothing has changed.
Here, you can find the censored output log for the above-listed workflow.
Maybe the solution will be to add some refspec based on github.ref
to this line in entrypoint.sh
?
I think I may have spotted the error, @skarzi -- I think the problem is the YAML type boolean.
Can you try one of the following:
omitting thePUSH_ALL_REFS
parameter altogether (instead of declaring it asfalse
)- you can do
PUSH_ALL_REFS: "false"
(string argument)
I believe that would fix your issue.
However, I'd still like to patch to properly handle YAML booleans if that's the case.
I think YAML booleans works fine, because env variables are interpoleted using "
e.g "${INPUT_PUSH_ALL_REFS}"
Solution 1.
won't work like expected, because PUSH_ALL_REFS
default is true
.
Solution 2.
doesn't work either - I have tried with actions/checkout@v1
and actions/checkout@v2
, both runs haven't pushed the current branch.
Hmmm. What I'm trying to reconcile is this:
In your job log, I see this line is executed:
eval git push -u --tags --force --prune mirror
However, this should only happen if "${INPUT_PUSH_ALL_REFS}" != "false"
if [[ "${INPUT_PUSH_ALL_REFS}" != "false" ]]; then
eval git push ${GIT_PUSH_ARGS} mirror "\"refs/remotes/origin/*:refs/heads/*\""
else
if [[ "${HAS_CHECKED_OUT}" != "true" ]]; then
echo "FATAL: You must upgrade to using actions inputs instead of args: to push a single branch" > /dev/stderr
exit 1
else
eval git push -u ${GIT_PUSH_ARGS} mirror
fi
fi
So, if [[ "${INPUT_PUSH_ALL_REFS}" != "false" ]]; then
doesn't seem to work as expected.
In your job log, I see this line is executed:
This line is executed because I do not want to push all refs, but only the current branch, so I have set PUSH_ALL_REFS
to false
(and also have tried "false"
string like suggested in your previous comment).
When I do not declare PUSH_ALL_REFS
or set it to true
it executes:
eval git push ${GIT_PUSH_ARGS} mirror "\"refs/remotes/origin/*:refs/heads/*\""
and pushes all branches.
Ah, sorry, you're right. I got my wires crossed there for a moment. Happens around 3AM.
I wonder if fetch-depth: 0
is playing a factor here. This would fetch all refs, so they would also be pushed with push -u mirror
.
Maybe the solution will be to add some refspec based on github.ref to this line in entrypoint.sh?
This now makes more sense to me and seems like a good suggestion :-)
I'll take a closer look this week and try to make a patch, but would also be happy to review a PR earlier if you'd like to make the contribution.