From 10fce91913d5a57ae442a5316b2c5feab37aead1 Mon Sep 17 00:00:00 2001 From: Jon Church Date: Thu, 11 Jul 2024 19:36:52 -0400 Subject: [PATCH 1/2] create a GHA to run update and open a PR if diff --- .github/workflows/generate.yml | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/generate.yml diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml new file mode 100644 index 000000000..de9a8cebf --- /dev/null +++ b/.github/workflows/generate.yml @@ -0,0 +1,58 @@ +name: Update and Create PR + +on: + schedule: + - cron: '0 0 1 * *' # Runs on the first day of each month at midnight + workflow_dispatch: # Allows the workflow to be triggered manually + +jobs: + update-and-pr: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository ๐Ÿ›Ž๏ธ + uses: actions/checkout@v2 + + - name: Set up Node.js ๐Ÿ› ๏ธ + uses: actions/setup-node@v2 + with: + node-version: 'lts/*' # Use the LTS version of Node.js + + - name: Install dependencies ๐Ÿ“ฆ + run: npm install + + - name: Run update script ๐Ÿ”„ + run: npm run update + + - name: Check for changes and create branch ๐Ÿ“ค + id: check_changes + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + if [ -n "$(git status --porcelain)" ]; then + BRANCH_NAME="update-branch" + if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then + TIMESTAMP=$(date +%s) + BRANCH_NAME="${BRANCH_NAME}-${TIMESTAMP}" + fi + git checkout -b $BRANCH_NAME + git add . + git commit -m "Automated update" + git push --set-upstream origin $BRANCH_NAME + echo "::set-output name=changes_detected::true" + echo "::set-output name=branch::$BRANCH_NAME" + else + echo "No changes detected." + echo "::set-output name=changes_detected::false" + echo "::set-output name=branch::" + + - name: Create Pull Request ๐Ÿš€ + if: steps.check_changes.outputs.changes_detected == 'true' + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ steps.check_changes.outputs.branch }} + title: "๐Ÿค–Automated update" + body: "This PR contains automated updates from running `npm run update`" + labels: ["automated update"] + From 405d86278eef1bbf6be7b9fbc60dbcc5b9d70ceb Mon Sep 17 00:00:00 2001 From: Jon Church Date: Thu, 11 Jul 2024 19:56:58 -0400 Subject: [PATCH 2/2] limit the git add to just db.json and src/ --- .github/workflows/generate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index de9a8cebf..e9278236d 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -36,7 +36,7 @@ jobs: BRANCH_NAME="${BRANCH_NAME}-${TIMESTAMP}" fi git checkout -b $BRANCH_NAME - git add . + git add db.json src/ git commit -m "Automated update" git push --set-upstream origin $BRANCH_NAME echo "::set-output name=changes_detected::true"