Skip to main content

Continuous integration for Actors

Learn how to integrate your Actors by setting up automated builds, deploys, and testing for your Actors using GitHub Actions or Bitbucket Pipelines.


If you have a project consisting of several Actors, or even one Actor that requires frequent updates, you may want to automate some part of the development process. Instead of manually pushing your code, building each Actor, then testing it, you could perform the whole process whenever you run git push.

You can automate Actor builds and tests using your Git repository's automated workflows like GitHub Actions or Bitbucket Pipelines.

This article will focus on GitHub, but we also have a guide for Bitbucket.

TL;DR

Below is an example GitHub Actions workflow that will run your tests and build your Actor every time you push your code to GitHub. This workflow supports both latest and beta builds. Copy the code into separate files in your Actor repo's .github/workflows directory: e.g. .github/workflows/latest.yml and .github/workflows/beta.yml.

Each time you push to the main/master branch, a new latest version of your Actor will be built. When you push to develop, a beta version will be built.

name: Test and build latest version
on:
push:
branches:
- master
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
# Install dependencies and run tests
- uses: actions/checkout@v2
- run: npm install && npm run test
# Build latest version
- uses: distributhor/workflow-webhook@v1
env:
webhook_url: ${{ secrets.LATEST_BUILD_URL }}
webhook_secret: ${{ secrets.APIFY_TOKEN }}

Find the Bitbucket version here.

Prerequisites

To follow along, you will need a GitHub repository containing your Actor code and your Apify API token.

Find your Apify token in the Apify Console.

Apify token in app

Add the token to GitHub secrets. Go to your repo > Settings > Secrets > New repository secret.

Add the Build Actor API endpoint URL to GitHub secrets. Configure it to use your Actor's ID and your API token.

https://api.apify.com/v2/acts/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=beta&waitForFinish=60

Add build Actor URL to secrets

Set up automatic builds

Once you have your prerequisites, you can start automating your builds. You can use webhooks or the Apify CLI (described in our Bitbucket guide) in your Git workflow.

To use webhooks, you can use the distributhor/workflow-webhook action, which uses the secrets described in the prerequisites section.

name: Build Actor
- uses: distributhor/workflow-webhook@v1
env:
webhook_url: ${{ secrets.[VERSION]_BUILD_URL }}
webhook_secret: ${{ secrets.APIFY_TOKEN }}

You can find your builds under the Actor's Builds section.

An Actor's builds

Automatic builds from GitHub

If the source code of an Actor is hosted in a Git repository, it is possible to set up an integration so that the Actor is automatically rebuilt on every push to the Git repository. For that, you only need to set up a webhook in your Git source control system that will invoke the Build Actor API endpoint on every push.

For repositories on GitHub, you can use the following steps. First, go to the Actor detail page, open the API tab, and copy the Build Actor API endpoint URL. It should look something like this:

https://api.apify.com/v2/acts/apify~hello-world/builds?token=<API_TOKEN>&version=0.1

Then go to your GitHub repository, click Settings, select Webhooks tab and click Add webhook. Paste the API URL to the Payload URL as follows:

GitHub integration

And that's it! Now your Actor should automatically rebuild on every push to the GitHub repository.