I'm trying to get a GitHub Actions workflow to work with my SvelteKit site but keep running into an error. I am building a website using SvelteKit and SSG and I want to put my built site into a production
branch in the same repo as the source code.
Here is my workflow:
name: Build and Deploy
on:
push:
branches: [ "sveltekit" ]
workflow_dispatch:
permissions:
contents: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: sveltekit
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.17.0
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to production branch
run: |
git worktree add prod-branch production
cp -r build/* /prod-branch/
cd prod-branch
git add .
git commit -m "Deploying build artifacts to production"
git push origin production
This successfully builds the project, and even creates the /prod-branch/
folder, but when it tries to check out the production
branch into the /prod-branch/
folder, it errors out with
fatal: invalid reference: production
Error: Process completed with exit code 128.
This occurs on the "Deploy to production branch" step. The branch has already been created (local and remote) so I'm not sure why this would happen.
Finally got this to work using the following workflow: