Continuous integration for Actors
Learn how to set up automated builds, deploys, and testing for your Actors using GitHub Actions or Bitbucket Pipelines.
Automating your Actor development process can save time and reduce errors, especially for projects with multiple Actors or frequent updates. Instead of manually pushing code, building Actors, and running tests, you can automate these steps to run whenever you push code to your repository.
You can automate Actor builds and tests using your Git repository's automated workflows like GitHub Actions or Bitbucket Pipelines.
This article focuses on GitHub, but we also have a guide for Bitbucket.
Set up automated builds and tests
To set up automated builds and tests for your Actors you need to:
-
Create a GitHub repository for your Actor code.
-
Get your Apify API token from the Apify Console
-
Add your Apify token to GitHub secrets
- Go to your repo > Settings > Secrets > New repository secret
- Name the secret & paste in your token
-
Add the Builds Actor API endpoint URL to GitHub secrets
-
Use this format:
https://api.apify.com/v2/acts/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=beta&waitForFinish=60
-
Name the secret
-
-
Create GitHub Actions workflow files:
- In your repo, create the
.github/workflows
directory - Add
latest.yml
andbeta.yml
files with the following content
- latest.yml
- beta.yml
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 }}With this setup, pushing to the
main
ormaster
branch builds a new latest version.name: Test and build beta version
on:
push:
branches:
- develop
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.BETA_BUILD_URL }}
webhook_secret: ${{ secrets.APIFY_TOKEN }}With this setup, pushing to the
develop
branch builds a new beta version. - In your repo, create the
GitHub integration
To set up automatic builds from GitHub:
- Go to your Actor's detail page and coy the Build Actor API endpoint URL from the API tab.
- In your GitHub repository, go to Settings > Webhooks > Add webhook.
- Paste the API URL into the Payload URL field.
Now your Actor will automatically rebuild on every push to the GitHub repository.