-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (102 loc) · 4.36 KB
/
delete-branches.yaml
File metadata and controls
121 lines (102 loc) · 4.36 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Delete backport labels in plugins
description: |
This workflow deletes backport labels (backport/vault-<version>)
for Vault plugins based on the specified version.
run-name: Delete ${{ inputs.version }} backport labels
on:
workflow_dispatch:
inputs:
version:
description: 'Backport label version to delete with *NO* "v", e.g., 1.19.x'
required: true
type: string
jobs:
delete-labels:
name: Delete backport labels
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.PRATHIC_GH_TOKEN }}
steps:
- name: Checkout current repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
token: ${{ secrets.PRATHIC_GH_TOKEN }}
- name: Validate version
shell: bash
run: |
version="${{ inputs.version }}"
regex='^[0-9]+\.[0-9]+\.([0-9]+|x)([^\ ]+)?$'
if ! [[ "${version}" =~ ${regex} ]]; then
echo "::error::Version '${version}' is invalid, must match the pattern '${regex}'"
exit 1
fi
- name: Configure Git
run: git config --global url."https://${{ secrets.PRATHIC_GH_TOKEN }}:@github.com".insteadOf "https://github.com"
- name: Install yq
run: |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Delete Labels
run: |
plabel="backport/vault-${{ inputs.version }}"
# Initialize arrays to track results
deleted_labels=()
skipped_labels=()
failed_labels=()
# Go through all the plugins from plugins.yaml (lowercase keys)
plugins=$(yq eval 'keys | .[]' plugins.yaml | awk '{print tolower($0)}')
for plugin in $plugins; do
if [[ -z "$plugin" ]]; then
continue
fi
echo "::debug::Processing plugin for label deletion: $plugin"
repo=$(yq eval "to_entries | map(select(.key | downcase == \"$plugin\")) | .[0].value.repository" plugins.yaml)
# If repository is not specified or is null, use the plugin name as fallback
if [[ "$repo" == "null" ]] || [[ -z "$repo" ]]; then
repo="prathic-hashicorp/$plugin"
else
repo="prathic-hashicorp/$repo"
fi
echo "::debug::Deleting label in repository: $repo"
# Check if label exists
if ! gh label list --repo "$repo" --search "$plabel" | grep -q "$plabel"; then
skipped_labels+=("$repo")
else
# Delete the label using gh CLI
if gh label delete "$plabel" --repo "$repo" --yes; then
deleted_labels+=("$repo")
else
echo "::error::Label deletion failed for repository $repo"
failed_labels+=("$repo")
fi
fi
done
# Simple summary report
echo "# Label Deletion Summary for vault-${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Create a simple table
echo "| Repository | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------------|--------|" >> $GITHUB_STEP_SUMMARY
# Get all unique repositories and their status
all_repos=($(printf '%s\n' "${deleted_labels[@]}" "${skipped_labels[@]}" "${failed_labels[@]}" | sort -u))
# Generate table rows
for repo in "${all_repos[@]}"; do
if [[ -n "$repo" ]]; then
if [[ " ${deleted_labels[*]} " =~ " $repo " ]]; then
status="✅ Deleted"
elif [[ " ${skipped_labels[*]} " =~ " $repo " ]]; then
status="⏭️ Not Found"
elif [[ " ${failed_labels[*]} " =~ " $repo " ]]; then
status="❌ Failed"
else
status="❓ Unknown"
fi
echo "| \`$repo\` | $status |" >> $GITHUB_STEP_SUMMARY
fi
done
echo "" >> $GITHUB_STEP_SUMMARY
# Exit with error if there were any failures
if [[ ${#failed_labels[@]} -gt 0 ]]; then
echo "::error::Some label deletion operations failed. Check the summary above."
exit 1
fi