Continuous integration for Actors
Learn how to set up automated builds, deploys, and testing for your Actors.
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.
Follow our step-by-step guide to set up continuous integration for your Actors with Bitbucket Pipelines: Read the Bitbucket CI guide.
Set up continuous integration for your Actors using one of these methods:
Choose the method that best fits your workflow.
Option 1: Trigger builds with a Webhook
-
Push your Actor to a GitHub repository.
-
Go to your Actor's detail page in Apify Console, click on the API tab in the top right, then select API Endpoints. Copy the Build Actor API endpoint URL. The format is as follows:
https://api.apify.com/v2/acts/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=beta&waitForFinish=60
API tokenMake sure you select the correct API token from the dropdown.
-
In your GitHub repository, go to Settings > Webhooks > Add webhook.
-
Paste the API URL into the Payload URL field and add the webhook.
Now your Actor will automatically rebuild on every push to the GitHub repository.
Option 2: Set up automated builds and tests with GitHub Actions
-
Push your Actor to a GitHub repository.
-
Get your Apify API token from the Apify Console
-
Add your Apify token to GitHub secrets
- Go to your repository > Settings > Secrets and variables > Actions > New repository secret
- Name the secret and paste in your token
-
Add the Build Actor API endpoint URL to GitHub secrets
-
Go to your repository > Settings > Secrets and variables > Actions > New repository secret
-
In Apify Console, go to your Actor's detail page, click the API tab in the top right, and then select API Endpoints. Copy the Build Actor API endpoint URL. The format is as follows:
API tokenMake sure you select the correct API token from the dropdown.
https://api.apify.com/v2/acts/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=latest&waitForFinish=60
-
Name the secret & paste in your API endpoint
-
-
Create GitHub Actions workflow files:
- In your repository, create the
.github/workflows
directory - Add
latest.yml
. If you want, you can also addbeta.yml
to build Actors from the develop branch (or other branches).
- latest.yml
- beta.yml
Use your secret namesMake sure to use the exact secret names you set in the previous step.
name: Test and build latest version
on:
push:
branches:
- master
- main
jobs:
test-and-build:
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.BUILD_ACTOR_URL }}
webhook_secret: ${{ secrets.APIFY_TOKEN }}With this setup, pushing to the
main
ormaster
branch tests the code and builds a new latest version.Use your secret namesMake sure to use the exact secret names you set in the previous step.
name: Test and build beta version
on:
push:
branches:
- develop
jobs:
test-and-build:
runs-on: ubuntu-latest
steps:
# Install dependencies and run tests
- uses: actions/checkout@v2
- run: npm install && npm run test
# Build beta version
- uses: distributhor/workflow-webhook@v1
env:
webhook_url: ${{ secrets.BUILD_ACTOR_URL }}
webhook_secret: ${{ secrets.APIFY_TOKEN }}With this setup, pushing to the
develop
branch tests the code and builds a new beta version. - In your repository, create the
Conclusion
Setting up continuous integration (CI) for your Apify Actors ensures that CI automatically tests and builds your code whenever you push changes to your repository. This helps catch issues early and streamlines your deployment process, whether you're releasing to production or maintaining a beta branch.
You can also integrate directly with GitHub, check out the official Apify GitHub integration documentation.