Merge rust-bitcoin/rust-bitcoin#2365: Add automated labeler job

c6c5f07880 Add automated labeler job (Martin Habovstiak)

Pull request description:

  Rather than modifying the labels manually, which we often forget, we can label the PRs automatically. This will make it easier to search PRs.

ACKs for top commit:
  apoelstra:
    ACK c6c5f07880
  tcharding:
    ACK c6c5f07880

Tree-SHA512: d3f7ca8c69cc8734d914f871675568ca293e28c3dc7351ee54b9237645204b87d1b47db02863b27d930900ae4b41d6f169f130ed9f4c750d4afbb765921cfb66
This commit is contained in:
Andrew Poelstra 2024-01-22 15:02:08 +00:00
commit 8b9c2ae9cc
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 78 additions and 0 deletions

13
.github/labeler.yml vendored Normal file
View File

@ -0,0 +1,13 @@
ci:
- changed-files:
- any-glob-to-any-file: .github/**
test:
- changed-files:
- any-glob-to-any-file: fuzz/**
- any-glob-to-any-file: '*/tests/**'
- any-glob-to-any-file: 'dep_test'
- any-glob-to-any-file: 'contrib/test.sh'
- any-glob-to-any-file: '*/contrib/test.sh'
doc:
- changed-files:
- any-glob-to-any-file: '**/*.md'

26
.github/workflows/manage-pr.yml vendored Normal file
View File

@ -0,0 +1,26 @@
name: Manage PR
on:
- pull_request_target
jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v4
with:
path: master
- name: Checkout merge commit
uses: actions/checkout@v4
with:
path: merge
ref: "refs/pull/${{ github.event.number }}/merge"
- name: Generate label config
run: cd master && SCAN_DIR=../merge ./contrib/gen_label_config.sh
- name: Update labels
uses: actions/labeler@v5
with:
configuration-path: master/.github/labeler.yml

39
contrib/gen_label_config.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
set -e
# Generates the label configuration using crates in the repository.
# The label configuration is appended to the labeler config file.
config=.github/labeler.yml
if [ -n "$SCAN_DIR" ];
then
scan_dir="$SCAN_DIR"
else
scan_dir=.
fi
if [ "$1" '!=' "--force" ] && ! git diff --exit-code "$config";
then
echo "Error: $config is not committed."
echo "Refusing to overwrite it to prevent disaster."
echo "Run the script with --force to override this."
exit 1
fi
excluded_crates="fuzz|dep_test"
CRATES="`cd "$scan_dir" && cargo metadata --no-deps --format-version 1 | jq -j -r '.packages | map(.manifest_path | rtrimstr("/Cargo.toml") | ltrimstr("'$PWD'/")) | join(" ")'`"
for crate in $CRATES;
do
if echo "$crate" | grep -qE "$excluded_crates";
then
continue
fi
echo "C-$crate:" >> "$config"
echo " - changed-files:" >> "$config"
echo " - any-glob-to-any-file: $crate/**" >> "$config"
done