Skip to main content
Skip table of contents

GitHub Workflows

New Golive GitHub Actions are now available make this integration easier to implement.

This page shows an example of integration between Golive Cloud and GitHub Workflow.

To be able to push information, here deployments, you’ll need:

  • an API token generated by a user that has the required permission

  • an environment set up in Golive

  • an existing github workflow

To illustrate, we’ll use the Workflow of our Golive Monitor product as example.

The existing Workflow builds a docker image and pushes it to the Docker hub (Golive monitor).

At the end of the Workflow, we want to add a deployment to the corresponding environment on Golive:

Golive Token

First we create a Golive token:

Then “Generate a new token”, copy the token and close.

Github Secret

The token needs to be added as a secret on your GitHub repository in order to be used in the Workflow:

In Actions, click on “new repository secret” (top right of the screen), add the key in the field named secret.

The chosen name will be used to retrieve the secret in the yaml workflow file.

Adding the Golive update step in the Workflow

In the Github Workflow file that describes the build we add the following snippet as the last step of the build:

YAML
      - name: Push new deployment to Golive
        uses: fjogeleit/http-request-action@v1
        with:
            url: 'https://golive.apwide.net/api/deployment?environmentId=61'
            method: 'PUT'
            bearerToken: ${{ secrets.GOLIVE_TOKEN }}
            customHeaders: '{"Content-Type": "application/json"}'
            data: '{
                "versionName": "${{ env.today }}-${{ steps.commit.outputs.short }}",
                "description": "Github Workflow automated release\n\n
                    ➙ https://hub.docker.com/repository/docker/apwide/golive-monitor/general\n\n
                    ➙ https://github.com/apwide/golive-monitor/commit/${{steps.commit.outputs.short}}"
            }'

We use the fjogeleit/http-request-action action to perform our call the Golive API.

Line 4, the environment id (61) is hard-coded, this could also be a variable in the code or in the repository.

The token is added on line 6 with the ${{ secrets.GOLIVE_TOKEN }}.

In our example, line 8, we use a release version name that looks like 2023-02-01-2323gfj. We add a description that acts like some sort of signature. The result can be seen in the image at the top of this page.

The full Workflow script

This script is available in the Golive Monitor repository. This needs to be in .github/workflows.

YAML
name: build docker image

on:
  push:
    branches:
      - main

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - id: commit
        uses: pr-mpt/actions-commit-hash@v2
      - id: date
        run: |
            echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: apwide/golive-monitor:latest,apwide/golive-monitor:${{ env.today }}-${{ steps.commit.outputs.short }}
      - name: Push new deployment to Golive
        uses: fjogeleit/http-request-action@v1
        with:
            url: 'https://golive.apwide.net/api/deployment?environmentId=61'
            method: 'PUT'
            bearerToken: ${{ secrets.GOLIVE_TOKEN }}
            customHeaders: '{"Content-Type": "application/json"}'
            data: '{
                "versionName": "${{ env.today }}-${{ steps.commit.outputs.short }}",
                "description": "Github Workflow automated release\n\n
                    ➙ https://hub.docker.com/repository/docker/apwide/golive-monitor/general\n\n
                    ➙ https://github.com/apwide/golive-monitor/commit/${{steps.commit.outputs.short}}"
            }'

Only lines 30 to 37 are specific to Golive, the rest is just preparing for the build.

We use the combination of the date and the short commit hash to build our version name.

  1. Checkout (12-13)

  2. Retrieve commit hash (14-15)

  3. Build a date string and add it the env (16-18)

  4. Build the docker image and upload it (24-29)

  5. Pushing the deployment to Golive (30-37)

Troubleshooting

If the final action fails check the action tab in Github to read the output of the command. It might give a hint on what is not working.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.