From ec9672252a2cddca52f0e154bdd8444a48f3913b Mon Sep 17 00:00:00 2001 From: Raymond Berger Date: Sun, 18 Apr 2021 23:59:15 -1000 Subject: [PATCH] Run `awesome-lint` on new additions (#1962) Co-authored-by: Sindre Sorhus --- .github/workflows/main.yml | 14 ++++++++++++++ .github/workflows/repo_linter.sh | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100755 .github/workflows/repo_linter.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..db9455f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,14 @@ +on: + pull_request: + branches: [main] + paths: + - 'readme.md' +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: awesome-lint + run: ./.github/workflows/repo_linter.sh diff --git a/.github/workflows/repo_linter.sh b/.github/workflows/repo_linter.sh new file mode 100755 index 0000000..a407f9c --- /dev/null +++ b/.github/workflows/repo_linter.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Find the repo in the git diff and then set it to an env variables. +REPO_TO_LINT=$( + git diff main readme.md | + # Look for changes (indicated by lines starting with +). + grep ^+ | + # Get the line that includes the readme. + grep -Eo 'https.*#readme' | + # Get just the URL. + sed 's/#readme//') + +# If there's no repo found, exit quietly. +if [ -z ${REPO_TO_LINT+x} ]; then + echo "No new link found in the format: https://....#readme" +else + echo "Cloning $REPO_TO_LINT" + mkdir cloned + cd cloned + git clone --depth=1 "$REPO_TO_LINT" . + npx awesome-lint +fi