Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync all branches #13

Closed
TobKed opened this issue Feb 18, 2022 · 9 comments
Closed

Sync all branches #13

TobKed opened this issue Feb 18, 2022 · 9 comments

Comments

@TobKed
Copy link
Owner

TobKed commented Feb 18, 2022

No description provided.

@GWen124
Copy link

GWen124 commented Feb 19, 2022

@TobKed
Sorry, I don't understand English, what I said was translated by translation software, please forgive me if there is any problem with the sentence.
The problem I'm currently having is the following:

  1. I don't know how to clone all branches of a repository, I can only clone a few branches at the same time.
  2. After this update, I can't batch clone branches of different authors into the same repository.

If I encounter problems in the future, I will come back and submit again.

@TobKed
Copy link
Owner Author

TobKed commented Feb 20, 2022

@GWen124 no probs, I am not a native English speaker as well :)

1. I don't know how to clone all branches of a repository, I can only clone a few branches at the same time.

What do you mean by cloning all branches? git clone command clones all branches however they are remote branches.
Did you mean clone as synchronising changes from one (upstream, source) repo to another (target) repo c
so they will be exact clones?

2. After this update, I can't batch clone branches of different authors into the same repository.

What do you meean by batch clone of different authors? Different authors suggests that there may be some conficts but I not sure what is the problem. Was it working before? Could you provide logs so I could try reproduce it?

@GWen124
Copy link

GWen124 commented Feb 21, 2022

image
image

The old version is okay. This is the picture I took last time, and it hasn't been uploaded.

@TobKed
Copy link
Owner Author

TobKed commented Feb 21, 2022

It could be caused by mistake I did in #11 which I fixed and merged here: #14 .
Please rerun it and let me know how it went (since you use @master version latest fix should be used and you don't have to change anything in your workflow)

@GWen124
Copy link

GWen124 commented Feb 21, 2022

It could be caused by mistake I did in #11 which I fixed and merged here: #14 .

Please rerun it and let me know how it went (since you use @master version latest fix should be used and you don't have to change anything in your workflow)

OK, thank you very much. I found the problem again later, and I'm coming to submit it.

Regarding the cloning of the entire warehouse branch, I don't know how to explain it. Let's take your warehouse as an example.

image

These are the three branches of your warehouse. How can I clone them at once?

@GWen124
Copy link

GWen124 commented Feb 21, 2022

For example, the main branch of your warehouse is "master" and the other branch is "18.06". How can I clone it at one time? After all, some authors use branches to distinguish versions.

@TobKed
Copy link
Owner Author

TobKed commented Feb 23, 2022

@GWen124
If you wnat to update muttiple branches you can use matrix to parametrize it. (docs).
I created example workflow of syncing all branches:

name: Sync all branches
on:
  workflow_dispatch:

jobs:

  generate-matrix:
    name: Generate matrix of branches
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Set matrix of branches
        id: set-matrix
        run: |
          upstream_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_UPSTREAM_REPOSITORY}.git"
          upstream_dir=${INPUT_UPSTREAM_REPOSITORY##*/}
          
          git clone "${upstream_repo}"
          cd "${upstream_dir}"
          
          JSON="{\"branch\":["
          
          for branch in `git branch -a | grep remotes | grep -v HEAD`; do
              branch_trimmed=$(echo -e $branch | sed -e "s/remotes\/origin\///g")
              JSON="$JSON\"${branch_trimmed}\","
          done
          
          if [[ $JSON == *, ]]; then
            JSON="${JSON%?}"
          fi
          JSON="$JSON]}"
          
          echo $JSON | jq
        
          echo "::set-output name=matrix::$( echo "$JSON" )"

        env:
          INPUT_GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          INPUT_UPSTREAM_REPOSITORY: apache/airflow

  update_external_airflow_fork:
    runs-on: ubuntu-latest
    needs: generate-matrix
    strategy:
      matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
      fail-fast: false
    steps:
      - uses: TobKed/github-forks-sync-action@master
        with:
          github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          upstream_repository: apache/airflow
          target_repository: TobKed/airflow
          upstream_branch: ${{ matrix.branch }}
          target_branch: ${{ matrix.branch }}
          force: true
          tags: true

@GWen124
Copy link

GWen124 commented Feb 24, 2022

@GWen124 If you wnat to update muttiple branches you can use matrix to parametrize it. (docs). I created example workflow of syncing all branches:

name: Sync all branches
on:
  workflow_dispatch:

jobs:

  generate-matrix:
    name: Generate matrix of branches
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Set matrix of branches
        id: set-matrix
        run: |
          upstream_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_UPSTREAM_REPOSITORY}.git"
          upstream_dir=${INPUT_UPSTREAM_REPOSITORY##*/}
          
          git clone "${upstream_repo}"
          cd "${upstream_dir}"
          
          JSON="{\"branch\":["
          
          for branch in `git branch -a | grep remotes | grep -v HEAD`; do
              branch_trimmed=$(echo -e $branch | sed -e "s/remotes\/origin\///g")
              JSON="$JSON\"${branch_trimmed}\","
          done
          
          if [[ $JSON == *, ]]; then
            JSON="${JSON%?}"
          fi
          JSON="$JSON]}"
          
          echo $JSON | jq
        
          echo "::set-output name=matrix::$( echo "$JSON" )"

        env:
          INPUT_GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          INPUT_UPSTREAM_REPOSITORY: apache/airflow

  update_external_airflow_fork:
    runs-on: ubuntu-latest
    needs: generate-matrix
    strategy:
      matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
      fail-fast: false
    steps:
      - uses: TobKed/github-forks-sync-action@master
        with:
          github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          upstream_repository: apache/airflow
          target_repository: TobKed/airflow
          upstream_branch: ${{ matrix.branch }}
          target_branch: ${{ matrix.branch }}
          force: true
          tags: true

ok, thanks a lot

@TobKed
Copy link
Owner Author

TobKed commented Apr 13, 2022

I added example to README in #16 and I am closing this issue for now.

@TobKed TobKed closed this as completed Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants