Skip to content

Conversation

dscho
Copy link
Member

@dscho dscho commented Aug 19, 2023

To support contributors wishing to contribute to Git GUI via a mail-based flow, GitGitGadget maps Git GUI's branches into the git-gui/ namespace. For example, Git GUI's master branch is synchronized to https://github.com/gitgitgadget/git as git-gui/master and can be targeted via PRs.

To keep those git-gui/* branches synchronized, GitGitGadget has https://dev.azure.com/gitgitgadget/git/_build/index?definitionId=10

As part of the initiative to move away from Azure Pipelines, this commit offers a reimplementation of that Azure Pipeline as a GitHub workflow.

This workflow was verified to work correctly by temporarily adding a push trigger: https://github.com/gitgitgadget/gitgitgadget-workflows/actions/runs/5910229339/job/16031599392

@dscho dscho requested a review from webstech August 19, 2023 07:43
@dscho dscho self-assigned this Aug 19, 2023
@webstech
Copy link
Collaborator

@dscho, waiting for changes in PR #2 to be mirrored here.

To support contributors wishing to contribute to Git GUI via a
mail-based flow, GitGitGadget maps Git GUI's branches into the
`git-gui/` namespace. For example, Git GUI's `master` branch is
synchronized to https://github.com/gitgitgadget/git as `git-gui/master`
and can be targeted via PRs.

To keep those `git-gui/*` branches synchronized, GitGitGadget has
https://dev.azure.com/gitgitgadget/git/_build/index?definitionId=10

As part of the initiative to move away from Azure Pipelines, this commit
offers a reimplementation of that Azure Pipeline as a GitHub workflow.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member Author

dscho commented Aug 28, 2023

@dscho, waiting for changes in PR #2 to be mirrored here.

@webstech thank you for reminding me that I forgot to do this yet. Here is the range-diff:

  • 1: a855e8d ! 1: eddbced Add a scheduled workflow to synchronize Git GUI's branches

    @@ .github/workflows/sync-git-gui.yml (new)
     +  TARGET_REPOSITORY: gitgitgadget/git
     +  TARGET_REF_NAMESPACE: git-gui/
     +
    -+# Ideally, we would want to limit queuing to a single workflow run (i.e. if
    -+# there is already an active workflow run and a queued one, don't queue another
    -+# one), but that's not supported.
    ++# We want to limit queuing to a single workflow run i.e. if there is already
    ++# an active workflow run and a queued one, queue another one canceling the
    ++# already queued one.
     +concurrency:
     +  group: ${{ github.workflow }}
     +
    @@ .github/workflows/sync-git-gui.yml (new)
     +            }
     +
     +            const getRefs = async (repository, stripRefsPrefix) => {
    -+              for (let i = 1; i <= 10; i++) {
    ++              let attemptCounter = 1
    ++              for (;;) {
     +                try {
     +                  const [owner, repo] = repository.split('/')
     +                  let { data } = await github.rest.git.listMatchingRefs({
    @@ .github/workflows/sync-git-gui.yml (new)
     +                  if (e?.status !== 502) throw e
     +                }
     +
    -+                const seconds = i * i + 15 * Math.random()
    ++                if (++attemptCounter > 10) throw new Error('Giving up listing refs after 10 attempts')
    ++
    ++                const seconds = attemptCounter * attemptCounter + 15 * Math.random()
     +                core.info(`Encountered a Server Error; retrying in ${seconds} seconds`)
     +                await sleep(1000 * seconds)
     +              }
    @@ .github/workflows/sync-git-gui.yml (new)
     +            const refspecs = []
     +            const toFetch = new Set()
     +            for (let i = 0, j = 0; i < sourceRefs.length || j < targetRefs.length; ) {
    -+              const c =  i >= sourceRefs.length
    ++              const compare = i >= sourceRefs.length
     +                ? +1
     +                : j >= targetRefs.length
     +                  ? -1
     +                  : sourceRefs[i].name.localeCompare(targetRefs[j].name)
    -+              if (c > 0) {
    ++              if (compare > 0) {
     +                // no source ref => delete target ref
    -+                refspecs.push(`:${targetPrefix}${targetRefs[j++].name}`)
    -+              } else if (c < 0) {
    ++                refspecs.push(`:${targetPrefix}${targetRefs[j].name}`)
    ++                j++
    ++              } else if (compare < 0) {
     +                // no corresponding target ref yet => push source ref (new)
     +                const sha = sourceRefs[i].object.sha
     +                toFetch.add(sha)
    -+                refspecs.push(`${sha}:${targetPrefix}${sourceRefs[i++].name}`)
    -+              } else if (c === 0 && sourceRefs[i].object.sha !== targetRefs[j].object.sha) {
    -+                // target ref needs updating
    -+                const sha = sourceRefs[i].object.sha
    -+                toFetch.add(sha)
    -+                refspecs.push(`+${sha}:${targetPrefix}${sourceRefs[i++].name}`)
    -+                j++
    ++                refspecs.push(`${sha}:${targetPrefix}${sourceRefs[i].name}`)
    ++                i++
     +              } else {
    ++                // the sourceRef's name matches the targetRef's
    ++                if (sourceRefs[i].object.sha !== targetRefs[j].object.sha) {
    ++                  // target ref needs updating
    ++                  const sha = sourceRefs[i].object.sha
    ++                  toFetch.add(sha)
    ++                  refspecs.push(`+${sha}:${targetPrefix}${sourceRefs[i].name}`)
    ++                }
     +                i++
     +                j++
     +              }

Copy link
Collaborator

@webstech webstech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@webstech webstech merged commit 80b8272 into main Aug 29, 2023
@dscho dscho deleted the sync-git-gui branch August 31, 2023 05:54
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

Successfully merging this pull request may close these issues.

2 participants