Here’s a ready to use Github Actions file, that will push your project up to Anvil whenever something is merged into the branch main
or a new release is published.
I’d recommend creating three Secrets in the Github repo for the project: one for the ssh key, one for the anvil host info, and one for the project url at anvil.
The secret ANVIL_HOST
should contain:
[anvil.works]:2222,[52.56.203.177]:2222 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCv1qTximy8Og3MYb8+MGqwtWBorLho9MLgC35oO9Lk445j8GagTor02ucAe+m9Jsk7zfUbRMcjwpjGxMTqdzafnBRfXe0pG5bXpTO274s3TMHGK8Tvl5tt8RLHZXmWmxbYtEQd6gfDffSBtY66p3I0aPNcTNPvM1Ls7QJziiVf8GZ7w0y57vAILNwEaTjXWfdhcxwHEUG/Joamx3LiHRwkiYpO5jkeNn+hGath3lmAoZGC+/DVAo7FFIqsRFWL82FpUZ5g8aOQ7BHZW4vI7RlfEvhBK+FW5wYR5/e8eLBRYAvTbmn25qBo/oSeAA8ZZMdnVb2CQuIm6xv/4isMCpkj
This is the same for everyone, however it could change in the future. You could also find this from looking at .ssh/known_hosts
on a machine you use to push to anvil.
For the public/private key pair, the private key should be saved as a Github secret called ANVIL_SSH_KEY
and the public key should be uploaded to anvil.
Finally, the secret ANVIL_REPO_URL
should be the url anvil provides when you clone the repo. Alternatively this could be found using git remote -v
.
All that’s left is to create the file .github/workflows/main.yml
and paste in the content below.
name: CI
on:
release:
types: [published]
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
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-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/github_actions
- name: Build and deploy
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
git config --global user.name "GitHubActions"
git config --global user.email "actions@github.com"
git remote add anvil "${{ secrets.ANVIL_REPO_URL }}"
git push anvil main:master --force