| 1 |
name: GitHub to Gerrit Mirror |
| 2 |
|
| 3 |
run-name: "Mirror to Gerrit: ${{ github.event.ref || inputs.branch }} ${{ github.event.after }}" |
| 4 |
|
| 5 |
on: |
| 6 |
workflow_dispatch: |
| 7 |
inputs: |
| 8 |
branch: |
| 9 |
description: 'Branch to mirror (amd-staging or amd-mainline)' |
| 10 |
required: true |
| 11 |
default: 'amd-staging' |
| 12 |
type: choice |
| 13 |
options: |
| 14 |
- amd-staging |
| 15 |
- amd-mainline |
| 16 |
pull_request: |
| 17 |
branches: |
| 18 |
- amd-staging |
| 19 |
- amd-mainline |
| 20 |
types: [closed] |
| 21 |
|
| 22 |
env: |
| 23 |
GERRIT_SERVER: "gerrit-git.amd.com" |
| 24 |
GERRIT_PROJECT: "SYS-MGMT/ec/amd-smi" |
| 25 |
GERRIT_USER: "z1_runner" |
| 26 |
GERRIT_PORT: "29418" |
| 27 |
|
| 28 |
jobs: |
| 29 |
Setup: |
| 30 |
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true |
| 31 |
runs-on: banff-sc-cx43-29 |
| 32 |
steps: |
| 33 |
|
| 34 |
- name: Fix workspace permissions |
| 35 |
run: | |
| 36 |
sudo chown -R $(id -u):$(id -g) ${{ github.workspace }} |
| 37 |
sudo chmod -R u+rwX ${{ github.workspace }} |
| 38 |
|
| 39 |
- name: Check out repository code |
| 40 |
uses: actions/checkout@v4 |
| 41 |
with: |
| 42 |
fetch-depth: 0 |
| 43 |
|
| 44 |
- name: Create SSH key |
| 45 |
run: | |
| 46 |
mkdir -p ~/.ssh |
| 47 |
chmod 700 ~/.ssh |
| 48 |
touch ~/.ssh/known_hosts |
| 49 |
touch ~/.ssh/id_rsa |
| 50 |
chmod 600 ~/.ssh/id_rsa |
| 51 |
printf "%s" "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa |
| 52 |
ssh-keyscan -p ${{ env.GERRIT_PORT }} ${{ env.GERRIT_SERVER }} >> ~/.ssh/known_hosts |
| 53 |
|
| 54 |
- name: Debug SSH setup |
| 55 |
run: | |
| 56 |
ls -la ~/.ssh |
| 57 |
ssh -p ${{ env.GERRIT_PORT }} ${{ env.GERRIT_USER }}@${{ env.GERRIT_SERVER }} || true |
| 58 |
|
| 59 |
- name: Set Gerrit remote |
| 60 |
run: | |
| 61 |
cd ${{ github.workspace }} |
| 62 |
if git remote | grep -q "gerrit" |
| 63 |
then |
| 64 |
git remote set-url gerrit ssh://${{ env.GERRIT_USER }}@${{ env.GERRIT_SERVER }}:${{ env.GERRIT_PORT }}/${{ env.GERRIT_PROJECT }} |
| 65 |
else |
| 66 |
git remote add gerrit ssh://${{ env.GERRIT_USER }}@${{ env.GERRIT_SERVER }}:${{ env.GERRIT_PORT }}/${{ env.GERRIT_PROJECT }} |
| 67 |
fi |
| 68 |
|
| 69 |
- name: Set committer identity for Gerrit |
| 70 |
run: | |
| 71 |
git config user.name "z1_runner" |
| 72 |
git config user.email "[email protected]" |
| 73 |
|
| 74 |
- name: Fetch selected branch |
| 75 |
run: | |
| 76 |
BRANCH="${{ github.event.pull_request.base.ref || inputs.branch }}" |
| 77 |
git fetch origin ${BRANCH}:refs/remotes/origin/${BRANCH} |
| 78 |
git checkout ${BRANCH} |
| 79 |
|
| 80 |
- name: Mirror selected branch to Gerrit |
| 81 |
run: | |
| 82 |
BRANCH="${{ github.event.pull_request.base.ref || inputs.branch }}" |
| 83 |
git push gerrit refs/heads/${BRANCH}:refs/heads/${BRANCH} |