Deploying a Repository Inside a GitHub Organization to Vercel Using GitHub Actions

November 26, 2024 (6mo ago)

so vercel is dope but they want you to pay if you're deploying from a github org repo. here's how to get around that paywall:

the idea

we're gonna set up a github action that copies your org repo to your personal github. then vercel can deploy from your personal account for free. functionally identical to direct deployment, just with one additional step in between.

what you need

  • your personal github account
  • a repo in some github org
  • another repo in your personal account

while this solution works great for many cases, make sure you're careful with sensitive data if you're handling any.

the steps

1. make some ssh keys

run this in terminal:

ssh-keygen -t ed25519 -C "$(git config user.email)" -N "" -f github-your-personal-repo

this gives you two files:

  • public key (.pub)
  • private key

2. add private key to source repo

go to your org repo → settings → secrets → actions → new repository secret

name it SSH_DEPLOY_KEY and paste your private key

3. add public key to your personal repo

go to your personal repo → settings → deploy keys → add deploy key

paste your public key and check "allow write access"

4. turn off actions in personal repo

this is important af! go to your personal repo → settings → actions → general → disable actions

5. set up the github action

make a file at .github/workflows/push-to-external-repo.yml in your org repo:

name: push to personal repo
on:
  push:
    branches:
      - main
jobs:
  push-to-external-repo:
    runs-on: ubuntu-latest
    steps:
      - name: checkout repository
        uses: actions/checkout@v3
      - name: push to external repository
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.SSH_DEPLOY_KEY }}
          publish_dir: .
          external_repository: your-username/your-personal-repo
          publish_branch: main
          allow_empty_commit: true

6. test it

push something to your org repo's main branch and watch it show up in your personal repo

7. set up vercel

go to vercel → new project → import git repository → pick your personal repo → deploy

and that's it! you just finessed the #system 💯