Two Way Sync between GitHub and Anvil

Building on the work of @james.campbell Github Action for automatically pushing to Anvil

(side note: Are you related to Owen?)

I created a GitHub action that merges the master branch from Anvil to GitHub every hour. This, combined with the GitHub-to-Anvil Action allows me to have two-way sync. I still need a local repo to sort out merge conflicts but that won’t happen too often.

This Action uses the same secrets you’d set up for the other Action. I happened to use the same SSH key for Anvil and GitHub (ANVIL_SSH_KEY) but you should probably use different keys and add a few lines to this.

This and the other GitHub Action run in less than a minute so you’ll be ok with the free GitHub plan.

name: merge_from_anvil

on:
  workflow_dispatch:
  schedule:
    - cron: '0 * * * *' # This schedule is set to run every hour.

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Add SSH config
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          mkdir -p /home/runner/.ssh
          echo "${{ secrets.ANVIL_HOST }}" > /home/runner/.ssh/known_hosts
          echo "${{ secrets.ANVIL_SSH_KEY }}" > /home/runner/.ssh/github_actions
          chmod 600 /home/runner/.ssh/github_actions
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          ssh-agent -a $SSH_AUTH_SOCK > /dev/null
          ssh-add /home/runner/.ssh/github_actions
          git config --global user.name "GitHubActions"
          git config --global user.email "actions@github.com"
          git remote add anvil "${{ secrets.ANVIL_REPO_URL }}"
      - name: Merge from ANVIL HOST master
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          git fetch anvil
          git checkout master
          git merge anvil/master
          git push git@github.com:user/repo.git
5 Likes

Very nice!

…and yes, Owen is my Dad! :smiley:

4 Likes