Home > database >  Periodically clone external repo with github actions and set it as a private repo
Periodically clone external repo with github actions and set it as a private repo

Time:01-05

I am trying to set a GitHub action that periodically clones an external repository (e.g., targetuser/targetrepo and for which I have a personal access token).

The GitHub action runs smoothly, but I have no clue where the repository is being cloned: I cannot see it in my GitHub account.
Also, I would like the cloned repository to be set as private.

This is my main.yml file based on this response:

name: mainAction
on:
  schedule:
    - cron:  "*/5 * * * *"
  workflow_dispatch:
    
jobs: 
  copyRepo:
    runs-on: macOS-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Copy repo
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
      run: git clone "https://"$ACCESS_TOKEN"@github.com/targetuser/targetrepo.git"

Edit
I would like to have a copy of the GitHub repository on my account, and not just in the runner's "container".

CodePudding user response:

I would like to have a copy of the github repository on my account, and not just in the runner's "container".

That would be better address by a mirroring GitHub Action, like wearerequired/git-mirror-action, or better, in your case (using tokens): pkgstore/github-action-mirror

name: "Repository Mirror: GitHub"

on:
  schedule:
    - cron:  "*/5 * * * *"
  workflow_dispatch:

jobs:
  mirror:
    runs-on: ubuntu-latest
    name: "Mirror"
    steps:
      - uses: pkgstore/github-action-mirror@main
        with:
          source_repo: "https://github.com/${{ github.repository }}.git"
          source_user: "${{ secrets.MIRROR_SOURCE_USER_GITHUB }}"
          source_token: "${{ secrets.MIRROR_SOURCE_TOKEN_GITHUB }}"
          target_repo: "${{ secrets.MIRROR_TARGET_URL_GITHUB }}"
          target_user: "${{ secrets.MIRROR_TARGET_USER_GITHUB }}"
          target_token: "${{ secrets.MIRROR_TARGET_TOKEN_GITHUB }}"

That way, you can send the source repository to a private repository of yours.

  •  Tags:  
  • Related