action-pack / gitlab-sync

Action to mirror a repository to GitLab.
MIT License
16 stars 4 forks source link

Failed to sync tags #2

Open Frederick888 opened 1 year ago

Frederick888 commented 1 year ago

What I did

  1. Made the changes
  2. Pushed
  3. Tagged HEAD
  4. Pushed the new tag

Setup

name: GitLab Sync

on: [push, create, delete]

jobs:
  sync:
    name: Synchronise to GitLab
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: action-pack/gitlab-sync@v3
        with:
          username: Frederick888
          url: "https://git.tsundere.moe/Frederick888/git-credential-keepassxc.git"
          token: ${{ secrets.GITLAB_ACCESS_TOKEN }}

Results

https://github.com/Frederick888/git-credential-keepassxc/actions/runs/6626126547/job/17998425927

Logs in case the link expires
Run action-pack/gitlab-sync@v3
  with:
    username: Frederick888
    url: https://git.tsundere.moe/Frederick888/git-credential-keepassxc.git
    token: ***
Run /home/runner/work/_actions/action-pack/gitlab-sync/v3/entrypoint.sh
  /home/runner/work/_actions/action-pack/gitlab-sync/v3/entrypoint.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_TARGET_URL: https://git.tsundere.moe/Frederick888/git-credential-keepassxc.git
    INPUT_TARGET_TOKEN: ***
    INPUT_TARGET_USERNAME: Frederick888
    GITHUB_EVENT_REF: refs/tags/v0.14.0
push
git remote add target ***git.tsundere.moe/Frederick888/git-credential-keepassxc.git
+ git fetch --all
Fetching origin
Fetching target
From https://git.tsundere.moe/Frederick888/git-credential-keepassxc
 * [new branch]      actions-just  -> target/actions-just
 * [new branch]      build-musl    -> target/build-musl
 * [new branch]      clap4         -> target/clap4
 * [new branch]      fix-win-build -> target/fix-win-build
 * [new branch]      group-detect  -> target/group-detect
 * [new branch]      master        -> target/master
 * [new branch]      shell-comp    -> target/shell-comp
 * [new branch]      yubikey-old   -> target/yubikey-old
+ git push -f --all target
Everything up-to-date
+ git push -f --prune target
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push target HEAD:

Error: Process completed with exit code 128.
kroese commented 1 year ago

Hi, thanks for reporting this! Unfortunaly I don't know why it does not work in your case as my knowledge about git is rather limited I must confess.

The action just executes these four commands:

  git fetch --all
  git push -f --all target
  git push -f --prune target
  git push -f --tags target

And it seems to fail on that last command for syncing the tags, with the message that your repo is in "detached HEAD" state.

When I run the action myself the output is:

git remote add target https://gitlab.com/***
+ git fetch --all
Fetching origin
From https://github.com/***
 * [new tag]         v1.14      -> v1.14
Fetching target
From https://gitlab.com/***
 * [new branch]      master     -> target/master
 * [new tag]         v1.***  -> v1.***
+ git push -f --all target
Everything up-to-date
+ git push -f --prune target
Everything up-to-date
+ git push -f --tags target
To ***
 + 9...dae9fd5 v1.14 -> v1.14 (forced update)

So in my case it syncs the tags without problems. But it would be really nice to make it work for you too, so if you have any suggestion which of those 4 commands needs to be changed, or what is "special" about your repo, Im happy to make those fixes.

Frederick888 commented 1 year ago

@kroese The key is to push the tag by itself to trigger a create event, so that actions/checkout checks out the tag.

In fact, this can be easily reproduced locally:

