GitHub Actions

Begin makes it easy to deploy from CI by providing integration with GitHub Actions.

Let’s work through an example of how you could use the action in your GitHub workflow. In this example, we’ll assume that you’ve already created your Begin app and two environments — one named staging and, and another, production.

Retrieve your Begin authentication token

Open your Begin configuration file (which is generated when you log in):

~/.begin/config.json
C:\Users\yourusername\begin\config.json

Copy the value of access_token in this file (without the quotes, of course).

Create a BEGIN_TOKEN secret on Github

  1. On GitHub, navigate to the main page of your app’s repository.
  2. Under your repository name, click Settings.
  3. In the Security section of the sidebar, select Secrets, then click Actions.
  4. Click New repository secret.
  5. Type BEGIN_TOKEN as the name for your secret in the Name input field.
  6. Enter the value of your access_token for the Secret input field.
  7. Click Add secret.

If you’ll be deploying multiple apps in the same GitHub organization, your respositories can share the same BEGIN_TOKEN via Organization Secrets.

To prevent security risks, never check your access_token in to source code control!

Example GitHub Actions

You can automatically deploy your code to Begin via GitHub Actions by creating a .github/workflows/deploy.yml file in your app’s repository. Below you can see two examples of how to deploy using tag based or branch based deployments.

Tag based deployment

Our recommended approach is to do tag based deployment. When this GitHub Action is installed, all commits to the main branch will be deployed to your staging environment. When a new tag is created on the repo, this will trigger a deploy to production.

name: Begin deploy

on: [ push, pull_request ]

defaults:
  run:
    shell: bash

jobs:
  # Deploy the build
  deploy:
    runs-on: ubuntu-latest
    if: github.event_name == 'push'

    steps:
      - name: Check out repo
        uses: actions/checkout@v3

      - name: Deploy to staging
        if: github.ref == 'refs/heads/main'
        uses: beginner-corp/actions/deploy@main
        with:
          begin_token: ${{ secrets.BEGIN_TOKEN }}
          begin_env_name: staging

      - name: Deploy to production
        if: startsWith(github.ref, 'refs/tags/v')
        uses: beginner-corp/actions/deploy@main
        with:
          begin_token: ${{ secrets.BEGIN_TOKEN }}
          begin_env_name: production

Branch based deployment

An alternative approach is to do branch based deployment. When this GitHub Action is installed, all commits to the main branch will be deployed to your staging environment. Commits to the production branch will be deployed to your production environment.

Feel free to adjust branch names as required.

name: Begin deploy

on: [ push, pull_request ]

defaults:
  run:
    shell: bash

jobs:
  # Deploy the build
  deploy:
    runs-on: ubuntu-latest
    if: github.event_name == 'push'

    steps:
      - name: Check out repo
        uses: actions/checkout@v3

      - name: Deploy to staging
        if: github.ref == 'refs/heads/main'
        uses: beginner-corp/actions/deploy@main
        with:
          begin_token: ${{ secrets.BEGIN_TOKEN }}
          begin_env_name: staging

      - name: Deploy to production
        if: github.ref == 'refs/heads/production'
        uses: beginner-corp/actions/deploy@main
        with:
          begin_token: ${{ secrets.BEGIN_TOKEN }}
          begin_env_name: production