-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (67 loc) · 2.42 KB
/
label-simple.yml
File metadata and controls
84 lines (67 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Simple labeler workflow that doesn't require label creation permissions
name: Simple Labeler
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
- name: Apply labels based on changed files
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
echo "Analyzing changed files in PR #${{ github.event.number }}"
git fetch origin "${{ github.base_ref }}" --depth=1
git diff --name-only "origin/${{ github.base_ref }}"...HEAD > changed_files.txt
echo "Changed files:"
cat changed_files.txt
echo ""
add_label() {
local label="$1"
echo "Attempting to add label: $label"
gh pr edit ${{ github.event.number }} --add-label "$label" 2>/dev/null && \
echo "Added label: $label" || \
echo "Could not add label '$label' (may not exist in repository)"
}
if grep -E '\.(md|txt)$|README|SECURITY|LICENSE' changed_files.txt; then
add_label "documentation"
fi
if grep -E '^(main\.go|cmd/|policies/|sql/)' changed_files.txt; then
add_label "cli"
fi
if grep -E '^ansible/' changed_files.txt; then
add_label "ansible"
fi
if grep -E '^scripts/|install\.|setupGo\.sh|uninstall\.sh' changed_files.txt; then
add_label "scripts"
fi
if grep -E '^pkg/(container|docker)/' changed_files.txt; then
add_label "pkg-container"
fi
if grep -E '^pkg/vault/' changed_files.txt; then
add_label "pkg-vault"
fi
if grep -E '^pkg/crypto/' changed_files.txt; then
add_label "pkg-crypto"
fi
if grep -E '^\.github/' changed_files.txt; then
add_label "ci"
fi
if grep -E '^(go\.(mod|sum)|Dockerfile|docker-compose\.yml)$' changed_files.txt; then
add_label "dependencies"
fi
if grep -E '^pkg/' changed_files.txt; then
add_label "pkg-other"
fi
echo ""
echo "Labeling complete!"
rm -f changed_files.txt