Skip to content

[Maintenance] Set assignees and reviewers #12

[Maintenance] Set assignees and reviewers

[Maintenance] Set assignees and reviewers #12

name: "[Maintenance] Set assignees and reviewers"
on:
workflow_dispatch:
env:
AUTH_USER: "bot-anik"
jobs:
check-permissions:
runs-on: ubuntu-22.04
steps:
- name: Not authorized
if: ${{ github.event_name == 'workflow_dispatch' && github.actor != env.AUTH_USER }}
run: |
echo "Error: Only $AUTH_USER can trigger this workflow."
exit 1
set-assignees-reviewers:
runs-on: ubuntu-22.04
needs:
- check-permissions
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ secrets.OKP4_TOKEN }}
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.OKP4_BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OKP4_BOT_GPG_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Set assignees and reviewers
env:
ORG: okp4
REPO_FILTER: --visibility=public --source
BRANCH_NAME: ci/update-dependabot-assignees-reviewers
DEPENDABOT_FILE: .github/dependabot.yml
DEPENDABOT_REVIEWERS: amimart ccamel
DEPENDABOT_ASSIGNEES: amimart ccamel
PR_REVIEWERS: amimart ccamel
PR_ASSIGNEES: amimart ccamel
COMMIT_MESSAGE: "ci(dependabot): update assignees and reviewers"
GH_TOKEN: ${{ secrets.OKP4_TOKEN }}
run: |
mkdir -p temp
cd temp
repos=$(gh repo list $ORG $REPO_FILTER --json nameWithOwner --jq '.[].nameWithOwner' | sort)
for repo in $repos; do
existing_pr=$(gh pr list --repo "$repo" --head "$BRANCH_NAME" --state open --json number --jq '.[].number')
if [[ -n $existing_pr ]]; then
echo "πŸ™… Existing pull request found for branch $BRANCH_NAME (#$existing_pr)."
continue
fi
echo "⬇️ Cloning $repo..."
git clone https://${AUTH_USER}:${GH_TOKEN}@github.com/${repo}.git --depth 1
repo_name=$(basename "$repo")
cd "$repo_name" || { echo "❌ Failed to enter $repo_name"; continue; }
if [[ ! -f "$DEPENDABOT_FILE" ]]; then
echo "πŸ™… No Dependabot config found in $repo. Skipping..."
continue
fi
echo "βœ… Dependabot config found. Checking for necessary changes..."
yq e "(.updates[] | select(has(\"reviewers\")).reviewers) = [\"$(echo $DEPENDABOT_REVIEWERS | sed 's/ /\",\"/g')\"]" -i "$DEPENDABOT_FILE"
yq e "(.updates[] | select(has(\"assignees\")).assignees) = [\"$(echo $DEPENDABOT_ASSIGNEES | sed 's/ /\",\"/g')\"]" -i "$DEPENDABOT_FILE"
if [[ ! -n $(git status -s) ]]; then
echo "β˜‘οΈ No changes required in Dependabot configuration. Skipping..."
continue
fi
echo "βœ… Changes detected. Updating Dependabot configuration..."
echo "β”‚"
echo "β”œβ”€β”€ Checking out $BRANCH_NAME..."
git checkout -b "$BRANCH_NAME"
echo "β”‚"
echo "β”œβ”€β”€ Committing changes..."
git add "$DEPENDABOT_FILE"
git commit -S -m "$COMMIT_MESSAGE"
echo "β”‚"
echo "└── Pushing changes..."
git push --set-upstream origin "$BRANCH_NAME"
echo "πŸ”€ Creating pull request..."
gh pr create \
--title "Update Dependabot assignees and reviewers" \
--body "This PR updates the Dependabot configuration to specify new mainteners." \
--reviewer "$(echo $PR_REVIEWERS | sed 's/ /,/g')" \
--assignee "$(echo $PR_ASSIGNEES | sed 's/ /,/g')" \
--head $(git branch --show-current)
echo "πŸŽ‰ Done!"
cd ..
rm -rf "$repo_name"
done