$ mkdir test && cd $_
$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /home/frederick/Downloads/test/.git/
$ git remote add origin https://github.com/Frederick888/git-credential-keepassxc
$ git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin '+refs/heads/*:refs/remotes/origin/*' '+refs/tags/*:refs/tags/*'
remote: Enumerating objects: 1828, done.
remote: Counting objects: 100% (179/179), done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 1828 (delta 150), reused 150 (delta 141), pack-reused 1649
Receiving objects: 100% (1828/1828), 751.65 KiB | 6.90 MiB/s, done.
Resolving deltas: 100% (1180/1180), done.
From https://github.com/Frederick888/git-credential-keepassxc
 * [new branch]      clap4          -> origin/clap4
 * [new branch]      master         -> origin/master
 * [new branch]      shell-comp     -> origin/shell-comp
 * [new branch]      yubikey-old    -> origin/yubikey-old
 * [new tag]         v0.1.0         -> v0.1.0
 * [new tag]         v0.1.1         -> v0.1.1
 * [new tag]         v0.1.2         -> v0.1.2
 * [new tag]         v0.1.3         -> v0.1.3
 * [new tag]         v0.10.0        -> v0.10.0
 * [new tag]         v0.10.1        -> v0.10.1
 * [new tag]         v0.10.1-beta.1 -> v0.10.1-beta.1
 * [new tag]         v0.10.1-beta.2 -> v0.10.1-beta.2
 * [new tag]         v0.10.1-beta.3 -> v0.10.1-beta.3
 * [new tag]         v0.10.1-beta.4 -> v0.10.1-beta.4
 * [new tag]         v0.10.2-beta.1 -> v0.10.2-beta.1
 * [new tag]         v0.10.2-beta.2 -> v0.10.2-beta.2
 * [new tag]         v0.10.2-beta.3 -> v0.10.2-beta.3
 * [new tag]         v0.11.0        -> v0.11.0
 * [new tag]         v0.12.0        -> v0.12.0
 * [new tag]         v0.13.0        -> v0.13.0
 * [new tag]         v0.14.0        -> v0.14.0
 * [new tag]         v0.2.0         -> v0.2.0
 * [new tag]         v0.3.0         -> v0.3.0
 * [new tag]         v0.3.1         -> v0.3.1
 * [new tag]         v0.3.2         -> v0.3.2
 * [new tag]         v0.3.3         -> v0.3.3
 * [new tag]         v0.4.0         -> v0.4.0
 * [new tag]         v0.4.1         -> v0.4.1
 * [new tag]         v0.4.2         -> v0.4.2
 * [new tag]         v0.4.3         -> v0.4.3
 * [new tag]         v0.5.0         -> v0.5.0
 * [new tag]         v0.5.1         -> v0.5.1
 * [new tag]         v0.6.0         -> v0.6.0
 * [new tag]         v0.6.1         -> v0.6.1
 * [new tag]         v0.7.0         -> v0.7.0
 * [new tag]         v0.8.0         -> v0.8.0
 * [new tag]         v0.8.1         -> v0.8.1
 * [new tag]         v0.8.2         -> v0.8.2
 * [new tag]         v0.9.0         -> v0.9.0
 * [new tag]         v0.9.1         -> v0.9.1
$ git checkout --progress --force refs/tags/v0.14.0
Note: switching to 'refs/tags/v0.14.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 1de3f2d chore: Bump version to 0.14.0
$ git push -f --prune origin
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>
jcbhmr commented 1 year ago

Hello! 👋

I had a similar problem using a different GitHub Action to mirror some SourceForge repos to GitHub. While doing some research on GitHub mirroring actions I came across this repo & issue. I know that I'm chiming in here with no context or anything, but here's some info that might help...

Would something like this work? This is kinda how the GitHub docs recommend doing things: https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository

git clone --bare https://github.com/octocat/project.git .
git push --mirror "https://x:$TOKEN@git.tsundere.moe/Frederick888/git-credential-keepassxc.git"

You could make it into a workflow like this maybe:

name: Sync to GitLab
on: [push, create, delete]
jobs:
  sync-to-gitlab:
    runs-on: ubuntu-latest
    steps:
      - run: git clone --bare "https://github.com/$GITHUB_REPOSITORY.git" .
      - run: git push --mirror "https://x:$TOKEN@git.tsundere.moe/Frederick888/git-credential-keepassxc.git"
        env:
          TOKEN: ${{ secrets.GITLAB_ACCESS_TOKEN }}

I know this strategy works great for syncing things from places like SourceForge or GitLab to GitHub, but I haven't had the chance yet to try the reverse.

This git push --mirror is what worked for me. idk if it'll work for you or if it's even relevant but I figured I'd mention it lol

kroese commented 1 year ago

@jcbhmr Thanks for your help! It would be very nice if I could fix this action so that it works for Frederick too.

Basicly it would mean that I change:

  git fetch --all
  git push -f --all target
  git push -f --prune target
  git push -f --tags target

to

git push --mirror $url

But I really have no idea what will be the implications of that. For example, maybe it re-uploads the whole history (instead of only the changeset) and the performance will suffer compared to the current method. Or maybe there are some other downsides?

Because there must be some reason that the original author of this action made the choice not to use git push --mirror?