Skip to content

Commit

Permalink
add workflow to create dependabot pr (#10841)
Browse files Browse the repository at this point in the history
* add workflow to create dependabot pr

This pr adds a workflow to replace the manual work required to commit all the dependabot PRs. The workflow:
- checks out the code
- runs .github/workflows/scripts/dependabot-pr.sh which looks for all dependabot PRs and applies the dependency update
- runs tidy/builds the collector
- commits a change and creates a PR

The workflow is triggered manually and the GITHUB_ACTOR who triggered the workflow is the user used to create the PR.

* Update .github/workflows/scripts/dependabot-pr.sh

Co-authored-by: Tyler Helmuth <[email protected]>

* fix typo

Co-authored-by: Tyler Helmuth <[email protected]>
  • Loading branch information
Alex Boten and TylerHelmuth committed Jun 9, 2022
1 parent 55304f6 commit eac0998
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/create-dependabot-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: dependabot-pr

on:
workflow_dispatch:

jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run dependabot-pr.sh
run: ./.github/workflows/scripts/dependabot-pr.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/scripts/dependabot-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash -ex

git config user.name $GITHUB_ACTOR
git config user.email $GITHUB_ACTOR@users.noreply.github.com

PR_NAME=dependabot-prs/`date +'%Y-%m-%dT%H%M%S'`
git checkout -b $PR_NAME

IFS=$'\n'
requests=$(gh pr list --search "author:app/dependabot" --json number,title --template '{{range .}}{{tablerow .title}}{{end}}')
message=""

for line in $requests; do
if [[ $line != Bump* ]]; then
continue
fi

module=$(echo $line | cut -f 2 -d " ")
if [[ $module == go.opentelemetry.io/collector* ]]; then
continue
fi
version=$(echo $line | cut -f 6 -d " ")
make for-all CMD="$GITHUB_WORKSPACE/internal/buildscripts/update-dep" MODULE=$module VERSION=v$version
message+=$line
message+=$'\n'
done

make gotidy
make otelcontribcol

git add go.sum go.mod
git add "**/go.sum" "**/go.mod"
git commit -m "dependabot updates `date`
$message"
git push origin $PR_NAME

gh pr create --title "dependabot updates `date`" --body "$message" -l "Skip Changelog"
2 changes: 1 addition & 1 deletion internal/buildscripts/update-dep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -x
#!/bin/bash -x

# Updates MODULE inside go.mod if it is already present to version VERSION.

Expand Down

0 comments on commit eac0998

Please sign in to comment.