How to configure autodeploys for more than one branch/heroku app?

I’m trying to set up autodeploys for two different branches / to two different heroku apps for the same codebase.
autodeploys should happen to the staging app from the main branch.
autodeploys should happen to the production app from the production branch.

I’ve read the docs here which are pretty clear for a single app, but what about multiple apps/branches?

Right now I have

version: 2.1

orbs:
  browser-tools: circleci/browser-tools@1.1.3
commands:
...
jobs:
...
deploy:
  machine:
      enabled: true
  working_directory: ~/
  environment:
    HEROKU_APP: $HEROKU_APP_NAME # How do I make this dynamic per branch / app??
  steps:
    - checkout
    - run:
        command: |
          git push staging main # How do I make this dynamic per branch / app??
          heroku run rake db:migrate # How do I make this dynamic per branch / app??
          sleep 5 # sleep for 5 seconds to wait for dynos
          heroku restart

workflows:
  version: 2
  build_lint_and_test:
    jobs:
      - build
      - lint:
          requires:
            - build
      - test:
          requires:
            - build
      - jest:
          requires:
            - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only:
                - main
                - production

How do I make this dynamic for both branches/apps? Is this possible?

I was able to solve this myself:

...
 heroku_deploy_staging:
    executor: heroku/default
    steps:
      - checkout
      - heroku/install
      - heroku/deploy-via-git:
          app-name: $HEROKU_STAGING_APP_NAME

  heroku_deploy_production:
    executor: heroku/default
    steps:
      - checkout
      - heroku/install
      - heroku/deploy-via-git:
          app-name: $HEROKU_PRODUCTION_APP_NAME

workflows:
  version: 2
  build_lint_and_test:
    jobs:
      - build
      - lint:
          requires:
            - build
      - test:
          requires:
            - build
      - jest:
          requires:
            - build
      - heroku_deploy_staging:
          requires:
            - build
            - lint
            - test
            - jest
          filters:
            branches:
              only:
                - main
      - heroku_deploy_production:
          requires:
            - build
            - lint
            - test
            - jest
          filters:
            branches:
              only:
                - production

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