Skip to content

Commit

Permalink
Check that code owners have write access for the regular review
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Apr 24, 2024
1 parent 1d10641 commit 9028d17
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v26

- uses: actions/checkout@v4
with:
path: repo

- name: Generate issue body
run: repo/scripts/review-body.sh repo ${{ github.repository }} > body
env:
# This token has read-only admin access to see who has write access to this repo
GH_TOKEN: "${{ secrets.OWNERS_VALIDATOR_GITHUB_SECRET }}"

- run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/"$GITHUB_REPOSITORY"/issues \
/repos/${{ github.repository }}/issues \
-f title="[$(date +'%Y %B')] Regular manual review " \
-f body="$(./scripts/review-body.sh)"
-F body=@body
env:
# This token has write access to only issues to create one
GH_TOKEN: ${{ github.token }}
25 changes: 22 additions & 3 deletions scripts/review-body.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/usr/bin/env bash
#!/usr/bin/env nix-shell
#!nix-shell -i bash --pure --keep GH_TOKEN -I nixpkgs=channel:nixpkgs-unstable -p codeowners github-cli gitMinimal

set -euo pipefail

# This script outputs the contents of the regular review issue, see ./github/workflows/review.yml

rev=$(git rev-parse HEAD)
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

if (( $# != 2 )); then
echo "Usage: $0 PATH OWNER/REPO"
exit 1
fi

root=$1
repo=$2

rev=$(git -C "$root" rev-parse HEAD)

echo "Because the documentation in this repository may slowly deviate from reality, this monthly issue is created to regularly review the files.
Expand All @@ -30,4 +42,11 @@ while read -r file users; do
continue
fi
echo "- [ ] \`$file\`: $users"
done < .github/CODEOWNERS
done < "$root"/.github/CODEOWNERS

echo ""

# Check that all code owners have write permissions
# `|| true` because this script fails when there are code owners without permissions,
# which is useful to fail PRs, but not here
bash "$SCRIPT_DIR"/unprivileged-owners.sh "$root" "$repo" || true

0 comments on commit 9028d17

Please sign in to comment.