Skip to content
Latchkey

Repo Sync Triggered by PR workflow (intel/neural-compressor)

The Repo Sync Triggered by PR workflow from intel/neural-compressor, explained and optimized by Latchkey.

C

CI health: C - fair

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: intel/neural-compressor.github/workflows/pr-code-sync.ymlLicense Apache-2.0View source

What it does

This is the Repo Sync Triggered by PR workflow from the intel/neural-compressor repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# Sync code between InnerSource and External GitHub repositories

name: Repo Sync Triggered by PR

on:
  pull_request:
    branches: [main]
    types: [opened, reopened, ready_for_review, synchronize]
  push:
    branches: [main]
  schedule:
    - cron: '0 * * * *'
  workflow_dispatch:

env:
  INNERSOURCE_REPO: intel-innersource/frameworks.ai.lpot.neural-compressor
  INNERSOURCE_BRANCH: main
  EXTERNAL_REPO: intel/neural-compressor
  EXTERNAL_BRANCH: main

permissions:
  contents: read

jobs:
  git-sync:
    if: ${{ contains(github.repository, 'intel-innersource') }}
    runs-on: [repo-sync]
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Git sync
        run: |
          internal_sha=$(git ls-remote https://github.com/${INNERSOURCE_REPO}.git refs/heads/${INNERSOURCE_BRANCH} | cut -f1)
          external_sha=$(git ls-remote https://github.com/${EXTERNAL_REPO}.git refs/heads/${EXTERNAL_BRANCH} | cut -f1)
          if [ "$internal_sha" = "$external_sha" ]; then
              echo "SHAs are aligned, no need to sync. SHA: $internal_sha."
              exit 0
          else
              echo "SHAs are not aligned. Internal SHA: $internal_sha, External SHA: $external_sha"
          fi

          git clone --depth=1 -b $EXTERNAL_BRANCH https://${{ secrets.REPO_SYNC_USER_NAME }}:${{ secrets.REPO_SYNC_SSH_PRIVATE_KEY }}@github.com/${EXTERNAL_REPO}.git neural-compressor
          cd neural-compressor
          git remote add innersource https://${{ secrets.REPO_SYNC_USER_NAME }}:${{ secrets.REPO_SYNC_SSH_PRIVATE_KEY }}@github.com/${INNERSOURCE_REPO}.git
          git fetch innersource ${INNERSOURCE_BRANCH} --depth=100
          git fetch origin ${EXTERNAL_BRANCH} --depth=100
          MB=$(git merge-base $external_sha $internal_sha)

          if [ "$MB" = "$external_sha" ]; then
              echo "Need to sync internal code into external!"
              git push origin innersource/${INNERSOURCE_BRANCH}:${EXTERNAL_BRANCH}
          elif [ "$MB" = "$internal_sha" ]; then
              echo "Need to sync external code into internal!"
              git push innersource origin/${EXTERNAL_BRANCH}:${INNERSOURCE_BRANCH}
          else
              echo "::error::${INNERSOURCE_REPO}:${INNERSOURCE_BRANCH} and ${EXTERNAL_REPO}:${EXTERNAL_BRANCH} commit history have diverged, manual intervention required!"
              exit 1
          fi

      - name: Clean up
        if: always()
        run: |
          rm -rf ${{github.workspace}}/* || true

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# Sync code between InnerSource and External GitHub repositories
 
name: Repo Sync Triggered by PR
 
on:
  pull_request:
    branches: [main]
    types: [opened, reopened, ready_for_review, synchronize]
  push:
    branches: [main]
  schedule:
    - cron: '0 * * * *'
  workflow_dispatch:
 
env:
  INNERSOURCE_REPO: intel-innersource/frameworks.ai.lpot.neural-compressor
  INNERSOURCE_BRANCH: main
  EXTERNAL_REPO: intel/neural-compressor
  EXTERNAL_BRANCH: main
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  git-sync:
    timeout-minutes: 30
    if: ${{ contains(github.repository, 'intel-innersource') }}
    runs-on: [repo-sync]
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Git sync
        run: |
          internal_sha=$(git ls-remote https://github.com/${INNERSOURCE_REPO}.git refs/heads/${INNERSOURCE_BRANCH} | cut -f1)
          external_sha=$(git ls-remote https://github.com/${EXTERNAL_REPO}.git refs/heads/${EXTERNAL_BRANCH} | cut -f1)
          if [ "$internal_sha" = "$external_sha" ]; then
              echo "SHAs are aligned, no need to sync. SHA: $internal_sha."
              exit 0
          else
              echo "SHAs are not aligned. Internal SHA: $internal_sha, External SHA: $external_sha"
          fi
 
          git clone --depth=1 -b $EXTERNAL_BRANCH https://${{ secrets.REPO_SYNC_USER_NAME }}:${{ secrets.REPO_SYNC_SSH_PRIVATE_KEY }}@github.com/${EXTERNAL_REPO}.git neural-compressor
          cd neural-compressor
          git remote add innersource https://${{ secrets.REPO_SYNC_USER_NAME }}:${{ secrets.REPO_SYNC_SSH_PRIVATE_KEY }}@github.com/${INNERSOURCE_REPO}.git
          git fetch innersource ${INNERSOURCE_BRANCH} --depth=100
          git fetch origin ${EXTERNAL_BRANCH} --depth=100
          MB=$(git merge-base $external_sha $internal_sha)
 
          if [ "$MB" = "$external_sha" ]; then
              echo "Need to sync internal code into external!"
              git push origin innersource/${INNERSOURCE_BRANCH}:${EXTERNAL_BRANCH}
          elif [ "$MB" = "$internal_sha" ]; then
              echo "Need to sync external code into internal!"
              git push innersource origin/${EXTERNAL_BRANCH}:${INNERSOURCE_BRANCH}
          else
              echo "::error::${INNERSOURCE_REPO}:${INNERSOURCE_BRANCH} and ${EXTERNAL_REPO}:${EXTERNAL_BRANCH} commit history have diverged, manual intervention required!"
              exit 1
          fi
 
      - name: Clean up
        if: always()
        run: |
          rm -rf ${{github.workspace}}/* || true
 

What changed

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.