Skip to content

Instantly share code, notes, and snippets.

@paulo-ferraz-oliveira
Last active December 17, 2023 18:28
Show Gist options
  • Save paulo-ferraz-oliveira/4e9707d68f9c9b1fc972abd8f65cea0a to your computer and use it in GitHub Desktop.
Save paulo-ferraz-oliveira/4e9707d68f9c9b1fc972abd8f65cea0a to your computer and use it in GitHub Desktop.
Schedule your rebar.config version updates with rebar3_depup and GitHub Actions

rebar3_depup-based rebar.config version updates

... on scheduled GitHub Actions.

How to achieve it?

workflow .yml

This is an example scheduled-based workflow to run a .sh at a given time of day.

---
name: Update dependencies

"on":
  schedule:
    - cron: '0 12 * * *'
  workflow_dispatch:

jobs:
  update:
    name: Update dependencies
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: erlef/setup-beam@v1
        with:
          otp-version: 26
          rebar3-version: 3
      - run: ./.github/workflows/rebar3_depup.sh
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

(the GITHUB_TOKEN is required to allow github-actions to open pull requests to your repository)

workflow .sh

This is an example .sh that opens a specific Git branch, updates the deps. (rebar3 alias up) and creates a pull request with changes, if any.

#!/usr/bin/env bash

set -eux

git config user.name "GitHub Actions"
git config user.email "[email protected]"

git fetch origin
BRANCHES=$(git branch -a)
BRANCH=feature/rebar3-depup-updates
if echo "${BRANCHES}" | grep "${BRANCH}" >/dev/null; then
    # exists
    exit
fi

git checkout -b "${BRANCH}"
mkdir -p "${HOME}/.config/rebar3"
echo "{plugins, [rebar3_depup]}." > "${HOME}/.config/rebar3/rebar.config"
rebar3 update-deps --replace
rebar3 upgrade --all

if ! git diff --exit-code 1> /dev/null ; then
    # there's stuff to push
    TITLE="[automation] Update \`rebar.config\` versions (via \`rebar3 depup\`)"

    git add rebar.config
    git add rebar.lock
    git commit -m "${TITLE}"
    git push origin "${BRANCH}"

    gh pr create --fill \
        --title "${TITLE}" \
        --body "This is an automated action to update the repository's \`rebar.config\` versions."
fi

(the commits are signed by GitHub Actions / [email protected], and we're using bleeding edge rebar3_depup)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment