Skip to content

Commit

Permalink
Check dependency updates automatically in CI (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide authored Nov 12, 2024
1 parent 917af7e commit 231178d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/check-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash -e

GITHUB_PR_LABEL="dependencies"
COMMIT_TITLE="Update dependencies"

if [ -z "$BRANCH_NAME" ]; then
echo "Branch name is required"
exit 1
fi

function check_pr {
gh pr list --state open --label "$GITHUB_PR_LABEL"
}

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

_update_output="$(TERM=dumb rebar3 update-deps --replace)"

if git diff --exit-code --quiet; then
echo "No changes to the dependencies"
exit 0
else
echo "Detected changes to dependencies"
fi

git checkout -b "$BRANCH_NAME"
git add .

git commit -F- <<EOF
$COMMIT_TITLE
Updates from "rebar3 update-deps --replace":
$_update_output
EOF

git push --set-upstream origin "$BRANCH_NAME"

if [[ $(check_pr) == "" ]]; then
gh pr create \
--label "$GITHUB_PR_LABEL" \
--title "$COMMIT_TITLE" \
--body-file - <<EOF
This PR updates the dependencies to their latest versions.
The following changes were made from \`rebar3 update-deps --replace\`:
\`\`\`
$_update_output
\`\`\`
EOF
fi
43 changes: 43 additions & 0 deletions .github/workflows/check_deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check Dependencies

on:
workflow_dispatch:
schedule:
- cron: '38 8 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-deps:
name: Check Dependencies
runs-on: ubuntu-22.04
strategy:
matrix:
otp_version: ['27.1']

steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp_version }}
rebar3-version: '3.22.1'
version-type: 'strict'

- uses: actions/cache@v4
with:
path: |
~/.cache/rebar3
_build
key: ${{ runner.os }}-erlang-${{ matrix.otp_version }}-${{ hashFiles('**/*rebar.lock') }}

- name: Build
run: make build

- name: Check dependencies
run: .github/workflows/check-deps.sh
env:
BRANCH_NAME: update-deps-${{ github.run_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 231178d

Please sign in to comment.