From 6b77c8f77059208b780f314f26e1ca427f564f20 Mon Sep 17 00:00:00 2001 From: David Davis Date: Thu, 9 Sep 2021 13:53:26 -0400 Subject: [PATCH] Add a single commit check workflow [noissue] --- .github/workflows/check_commits.yaml | 14 ++++++++++++++ CHANGES/494.feature | 1 + README.md | 2 ++ plugin-template | 1 + templates/github/.github/workflows/ci.yml.j2 | 17 +++++++++++++++++ 5 files changed, 35 insertions(+) create mode 100644 CHANGES/494.feature diff --git a/.github/workflows/check_commits.yaml b/.github/workflows/check_commits.yaml index c29bf715..499960c6 100644 --- a/.github/workflows/check_commits.yaml +++ b/.github/workflows/check_commits.yaml @@ -2,6 +2,20 @@ name: Check Commit on: pull_request jobs: + single_commit: + name: Assert single commit + steps: + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 30 + - name: Checkout master + run: git fetch origin master + - name: create local master branch + run: git branch master origin/master + - name: Commit Count Check + run: test `git log --oneline --no-merges HEAD ^master | wc -l ` = 1 + runs-on: ubuntu-latest test: runs-on: ubuntu-latest steps: diff --git a/CHANGES/494.feature b/CHANGES/494.feature new file mode 100644 index 00000000..4037277e --- /dev/null +++ b/CHANGES/494.feature @@ -0,0 +1 @@ +Added a workflow to check that PRs contain a single commit. diff --git a/README.md b/README.md index 45c2fb83..db4e8a1f 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,8 @@ The following settings are stored in `template_config.yml`. noissue_marker A string that is used to mark a commit as not attached to an issue. + single_commit_check Runs a job to check whether a PR contains a single commit or not. + sync_ci Enables a nightly workflow to update the CI files. test_bindings Include a job that runs a script to test generated client diff --git a/plugin-template b/plugin-template index 2b56819c..3b6e6d0a 100755 --- a/plugin-template +++ b/plugin-template @@ -60,6 +60,7 @@ DEFAULT_SETTINGS = { "release_user": "pulpbot", "release_email": "pulp-infra@redhat.com", "noissue_marker": "[noissue]", + "single_commit_check": True, "sync_ci": True, "test_bindings": True, "test_cli": False, diff --git a/templates/github/.github/workflows/ci.yml.j2 b/templates/github/.github/workflows/ci.yml.j2 index a04c2e6a..80a6e15e 100644 --- a/templates/github/.github/workflows/ci.yml.j2 +++ b/templates/github/.github/workflows/ci.yml.j2 @@ -17,6 +17,23 @@ jobs: {% if pre_job_template -%}{{ " " | indent }}{% include pre_job_template.path %}{%- endif %} + {%- if single_commit_check %} + single_commit: + name: Assert single commit + steps: + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 30 + - name: Checkout {{ plugin_default_branch }} + run: git fetch origin {{ plugin_default_branch }} + - name: create local {{ plugin_default_branch }} branch + run: git branch {{ plugin_default_branch }} origin/{{ plugin_default_branch }} + - name: Commit Count Check + run: test `git log --oneline --no-merges HEAD ^{{ plugin_default_branch }} | wc -l ` = 1 + runs-on: ubuntu-latest + {%- endif %} + lint: runs-on: ubuntu-latest {% if pre_job_template %}needs: {{ pre_job_template.name }}{% endif %}