Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Mirror OS PRs to internal monorepo | |
on: | |
pull_request_target: | |
branches: | |
- "main" | |
types: | |
- reopened | |
- opened | |
- synchronize | |
- edited | |
env: | |
branch_to_sync: ${{ github.base_ref || github.ref_name}} | |
sot_repo: NeuralQXLab/netket_pro | |
destination_repo: NeuralQXLab/nqxpack | |
jobs: | |
copybara-os-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up SSH key | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIV_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H github.com >> ~/.ssh/known_hosts | |
echo "https://x-access-token:${GH_TOKEN}@api.github.com" > ~/.git-credentials | |
env: | |
SSH_PRIV_KEY: ${{ secrets.SSH_GH_KEY }} | |
GH_TOKEN: ${{ secrets.GH_BOT_GITHUB_TOKEN }} | |
- name: Set up Git config | |
run: | | |
git config --global user.name "Quantum AI Lab @ X - Automation Bot" | |
git config --global user.email "quantumailabx@gmail.com" | |
- name: Reopen referenced PRs | |
if: github.event.action == 'reopened' | |
run: | | |
PR_NUMBER="${{ github.event.pull_request.number }}" | |
CONTENT="$(gh pr view "$PR_NUMBER" --json "body,comments" -q '.body, .comments[].body' | tac)" | |
while read -r line; do | |
if [[ $line =~ (Closes|Internal\ PR)\ ([^/]+)/([^/]+)#([0-9]+) ]]; then | |
OWNER="${BASH_REMATCH[2]}" | |
REPO="${BASH_REMATCH[3]}" | |
OTHER_PR="${BASH_REMATCH[4]}" | |
echo "Reopening PR: $OWNER/$REPO/$OTHER_PR" | |
gh pr reopen --repo "$OWNER/$REPO" \ | |
--comment "This pull request has been reopened because of reopening of https://github.com/${{ github.repository }}/pull/${PR_NUMBER}" \ | |
$OTHER_PR | |
fi | |
done <<< "$CONTENT" | |
env: | |
GH_TOKEN: ${{ secrets.GH_BOT_GITHUB_TOKEN }} | |
- name: Generate copybara config file | |
run: | | |
sed -e 's#<branch_to_sync>#${{ env.branch_to_sync }}#' \ | |
-e 's#<sot_repo>#${{ env.sot_repo }}#' \ | |
-e 's#<destination_repo>#${{ env.destination_repo }}#' \ | |
.github/workflows/common-copybara.bara.sky.template > .github/workflows/common-copybara.bara.sky | |
- uses: hazelcast/copybara-action@main | |
name: "Copybara PR #${{ github.event.pull_request.number }} -> ${{ env.branch_to_sync }}" | |
with: | |
ssh_key: ${{ secrets.SSH_GH_KEY }} | |
access_token: ${{ secrets.GH_BOT_GITHUB_TOKEN }} | |
sot_repo: ${{ env.sot_repo }} | |
sot_branch: ${{ env.branch_to_sync }} | |
destination_repo: ${{ env.destination_repo }} | |
copybara_options: "--nogit-destination-rebase" | |
custom_config: .github/workflows/os-pr.sky |