Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: workflow to lint repo config #66

Closed
wants to merge 15 commits into from
41 changes: 41 additions & 0 deletions .github/gh-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

declare -a errors

function validate_jq() {
local json="$1"
local query="$2"
local expected="$3"

local actual
actual=$(echo "$json" | jq -r "$query")

if ! echo "$actual" | grep -q "$expected"; then
errors+=("$query is set incorrectly:
expected: $expected
but was: $actual
")
fi
}

function check_errors() {
num_errors="${#errors[@]}"
if [ "$num_errors" -ne 0 ]; then
printf "%s\n" "${errors[@]}"
exit 1
else
echo "all good!"
fi
}

repo=$(gh api 'repos/{owner}/{repo}')

validate_jq "$repo" '.allow_squash_merge' 'true'
validate_jq "$repo" '.allow_merge_commit' 'false'
validate_jq "$repo" '.allow_rebase_merge' 'false'
validate_jq "$repo" '.allow_auto_merge' 'true'
validate_jq "$repo" '.delete_branch_on_merge' 'true'
validate_jq "$repo" '.allow_update_branch' 'true'
validate_jq "$repo" '.use_squash_pr_title_as_default' 'true'

check_errors
9 changes: 9 additions & 0 deletions .github/workflows/lint-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Lint Repo Settings

on:
pull_request:

jobs:
lint:
uses: SebastianGoeb/automation/.github/workflows/lint-repo-settings.yml@main
secrets: inherit
4 changes: 3 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: PR
on:
pull_request:
jobs:
lint-repo:
uses: "./.github/workflows/lint-repo.yml"

test:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -39,4 +42,3 @@ jobs:
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2.2.3
if: always()

Loading