yesolutions/mirror-action

Remote "mirror" may already exist for self-hosted Actions runners

Closed this issue · 4 comments

Brought up initially in PR #17 by @duythinht

Currently, the mirroring script works on an assumption that the remote mirror does not exist when the action executes. This should be true when using GitHub-hosted runners and using . However, if a user is using a self-hosted GitHub Action runner, this assumption may not necessarily be true.

In such a case where the remote exists git remote add fails.

@duythinht when you encounter this problem, are you using actions/checkout@v1 in your workflow to checkout the repository initially?

@duythinht when you encounter this problem, are you using actions/checkout@v1 in your workflow to checkout the repository initially?

Yeah, I have encounter this situation when I using a self-hosted GitHub Action runner on my server (via NAT) and try to mirror in to our gitlab server (self-hosted and have no access form outside internet), and I have used checkout@v2.
You also can look at the workflow (I already fixed it by some change, and I think those commit should merge to your upstream, because someone might be need it.

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: self-hosted

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          fetch-depth: '0'
      - uses: duythinht/mirror-action@master
        with:
          REMOTE: 'https://gitlab.internal'
          GIT_USERNAME: mirror-bot
          GIT_PASSWORD: ${{ secrets.GITLAB_PASSWORD }}

Also, the problem is addressing for self-hosted action runner, there is only once runner that can be action running, so everytime when the action run, there are no need to init a repo, which is already stored on the runner server. And the runner just use to checkout the branch, tag, etc... to run the workflow.

There are total difference with the cloud runner, each time the runner is triggered, the gh cloud runner will "borrow" a server, that may be available in the server pool, and I think after run the workflow the runner should be clean up before return to pool, so next time that server is borrow from another runner, the situation existed remote repo is not happened.

I believe this is resolved by #22 released in v0.5.0