Skip to content

outdated-dependencies #481

outdated-dependencies

outdated-dependencies #481

Workflow file for this run

name: Create Pull Requests for Dependency Updates
on:
repository_dispatch:
types:
- outdated-dependencies
jobs:
create_prs:
runs-on: ubuntu-latest
if: github.event.client_payload.has_outdated_dependencies == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Fetch all branches
run: git fetch --no-tags --prune --depth=1 origin '+refs/heads/*:refs/remotes/origin/*'
- name: Get list of outdated dependency branches
id: get_branches
run: |
branches=$(git branch --remote --list 'origin/update-*' | sed 's/origin\///')
branches="${branches//$'\n'/,}"
echo "::set-output name=branches::$branches"
- name: Create Pull Requests
run: |
branches="${{ steps.get_branches.outputs.branches }}"
IFS=',' read -ra branch_list <<< "$branches"
for branch in "${branch_list[@]}"; do
branch=$(echo "$branch" | xargs) # Trim the spaces
echo "Checking for existing PR for branch: $branch"
pr_title=$(echo $branch | sed 's/update-\(.*\)-\(.*\)/DependAware: update \1 to \2/')
pr_body=$(echo $branch | sed 's/update-\(.*\)-\(.*\)/This PR updates version \1 to version \2/')
existing_pr=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:$branch" | jq --arg title "$pr_title" '.[] | select(.title==$title)')
if [ -z "$existing_pr" ]; then
echo "Creating PR for branch: $branch"
gh pr create --repo ${{ github.repository }} --base main --head $branch --title "$pr_title" --body "$pr_body" --label "dependencies"
else
echo "PR already exists for branch: $branch"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}