From f16d84a5a7bf4f9cfb9a54d74bc35d128ff2c398 Mon Sep 17 00:00:00 2001 From: Michael Zeevi Date: Mon, 15 Jul 2024 14:18:53 +0300 Subject: [PATCH] feat: add github action to sync mellanox fork from k8swg upstream Signed-off-by: Michael Zeevi --- .github/workflows/fork-ci.yaml | 12 +++--- .github/workflows/fork-sync.yaml | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/fork-sync.yaml diff --git a/.github/workflows/fork-ci.yaml b/.github/workflows/fork-ci.yaml index 3a23a211d..9a734f8e4 100644 --- a/.github/workflows/fork-ci.yaml +++ b/.github/workflows/fork-ci.yaml @@ -1,11 +1,11 @@ name: Fork Docker CI -on: - push: - branches: - - network-operator-* - tags: - - network-operator-* +# on: +# push: +# branches: +# - network-operator-* +# tags: +# - network-operator-* jobs: determine_docker_registry_and_tag: diff --git a/.github/workflows/fork-sync.yaml b/.github/workflows/fork-sync.yaml new file mode 100644 index 000000000..b4b20806c --- /dev/null +++ b/.github/workflows/fork-sync.yaml @@ -0,0 +1,66 @@ +# TODO: uncomment triggers for sr-iov fork-ci workflow after fork-sync works +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 }} + persist-credentials: true + - name: Sync + if: ${{ matrix.branch != '' }} + env: + # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} + SYNC_BRANCH: sync-upstream/master-to-origin/${{ matrix.branch }} + run: | + git config user.name nvidia-ci-cd + git config user.email svc-cloud-orch-gh@nvidia.com + 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 --hostname https://github.com # --with-token $GH_TOKEN # TODO: try `echo $GH_TOKEN | gh auth login --with-token` + echo DEBUG BBBB + gh pr create \ + --head $SYNC_BRANCH \ + --base Mellanox:${{ 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 + echo DEBUG DDDD + + git push -d origin $SYNC_BRANCH # cleanup # TODO: validate if this may be redundant after PR merged