Skip to content

Validate Signing on Mac + Linux #65

Validate Signing on Mac + Linux

Validate Signing on Mac + Linux #65

name: Add Branch Lockdown Label to PRs
on:
pull_request_target:
workflow_dispatch: # Allows manual triggering of the workflow
permissions:
actions: write # For managing the operation state cache
issues: write
jobs:
add-label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install jq
run: sudo apt-get install -y jq
- name: Add label to PRs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Determine the third Tuesday of the current month
third_tuesday=$(date -d "$(date +%Y-%m-01) +14 days" +%Y-%m-%d)
while [ $(date -d "$third_tuesday" +%u) -ne 2 ]; do
third_tuesday=$(date -d "$third_tuesday + 1 day" +%Y-%m-%d)
done
# Determine the first Tuesday of the current month
first_tuesday=$(date -d "$(date +%Y-%m-01)" +%Y-%m-%d)
while [ $(date -d "$first_tuesday" +%u) -ne 2 ]; do
first_tuesday=$(date -d "$first_tuesday + 1 day" +%Y-%m-%d)
done
# Get current date
current_date=$(date +%Y-%m-%d)
echo "Current Date: $current_date"
echo "Third Tuesday of the month: $third_tuesday"
echo "First Tuesday of the month: $first_tuesday"
# Check if the current date is after the third Tuesday of this month or before the first Tuesday of this month
if [[ "$current_date" > "$third_tuesday" || "$current_date" < "$first_tuesday" ]]; then
echo "Within the label period. Checking if the branch matches..."
# Get all open PRs targeting branches release/8* and release/9* excluding release/9.0.3xx
echo "Running gh pr list query..."
prs=$(gh pr list --state open --limit 200 --json number,baseRefName,author,labels)
echo "Total PRs Count: $(echo "$prs" | jq length)"
echo "PRs JSON: $prs"
echo "Filtering PRs targeting release/8* and release/9* excluding release/9.0.3xx..."
prs_targeting_branches=$(echo "$prs" | jq '[.[] | select(.baseRefName | test("^release/[89].*")) | select(.baseRefName | test("^release/9.0.3xx") | not)]')
echo "Count of PRs targeting specific branches: $(echo "$prs_targeting_branches" | jq length)"
echo "Filtering PRs without Branch Lockdown label..."
filtered_prs=$(echo "$prs_targeting_branches" | jq '[.[] | select(.labels | map(.name) | index("Branch Lockdown") | not) | .number]')
echo "Filtered PRs without Branch Lockdown label JSON: $filtered_prs"
echo "Count of Filtered PRs without Branch Lockdown label: $(echo "$filtered_prs" | jq length)"
# Loop through filtered PRs and add label
for pr in $(echo "$filtered_prs" | jq -r '.[]'); do
echo "Adding label to PR #$pr"
gh pr edit $pr --add-label "Branch Lockdown"
done
else
echo "Outside the label period. No labels added."
fi