From 5e500ae17877750f42ff00f5c8bb08daa17aed1c Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Wed, 18 Aug 2021 11:22:05 +0100 Subject: [PATCH 1/2] updating pipeline to auto release on tag. adding mergify config --- .github/mergify.yml | 247 ++++++++++++++++++++++++++++++++ .github/workflows/run-tests.yml | 75 ++++++---- .make/go.mk | 3 + 3 files changed, 295 insertions(+), 30 deletions(-) create mode 100644 .github/mergify.yml diff --git a/.github/mergify.yml b/.github/mergify.yml new file mode 100644 index 00000000..eb9f7a9b --- /dev/null +++ b/.github/mergify.yml @@ -0,0 +1,247 @@ +pull_request_rules: + + # =============================================================================== + # DEPENDABOT + # =============================================================================== + + - name: Automatic Merge for Dependabot Minor Version Pull Requests + conditions: + - -draft + - author~=^dependabot(|-preview)\[bot\]$ + - check-success='build (1.14.x, ubuntu-latest)' + - check-success='build (1.15.x, ubuntu-latest)' + - check-success='build (1.16.x, ubuntu-latest)' + - check-success='build (1.14.x, macos-latest)' + - check-success='build (1.15.x, macos-latest)' + - check-success='build (1.16.x, macos-latest)' + - check-success='lint (1.15.x, ubuntu-latest)' + - check-success='lint (1.16.x, ubuntu-latest)' + - check-success='lint (1.15.x, macos-latest)' + - check-success='lint (1.16.x, macos-latest)' + - check-success='Analyze (go)' + - title~=^Bump [^\s]+ from ([\d]+)\..+ to \1\. + actions: + review: + type: APPROVE + message: Automatically approving dependabot pull request + merge: + method: merge + - name: Alert on major version detection + conditions: + - author~=^dependabot(|-preview)\[bot\]$ + - check-success='build (1.14.x, ubuntu-latest)' + - check-success='build (1.15.x, ubuntu-latest)' + - check-success='build (1.16.x, ubuntu-latest)' + - check-success='build (1.14.x, macos-latest)' + - check-success='build (1.15.x, macos-latest)' + - check-success='build (1.16.x, macos-latest)' + - check-success='lint (1.15.x, ubuntu-latest)' + - check-success='lint (1.16.x, ubuntu-latest)' + - check-success='lint (1.15.x, macos-latest)' + - check-success='lint (1.16.x, macos-latest)' + - check-success='Analyze (go)' + - -title~=^Bump [^\s]+ from ([\d]+)\..+ to \1\. + actions: + comment: + message: "⚠️ @theflyingcodr @jadwahab: this is a major version bump and requires your attention" + + + # =============================================================================== + # AUTOMATIC MERGE (APPROVALS) + # =============================================================================== + + - name: Automatic Merge ⬇️ on Approval ✔ + conditions: + - "#approved-reviews-by>=1" + - check-success='build (1.14.x, ubuntu-latest)' + - check-success='build (1.15.x, ubuntu-latest)' + - check-success='build (1.16.x, ubuntu-latest)' + - check-success='build (1.14.x, macos-latest)' + - check-success='build (1.15.x, macos-latest)' + - check-success='build (1.16.x, macos-latest)' + - check-success='lint (1.15.x, ubuntu-latest)' + - check-success='lint (1.16.x, ubuntu-latest)' + - check-success='lint (1.15.x, macos-latest)' + - check-success='lint (1.16.x, macos-latest)' + - check-success='Analyze (go)' + - label!=work-in-progress + - -draft + actions: + merge: + method: merge + + # =============================================================================== + # AUTHOR + # =============================================================================== + + - name: Auto-Assign Author + conditions: + - "#assignee=0" + actions: + assign: + users: [ "theflyingcodr" ] + + # =============================================================================== + # ALERTS + # =============================================================================== + + - name: Notify on merge + conditions: + - merged + - label=automerge + actions: + comment: + message: "✅ @{{author}}: **{{title}}** has been merged successfully." + - name: Alert on merge conflict + conditions: + - conflict + - label=automerge + actions: + comment: + message: "🆘 @{{author}}: `{{head}}` has conflicts with `{{base}}` that must be resolved." + label: + add: + - conflict + - name: Alert on tests failure for automerge + conditions: + - label=automerge + - status-failure=commit + actions: + comment: + message: "🆘 @{{author}}: unable to merge due to CI failure." + + - name: remove conflict label if not needed + conditions: + - -conflict + actions: + label: + remove: + - conflict + + # =============================================================================== + # LABELS + # =============================================================================== + # Automatically add labels when PRs match certain patterns + # + # NOTE: + # - single quotes for regex to avoid accidental escapes + # - Mergify leverages Python regular expressions to match rules. + # + # Semantic commit messages + # - chore: updating grunt tasks etc.; no production code change + # - docs: changes to the documentation + # - feat: feature or story + # - enhancement: an improvement to an existing feature + # - feat: new feature for the user, not a new feature for build script + # - fix: bug fix for the user, not a fix to a build script + # - idea: general idea or suggestion + # - test: test related changes + # =============================================================================== + + - name: Hotfix label + conditions: + - "head~=(?i)^hotfix" # if the PR branch starts with hotfix/ + actions: + label: + add: ["hot-fix"] + - name: Bug / Fix label + conditions: + - "head~=(?i)^(bug)?fix" # if the PR branch starts with (bug)?fix/ + actions: + label: + add: [ "bug-P3" ] + - name: Documentation label + conditions: + - "head~=(?i)^docs" # if the PR branch starts with docs/ + actions: + label: + add: [ "documentation" ] + - name: Feature label + conditions: + - "head~=(?i)^feat(ure)?" # if the PR branch starts with feat(ure)?/ + actions: + label: + add: ["feature"] + - name: Enhancement label + conditions: + - "head~=(?i)^enhancement?" # if the PR branch starts with enhancement/ + actions: + label: + add: ["feature"] + - name: Chore label + conditions: + - "head~=(?i)^chore" # if the PR branch starts with chore/ + actions: + label: + add: ["update"] + - name: Question label + conditions: + - "head~=(?i)^question" # if the PR branch starts with question/ + actions: + label: + add: ["question"] + - name: Test label + conditions: + - "head~=(?i)^test" # if the PR branch starts with test/ + actions: + label: + add: ["test"] + - name: Idea label + conditions: + - "head~=(?i)^idea" # if the PR branch starts with idea/ + actions: + label: + add: ["idea"] + + # =============================================================================== + # STALE BRANCHES + # =============================================================================== + + - name: Close stale pull request + conditions: + - base=master + - -closed + - updated-at<21 days ago + actions: + close: + message: | + This pull request looks stale. Feel free to reopen it if you think it's a mistake. + # =============================================================================== + # BRANCHES + # =============================================================================== + + - name: Delete head branch after merge + conditions: + - merged + actions: + delete_head_branch: + + #- name: automatic update for PR marked as “Ready-to-Go“ + # conditions: + # - -conflict # skip PRs with conflicts + # - -draft # filter-out GH draft PRs + # - label="Ready-to-Go" + # actions: + # update: + + # =============================================================================== + # CONVENTION + # =============================================================================== + # https://www.conventionalcommits.org/en/v1.0.0/ + # Premium feature only + + #- name: Conventional Commit + # conditions: + # - "title~=^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\\(.+\\))?:" + # actions: + # post_check: + # title: | + # {% if check_succeed %} + # Title follows Conventional Commit + # {% else %} + # Title does not follow Conventional Commit + # {% endif %} + # summary: | + # {% if not check_succeed %} + # Your pull request title must follow [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/). + # {% endif %} \ No newline at end of file diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 90207913..c33eec9e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,43 +1,58 @@ -name: run-go-tests - -env: - GO111MODULE: on +name: Go on: - pull_request: - branches: - - "*" push: - branches: - - "*" - schedule: - - cron: '1 4 * * *' + tags: + - '*' + branches: [ master ] + pull_request: + branches: [ master ] jobs: - test: + golangci: strategy: matrix: - go-version: [ 1.15.x,1.16.x, ] - os: [ ubuntu-latest ] + go-version: [1.15.x,1.16.x] + os: [macos-latest, ubuntu-latest] + name: lint runs-on: ${{ matrix.os }} steps: - - name: Install Go + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: latest + build: + strategy: + matrix: + go-version: [ 1.14.x, 1.15.x, 1.16.x ] + os: [ macos-latest, ubuntu-latest ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + + - name: Set up Go ${{ matrix.go-version }} uses: actions/setup-go@v2 with: go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: | - ~/go/pkg/mod # Module download cache - ~/.cache/go-build # Build cache (Linux) - ~/Library/Caches/go-build # Build cache (Mac) - '%LocalAppData%\go-build' # Build cache (Windows) - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Run linter and tests - run: make test-ci + + - name: Tests + run: make test-unit - name: Update code coverage - run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file + run: bash <(curl -s https://codecov.io/bash) + - name: Build + run: go build -v ./... + release: + needs: [golangci,build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: release + uses: goreleaser/goreleaser-action@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.make/go.mk b/.make/go.mk index 8a093b7c..341d1d5a 100644 --- a/.make/go.mk +++ b/.make/go.mk @@ -57,6 +57,9 @@ test: ## Runs vet, lint and ALL tests @echo "running tests..." @go test ./... -v +test-unit: + @go test ./... -race -coverprofile=coverage.txt -covermode=atomic + test-short: ## Runs vet, lint and tests (excludes integration tests) @$(MAKE) lint @echo "running tests (short)..." From e9a3861caa64e6c0f4b0443bdcd96a2fe883acc5 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Wed, 18 Aug 2021 11:40:07 +0100 Subject: [PATCH 2/2] use author variable for auto assign --- .github/mergify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/mergify.yml b/.github/mergify.yml index eb9f7a9b..7fde66fd 100644 --- a/.github/mergify.yml +++ b/.github/mergify.yml @@ -79,7 +79,7 @@ pull_request_rules: - "#assignee=0" actions: assign: - users: [ "theflyingcodr" ] + users: [ "@{{author}}" ] # =============================================================================== # ALERTS