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/e8ed376ecfda3a4aad2f7ffab6098abba0515c8e

commit e8ed376ecfda3a4aad2f7ffab6098abba0515c8e
Author: Nikita Skrynnik <93182827+NikitaSkrynnik@users.noreply.github.com>
Date:   Mon Jul 25 21:22:30 2022 +1100

    Add reusable workflows (#105)

    * reuse already existing workflows from .github

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * replace docker-push workflows

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * rework release workflow

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * rework update-deployments and ci workflows

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * finish reworking workflows

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * minor fixes

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * specify config_file path for yamllint job in CI workflow

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * fix automerge

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * fix yamllint issues

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * fix docker-build-and-test job in CI workflow

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

    * add print-debug-info job to automerge workflow

    Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
  • Loading branch information
NSMBot committed Jul 25, 2022
1 parent 8b8a17c commit a959afd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 419 deletions.
131 changes: 22 additions & 109 deletions .github/workflows/automerge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,115 +7,28 @@ on:
workflows:
- "ci"
jobs:
automerge:
name: Automerge
print-debug-info:
name: Print debug info
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/gh-find-current-pr@v1.0.2
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/request-action@v2.x
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
run: |
git remote -v
git fetch --depth=1 origin main
- name: Only allow go.mod and go.sum changes
run: |
find . -type f ! -name 'go.mod' ! -name 'go.sum' ! -name '*.yaml' ! -name '*.yml' ! -name '*.txt' ! -name '*.md' ! -name '*.conf' -exec git diff --exit-code origin/main -- {} +
- name: Merge PR
uses: ridedott/merge-me-action@master
with:
GITHUB_LOGIN: nsmbot
ENABLED_FOR_MANUAL_CHANGES: true
GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- uses: hmarr/debug-action@v2

check-mergeability:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.actor == 'nsmbot' }}
uses: networkservicemesh/.github/.github/workflows/check-mergeability.yaml@main
secrets:
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}

automerge:
needs: [check-mergeability]
if: ${{ needs.check-mergeability.result == 'success' }}
uses: networkservicemesh/.github/.github/workflows/automerge.yaml@main

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 "nsmbot@networkservicmesh.io"
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.18.2
- name: Update version manually
run: |
branch=${{ needs.automerge.outputs.pr_branch_ref }}
repository=${branch#update/networkservicemesh/}
echo Update ${repository} version in go.mod manually
go get -u github.com/networkservicemesh/${repository}@main
- 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 "nsmbot@networkservicmesh.io"
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 }}
needs: [check-mergeability]
if: ${{ always() && needs.check-mergeability.result == 'failure' && needs.check-mergeability.outputs.pr_branch_ref != '' }}
uses: networkservicemesh/.github/.github/workflows/resolve-conflicts.yaml@main
with:
pr_branch_ref: ${{ needs.check-mergeability.outputs.pr_branch_ref }}
secrets:
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
54 changes: 1 addition & 53 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,4 @@ on:

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['go']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

# - run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: networkservicemesh/.github/.github/workflows/codeql-analysis.yaml@main
36 changes: 3 additions & 33 deletions .github/workflows/docker-push-ghcr.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: docker-push-ghcr
name: Docker push ghcr

on:
push:
Expand All @@ -10,36 +10,6 @@ on:
workflows:
- 'automerge'
jobs:
docker:
runs-on: ubuntu-latest
push:
if: ${{ github.repository != 'networkservicemesh/cmd-template' && (github.event.workflow_run.conclusion == 'success' && github.actor == 'nsmbot' || github.event_name == 'push') }}
steps:
- name: "Checkout"
uses: actions/checkout@v2

- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v1

- name: "Login to GitHub Container Registry"
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: metaci
uses: docker/metadata-action@v3
with:
images: ghcr.io/${{ github.repository_owner }}/ci/${{ github.event.repository.name }}
tags: |
type=ref,event=pr
type=sha,prefix=
- name: "Build and push"
uses: docker/build-push-action@v2
with:
file: Dockerfile
context: .
push: true
tags: ${{ steps.metaci.outputs.tags }}
uses: networkservicemesh/.github/.github/workflows/docker-push-ghcr.yaml@main
20 changes: 3 additions & 17 deletions .github/workflows/pr-for-updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ on:
- update/**
jobs:
auto-pull-request:
name: Pull Request on update/sync Branch Push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Construct PR message
run: |
PULL_REQUEST_BODY=$(git log --pretty='format:%B' -1 | sed '/^$/d;$d' | sed 's/#/# /g')
echo "$PULL_REQUEST_BODY"
echo "PULL_REQUEST_BODY<<EOF" >> $GITHUB_ENV
echo "$PULL_REQUEST_BODY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: pull-request-action
uses: vsoch/pull-request-action@1.0.12
env:
GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
BRANCH_PREFIX: "update/"
PULL_REQUEST_BRANCH: "main"
uses: networkservicemesh/.github/.github/workflows/pr-for-updates.yaml@main
secrets:
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
Loading

0 comments on commit a959afd

Please sign in to comment.