Skip to content

Commit

Permalink
Try automating updates to default blocklist
Browse files Browse the repository at this point in the history
  • Loading branch information
g-andrade committed Oct 14, 2023
1 parent 039fc7e commit d681d1a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/default-blocklist-updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -eux

git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"

BASE_BRANCH=main
git fetch origin
git checkout "${BASE_BRANCH}"
git reset --hard "origin/${BASE_BRANCH}"
git clean -ffdx

./blocklist/update.exs
if [[ -z $(git status -s) ]]; then
# no update
exit
fi

DATE=$(date -r tmp/cacerts.pem '+%Y/%m/%d') # linux-specific
BLOCKLIST_REF=$(pushd deps/sqids_blocklist && git rev-parse --short HEAD)
NEW_BRANCH=automation/default-blocklist-update/$BLOCKLIST_REF
if git branch -a | grep "${NEW_BRANCH}" >/dev/null; then
# branch already created
exit
fi

REMOTE=origin
PR_TITLE="Update default blocklist to $BLOCKLIST_REF"
git checkout -b "$BRANCH"
git add .
git commit -a -m "${PR_TITLE}"
git push "$REMOTE" "$BRANCH"

PR_LABEL="default-blocklist-update"
if ! gh pr list --state open --label "$PR_LABEL" | grep "${PR_TITLE}" >/dev/null; then
gh pr create --fill \
--title "${PR_TITLE}" \
--label "${PR_LABEL}" \
--reviewer "g-andrade"
fi
38 changes: 38 additions & 0 deletions .github/workflows/default-blocklist-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Check for updates to default blocklist

on:
schedule:
- cron: '23 10 * * 1-5'

workflow_dispatch: # enables "click to run" button

env:
ELIXIR_VERSION: 1.15

jobs:
blocklist_update:
name: Check for updates to the default blocklist
runs-on: ubuntu-latest
steps:
- id: elixir-version-to-otp-version
name: "Read %{Elixir version => OTP version} map"
uses: juliangruber/read-file-action@v1
with:
path: ./.github/workflows/elixir_version_to_otp_version.json

- id: setup-beam
name: Setup BEAM
uses: erlef/setup-beam@v1
with:
# otp-version: https://stackoverflow.com/a/64405821
otp-version: |
${{ fromJson(steps.elixir-version-to-otp-version.outputs.content)[env.ELIXIR_VERSION] }}
elixir-version: ${{env.ELIXIR_VERSION}}
env:
GITHUB_TOKEN: ${{github.token}}

- run: |
.github/workflows/default-blocklist-updater.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit d681d1a

Please sign in to comment.