Push build folder from dev to main branch

Hi there,

The situation:
I have a simple gatsby-project with some headless CMS features.
Now I pushed my local directory to my github repo in a branch called ‘dev’ (contains config.yml /src package.json etc.)

Goal:
I want to use circleCI to build the code and than push the builded code (static files) to the main branch in a folder called “public” so it can be deployed to my clients “self-hosted” hoster using cPanel"

Problem:
I get the code to build but i have no clue where this build lives now.

Question
So, how can i instruct circleCI to:
build into a “public” folder and then push “public” from dev branch to main branch

A lot of thanks in advance,

Here is my attempt:

version: 2.1

jobs:
  build:
    executor: node/default
    steps:
      - checkout
      - node/install-packages:
          cache-path: ~/project/node_modules
          override-ci-command: npm install
      - run: npm run build
  push:
    machine: true
    steps:
      - checkout
      - add_ssh_keys:
          fingerprints:
            - "<my_fingerprint>"
      - run:
          name: Commit to GitHub
          command: |
            git config user.email "<my_email>"
            git config user.name "<my_username>"
            git commit --allow-empty -am "Automatic commit from CircleCI [skip ci]"
            git push origin main

orbs:
  node: circleci/node@4.0.0

workflows:
  build-and-deploy:
    jobs:
      - build
      - push

Got it, this did the job:

version: 2.1

jobs:
  build:
    executor: node/default
    steps:
      - checkout
      - node/install-packages:
          cache-path: ~/project/node_modules
          override-ci-command: npm install
      - run: npm run build
      - store_artifacts:
          path: public/
      - add_ssh_keys:
          fingerprints:
            - "<my_fingerprint>"
      - run:
          name: Push to GitHub
          command: |
            git config user.email "<my_email>"
            git config user.name "<my_username>"
            git checkout -f main
            git add public/*
            git commit --allow-empty -m "Automatic commit from CircleCI [skip ci]"
            git push -u origin main

orbs:
  node: circleci/node@3.0.0

workflows:
  build-and-deploy:
    jobs:
      - build

Thank you @bart-kipping for providing a solution!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.