Skip to content

Commit 18c3609

Browse files
committed
add readme, labels
1 parent 55a968d commit 18c3609

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

.github/workflows/example.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
contents: read
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@v4
15-
1613
- name: Download CLI
1714
env:
1815
# To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
result.jsonl

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Example CLI Usage
2+
3+
This repo serves as an example of how to use Dependabot CLI for updates. It is intended as a starting point for advanced users to run a self-hosted version of Dependabot within their own projects.
4+
5+
If you're looking for a hassle-free Dependabot experience, check out the hosted [Dependabot Service](https://docs.github.com/en/github/administering-a-repository/about-dependabot-version-updates).
6+
7+
This repo uses an Action which downloads and runs Dependabot CLI. To run the Action you would go to [the Action in the Actions tab](https://github.com/dependabot/example-cli-usage/actions/workflows/example.yml), and run it.
8+
9+
To see what the results look like, go check out the Pull Requests.
10+
11+
## Implementation details
12+
13+
The Action is defined at [.github/workflows/example.yml](.github/workflows/example.yml).
14+
15+
It contains two jobs, the first downloads and runs Dependabot CLI. The input for the Dependabot CLI job is [.github/dependabot/go.yml](.github/dependabot/go.yml). See the [Dependabot CLI repo](https://github.com/dependabot/cli) for more info on inputs such as credentials and groupings.
16+
17+
The results are redirected to a file and uploaded as artifacts.
18+
19+
The second job downloads the artifact and creates PRs from it using the script [create.sh](create.sh).
20+
21+
The reason there are two jobs is Dependabot CLI should only run with read-only tokens as some ecosystem may execute arbitrary code. To achieve that in Actions we must use two jobs with `permissions` defined differently.
22+
23+
Also take a look at the [Dependabot Smoke Tests repo](https://github.com/dependabot/smoke-tests/tree/main/tests) for example inputs and expected outputs.

create.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jq -c 'select(.type == "create_pull_request")' "$INPUT" | while read -r event; d
2626
PR_TITLE=$(echo "$event" | jq -r '.data."pr-title"')
2727
PR_BODY=$(echo "$event" | jq -r '.data."pr-body"')
2828
COMMIT_MSG=$(echo "$event" | jq -r '.data."commit-message"')
29-
BRANCH_NAME="dependabot/$(echo "$PR_TITLE" | tr ' /' '__' | tr -cd '[:alnum:]_-')"
29+
BRANCH_NAME="dependabot-$(echo -n "$COMMIT_MSG" | sha1sum | awk '{print $1}')"
3030

3131
echo "Processing PR: $PR_TITLE"
3232
echo " Base SHA: $BASE_SHA"
@@ -55,7 +55,7 @@ jq -c 'select(.type == "create_pull_request")' "$INPUT" | while read -r event; d
5555
git push origin "$BRANCH_NAME"
5656

5757
# Create PR using gh CLI
58-
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head "$BRANCH_NAME" || true
58+
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head "$BRANCH_NAME" --label dependencies || true
5959

6060
# Return to main branch for next PR
6161
git checkout main

0 commit comments

Comments
 (0)