Skip to content

Commit

Permalink
feat: add github action to sync mellanox fork from k8swg upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Zeevi <[email protected]>
  • Loading branch information
maze88 committed Jul 17, 2024
1 parent 1e0d604 commit 697f1d5
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/fork-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Fork Sync

on:
schedule:
- cron: '0 0 * * *' # nightly
workflow_dispatch: # enable manual trigger

jobs:
lookup-most-recent-release-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lookup most recent release branch
id: lookup-most-recent-release-branch
run: |
git fetch --all
echo most_recent_release_branch=$(git branch --remotes --sort refname | grep network-operator- | tail -n 1 | cut -d '/' -f 2-) >> $GITHUB_OUTPUT
outputs:
most_recent_release_branch: ${{ steps.lookup-most-recent-release-branch.outputs.most_recent_release_branch }}

sync-fork:
runs-on: ubuntu-latest
needs: lookup-most-recent-release-branch
strategy:
fail-fast: false
matrix:
branch:
- master
- ${{ needs.lookup-most-recent-release-branch.outputs.most_recent_release_branch }}
steps:
- uses: actions/checkout@v4
if: ${{ matrix.branch != '' }}
with:
ref: ${{ matrix.branch }}
fetch-depth: 100
token: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} # TODO: check if redundant
persist-credentials: true
- name: Sync
if: ${{ matrix.branch != '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SYNC_BRANCH: sync-upstream/master-to-origin/${{ matrix.branch }}
run: |
git config user.name nvidia-ci-cd
git config user.email [email protected]
git remote add upstream https://github.com/k8snetworkplumbingwg/sriov-network-operator.git
git checkout -b $SYNC_BRANCH
git pull --no-ff upstream master
echo DEBUG AAAA
# git push origin $SYNC_BRANCH # pushed via `pr create --head` flag
# gh auth refresh -s project # TODO: check if required before PR creation
echo DEBUG BBBB
gh pr create \
--head $SYNC_BRANCH \
--base ${{ matrix.branch }} \
--title 'sync: from upstream master to ${{ matrix.branch }}' \
--body 'Created by [*${{ github.job }}* workflow job](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) to sync changes from [upstream](${{ github.server_url }}/k8snetworkplumbingwg/${{ github.event.repository.name }}) to [downstream](${{ github.server_url }}/${{ github.repository }}).'
echo DEBUG CCCC
# gh pr merge # TODO: uncomment after satisfied with PR creation result
git push -d origin $SYNC_BRANCH # cleanup # TODO: validate if this may be redundant after PR merged

0 comments on commit 697f1d5

Please sign in to comment.