Github Integration

Deployment depending on the status of CI

This section will show you how to configure your deployment.yml to take into account the status of your continuous integration step. We have a code example here for an elixir app, if you wish to skip to reading the source.

A note on INSTELLAR_ENDPOINT

The examples in the codebase we referenced the .github/workflows/deployment.yml file will contain a value for INSTELLAR_ENDPOINT this is only necessary in those repositories since they’re deploying to our staging environment. For our customers we recommend omitting this value.

Conditional deployments are useful for cases where you have a continuous integration step that runs your tests, linting or any other checks. If these checks pass then do the deployment. If this is something you want to have as your build pipeline then this page is for you.

We will not cover how the CI step is written because we believe that will be different for every project. Regardless of how the CI step is the following instruction should be the same.

Changes to the Event

When we’re deploying based on the CI workflow we need to make our on clause aware of the CI step. Feel free to customize the branches as you see fit.

on:
  workflow_run: 
    workflows: ["CI"]
    branches: [master, develop]
    types: 
      - completed

Job Definition

Let’s take a look at our job definition. You’ll see we’ve introduced an if condition that depends on the workflow_run’s conclusion. The build_and_deploy will only run of the conclusion turns out to be a success

jobs:
  build_and_deploy:
    name: Build and Deploy
    runs-on: ubuntu-20.04
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:

The rest of the steps should be mostly the same

      - name: 'Checkout'
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.workflow_run.head_branch }}
          fetch-depth: 0

      - name: 'Pakman'
        uses: upmaru/[email protected]
        with:
          command: 'bootstrap'
        env:
          ABUILD_PRIVATE_KEY: ${{secrets.ABUILD_PRIVATE_KEY}}
          ABUILD_PUBLIC_KEY: ${{secrets.ABUILD_PUBLIC_KEY}}

      - name: 'Build APK'
        uses: upmaru/[email protected]
        with:
          entrypoint: /var/lib/pakman/bin/build.sh

      - name: 'Archive'
        uses: upmaru/[email protected]
        with:
          entrypoint: /var/lib/pakman/bin/archive.sh

      - name: 'Create Deployment'
        uses: upmaru/[email protected]
        with:
          command: 'create_deployment'
          archive: 'packages.zip'
        env:
          WORKFLOW_REF: ${{ github.event.workflow_run.head_branch }}
          WORKFLOW_SHA: ${{ github.event.workflow_run.head_sha }}
          INSTELLAR_PACKAGE_TOKEN: ${{secrets.INSTELLAR_PACKAGE_TOKEN}}
          INSTELLAR_AUTH_TOKEN: ${{secrets.INSTELLAR_AUTH_TOKEN}}

If you look closely you’ll see that the WORKFLOW_REF and WORKFLOW_SHA is slightly different than before. We are now referencing the values from the workflow_run.

Putting it Together

The final file looks something like this.

name: 'Deployment'

on:
  workflow_run: 
    workflows: ["CI"]
    branches: [master, develop]
    types: 
      - completed

jobs:
  build_and_deploy:
    name: Build and Deploy
    runs-on: ubuntu-20.04
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - name: 'Checkout'
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.workflow_run.head_branch }}
          fetch-depth: 0

      - name: 'Pakman'
        uses: upmaru/[email protected]
        with:
          command: 'bootstrap'
        env:
          ABUILD_PRIVATE_KEY: ${{secrets.ABUILD_PRIVATE_KEY}}
          ABUILD_PUBLIC_KEY: ${{secrets.ABUILD_PUBLIC_KEY}}

      - name: 'Build APK'
        uses: upmaru/[email protected]
        with:
          entrypoint: /var/lib/pakman/bin/build.sh

      - name: 'Archive'
        uses: upmaru/[email protected]
        with:
          entrypoint: /var/lib/pakman/bin/archive.sh

      - name: 'Create Deployment'
        uses: upmaru/[email protected]
        with:
          command: 'create_deployment'
          archive: 'packages.zip'
        env:
          WORKFLOW_REF: ${{ github.event.workflow_run.head_branch }}
          WORKFLOW_SHA: ${{ github.event.workflow_run.head_sha }}
          INSTELLAR_PACKAGE_TOKEN: ${{secrets.INSTELLAR_PACKAGE_TOKEN}}
          INSTELLAR_AUTH_TOKEN: ${{secrets.INSTELLAR_AUTH_TOKEN}}

If you have further suggestions on how we can make this better please don't hesitate to open an issue. Or reach out to us via one of our support channels. If you need a quick support and would like to chat you can join our slack group.