GitHub Actions

Begin makes it easier 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 will assume that you have already created your Begin app and two environments named staging and production.

Retrieve your Begin authentication token

Open:

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

and copy the value of access_token (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 will be deploying multiple apps in the same GitHub organization your respositories can share the same BEGIN_TOKEN via Organization Secrets.

Never check in your access_token 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 that 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