From 9e9623f9b4f12d22122facce8779c5ea396a5de4 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 | 13 ++++++++++ CHANGES/tba.feature | 1 + README.md | 2 ++ .../github/.ci/scripts/discourse_post.sh | 24 +++++++++++++++++++ .../.github/workflows/single_commit.yml.j2 | 24 +++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 CHANGES/tba.feature create mode 100644 templates/github/.ci/scripts/discourse_post.sh create mode 100644 templates/github/.github/workflows/single_commit.yml.j2 diff --git a/.github/workflows/check_commits.yaml b/.github/workflows/check_commits.yaml index c29bf715..96a5f591 100644 --- a/.github/workflows/check_commits.yaml +++ b/.github/workflows/check_commits.yaml @@ -2,6 +2,19 @@ name: Check Commit on: pull_request jobs: + 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/tba.feature b/CHANGES/tba.feature new file mode 100644 index 00000000..4037277e --- /dev/null +++ b/CHANGES/tba.feature @@ -0,0 +1 @@ +Added a workflow to check that PRs contain a single commit. diff --git a/README.md b/README.md index fe5187de..89ae2cd4 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 workflow to indicate 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/templates/github/.ci/scripts/discourse_post.sh b/templates/github/.ci/scripts/discourse_post.sh new file mode 100644 index 00000000..a0cab577 --- /dev/null +++ b/templates/github/.ci/scripts/discourse_post.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Posts a release announcement to discourse + +URL="https://discourse.pulpproject.org/posts.json" +CATEGORY=1 # Announcements +DISCOURSE_USER="system" + +plugin="$1" +version="$2" +body = $(cat <<-EOM +$plugin $version has been released. + +PyPI: https://pypi.org/project/$plugin/$version/ +Changelog: Changelog — Pulp File 1.9.1 documentation +Docs: pulp_file Plugin — Pulp File 1.9.1 documentation +Python bindings: pulp-file-client · PyPI +Ruby bindings: pulp_file_client | RubyGems.org | your community gem host +EOM + +curl -X POST "$URL" + -H "Api-Key: $DISCOURSE_TOKEN" + -H "Api-Username: $DISCOURSE_USER" + -H "title: $1 $2 has been released" diff --git a/templates/github/.github/workflows/single_commit.yml.j2 b/templates/github/.github/workflows/single_commit.yml.j2 new file mode 100644 index 00000000..ec74557e --- /dev/null +++ b/templates/github/.github/workflows/single_commit.yml.j2 @@ -0,0 +1,24 @@ +name: Assert Single Commit + +on: + {%- if single_commit_check -%} + pull_request: + branches: [ {{ plugin_default_branch }} ] + {%- else -%} + workflow_dispatch: # don't run + {%- endif -%} + +jobs: + 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