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
Begin Deploy’s CLI provides the tokens list
command to retrieve your authentication token. Run the following command in your terminal:
npx begin tokens list --display
npx begin tokens list --display
Copy your “client token”.
Create a BEGIN_TOKEN secret on Github
- On GitHub, navigate to the main page of your app’s repository.
- Under your repository name, click Settings.
- In the Security section of the sidebar, select Secrets, then click Actions.
- Click New repository secret.
- Type
BEGIN_TOKEN
as the name for your secret in the Name input field. - Enter the value of your
access_token
for the Secret input field. - Click Add secret.
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@v4
- name: Deploy to staging
if: github.ref == 'refs/heads/main'
uses: beginner-corp/actions/deploy@v1
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@v1
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@v4
- name: Deploy to staging
if: github.ref == 'refs/heads/main'
uses: beginner-corp/actions/deploy@v1
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@v1
with:
begin_token: ${{ secrets.BEGIN_TOKEN }}
begin_env_name: production