Skip to content

Commit

Permalink
Sync files with networkservicemesh/cmd-template
Browse files Browse the repository at this point in the history
This PR syncs files with https://github.com/networkservicemesh/cmd-template

Revision: https://github.com/networkservicemesh/cmd-template/commits/9aac57bb4f76370492e830689f749c1355b398b4

commit 9aac57bb4f76370492e830689f749c1355b398b4
Author: Nikita Skrynnik <[email protected]>
Date:   Thu Feb 3 16:18:59 2022 +0700

    Release-deployments workflow fix (#86)

    * checkout release branch

    Signed-off-by: Nikita Skrynnik <[email protected]>

    * add conflict resolve

    Signed-off-by: NSMBot <[email protected]>

    Co-authored-by: NSMBot <[email protected]>

Signed-off-by: NSMBot <[email protected]>
  • Loading branch information
NSMBot committed Feb 3, 2022
1 parent b08da85 commit 0bb7880
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
90 changes: 88 additions & 2 deletions .github/workflows/automerge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,45 @@ on:
types:
- completed
workflows:
- 'ci'
- "ci"
jobs:
automerge:
name: Automerge
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.actor == 'nsmbot' }}
outputs:
pr_branch_ref: ${{ steps.check_mergeability.outputs.pr_branch_ref }}
steps:
- name: Find current PR
uses: jwalton/[email protected]
id: findPr
with:
sha: ${{ github.event.workflow_run.head_sha }}
github-token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- name: Validate PR number
run: |
if [ -z ${{ steps.findPr.outputs.pr }} ]; then
echo "No opened PR was found for SHA ${{ github.event.workflow_run.head_sha }}"
exit 1
fi
- name: Get PR Info
id: get_pull_request_info
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/pulls/${{ steps.findPr.outputs.pr }}
env:
GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- name: Check mergeability
id: check_mergeability
run: |
echo "Mergeable: ${{ fromJson(steps.get_pull_request_info.outputs.data).mergeable }}"
PR_BRANCH_REF=${{ fromJson(steps.get_pull_request_info.outputs.data).head.ref }}
echo "PR_BRANCH_REF: $PR_BRANCH_REF"
echo "::set-output name=pr_branch_ref::$PR_BRANCH_REF"
if [ "${{ fromJson(steps.get_pull_request_info.outputs.data).mergeable }}" != "true" ]; then
echo "PR has conflicts"
exit 1
fi
- name: Check out the code
uses: actions/checkout@v2
- name: Fetch main
Expand All @@ -26,4 +58,58 @@ jobs:
with:
GITHUB_LOGIN: nsmbot
ENABLED_FOR_MANUAL_CHANGES: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
resolve_conflicts:
name: Autoresolve Conflicts
needs: [automerge]
if: ${{ always() && needs.automerge.result == 'failure' && needs.automerge.outputs.pr_branch_ref != '' && github.actor == 'nsmbot' }}
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- name: Checkout PR branch
uses: actions/checkout@v2
with:
ref: ${{ needs.automerge.outputs.pr_branch_ref }}
fetch-depth: 0
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- name: Verify conflicts only in go.mod/go.sum
run: |
CONFLICTING_FILES=$(git merge-tree $(git merge-base origin/main HEAD) origin/main HEAD | \
awk 'BEGIN {is_conflict = 0} /changed in both/{is_conflict = 1; next} /base/{if (is_conflict) {print $4; is_conflict = 0} next }' | \
{ grep -vF "go.mod" || true; } | \
{ grep -vF "go.sum" || true; })
if [[ -n $CONFLICTING_FILES ]]; then
echo "Conflicts can be resolved only in go.mod and go.sum files, but conflicts were found in other files: $CONFLICTING_FILES"
exit 1
fi
- name: Check number of retries
run: |
if [ $(git log --oneline | head -n 10 | grep -Fc "Automatically resolving conflicts in go.mod") -ge 3 ]; then
echo "Couldn't automatically resolve conflicts (number of re-tries is >= 3). Please, resolve them manually."
exit 1
fi
- name: Merge default branch
run: |
git config --global user.email "[email protected]"
git config --global user.name "NSMBot"
git config pull.rebase false
git pull -q origin main -s ort -X theirs
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Re-generate go.sum
run: go mod tidy
- name: Push changes
run: |
echo "Automatically resolving conflicts in go.mod and updating dependency versions to the latest" >> /tmp/commit-message
git config --global user.email "[email protected]"
git config --global user.name "NSMBot"
git add -- go.sum go.mod
git commit -s -F /tmp/commit-message
echo "Force-pushing changes to ${{ needs.automerge.outputs.pr_branch_ref }}"
git push -f origin ${{ needs.automerge.outputs.pr_branch_ref }}
7 changes: 7 additions & 0 deletions .github/workflows/release-deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ jobs:
echo Starting to check release branch in deployments-k8s repository
branch=release/${{ steps.get-tag-step.outputs.tag }}
echo branch to be checked - ${branch}
if ! [ -z "$(git ls-remote --heads origin ${branch})" ]; then
echo Branch ${branch} is already presented in deployments-k8s repository
exit 0;
fi
echo Branch ${branch} is not presented in repository
echo Starting to create ${branch} branch in deployments-k8s repository
git config --global user.email "[email protected]"
git config --global user.name "NSMBot"
git checkout -b ${branch}
git push -u origin ${branch} || exit 0;
update-deployments-k8s:
needs: check-branch
name: Update deployments-k8s
Expand All @@ -63,12 +67,14 @@ jobs:
echo "" >> /tmp/commit-message
echo "Commit Message:"
cat /tmp/commit-message
- name: Checkout networkservicemesh/deployments-k8s
uses: actions/checkout@v2
with:
path: networkservicemesh/deployments-k8s
repository: networkservicemesh/deployments-k8s
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
ref: release/${{ steps.get-tag-step.outputs.tag }}

- name: Find and Replace ci/${{ github.repository }} version
uses: jacobtomlinson/gha-find-replace@master
Expand All @@ -85,6 +91,7 @@ jobs:
echo Repository already up to date
exit 0;
fi
branch=release/${{ github.repository }}/${{ steps.get-tag-step.outputs.tag }}
git config --global user.email "[email protected]"
git config --global user.name "NSMBot"
Expand Down

0 comments on commit 0bb7880

Please sign in to comment.