Edit

Continuous integration for actors

Learn how to set 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 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

You will need an actor, a GitHub repo for it, and your Apify 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

Automate tests

Depending on your needs, you can test your actors on push to Git (using frameworks like Jest or Mocha) or set up ongoing monitoring of your actors' performance.

Run tests on push to Git

See our Bitbucket guide for an outline of running tests in a Git workflow. It works the same for GitHub and Bitbucket.

In brief, you need to write your tests using your tool of choice, add a script that executes the tests to the package.json file, and add the command to your Git workflow.

# Install dependencies and run tests
- uses: actions/checkout@v2
- run: npm install && npm run test

Monitoring

For most ongoing monitoring scenarios, we recommend using the Apify monitoring suite. It allows you to check your actor's run statuses, validate your results, and receive notifications via email or Slack.

Check out our text and video tutorials for various monitoring use cases.

Ongoing testing

If you have advanced and specific requirements, you can create your own test actors, which you can schedule to regularly run and validate your actors' results. For this, you can use our Actor Testing (pocesar/actor-testing) actor (see the guide).

If using this approach, you can set up notifications using the Send Mail (apify/send-mail) and Send Slack Message (katerinahronik/slack-message) actors.