Skip to content

Commit 5329697

Browse files
janbucharszaganek
andauthored
feat: Improve continuous integration guide (#2612)
Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>
1 parent 54d3397 commit 5329697

1 file changed

Lines changed: 126 additions & 117 deletions

File tree

Lines changed: 126 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Continuous integration for Actors
33
sidebar_label: Continuous integration
4-
description: Set up automated builds, deploys, and tests for your Actors using GitHub Actions, Bitbucket Pipelines, webhooks, or direct calls to the Apify API.
4+
description: Set up automated builds, deploys, and tests for your Actors using GitHub Actions, webhooks, or the official GitHub integration.
55
slug: /actors/development/deployment/continuous-integration
66
sidebar_position: 2
77
---
@@ -13,152 +13,161 @@ import TabItem from '@theme/TabItem';
1313

1414
---
1515

16-
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.
17-
18-
You can automate Actor builds and tests using your Git repository's automated workflows like [GitHub Actions](https://github.com/features/actions) or [Bitbucket Pipelines](https://www.atlassian.com/software/bitbucket/features/pipelines).
19-
20-
21-
:::tip Using Bitbucket?
22-
23-
Follow the step-by-step guide to set up continuous integration for your Actors with Bitbucket Pipelines: [Read the Bitbucket CI guide](https://help.apify.com/en/articles/6988586-setting-up-continuous-integration-for-apify-actors-on-bitbucket).
24-
25-
:::
26-
16+
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.
2717

2818
Set up continuous integration for your Actors using one of these methods:
2919

30-
- [Trigger builds with a Webhook](#option-1-trigger-builds-with-a-webhook)
31-
- [Set up automated builds and tests with GitHub Actions](#option-2-set-up-automated-builds-and-tests-with-github-actions)
32-
33-
Choose the method that best fits your workflow.
34-
35-
## Option 1: Trigger builds with a webhook
36-
37-
1. Push your Actor to a GitHub repository.
38-
1. 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:
39-
40-
```cURL
41-
https://api.apify.com/v2/actors/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=beta&waitForFinish=60
42-
```
20+
- [GitHub Actions](#github-actions) - the most flexible approach, with support for tests, multi-branch builds, and custom workflows.
21+
- [API webhook](#api-webhook) - works with Bitbucket, GitLab, and other Git hosting providers that support webhooks.
22+
- [GitHub integration](#github-integration) - the quickest setup with no workflow files needed, but less flexible than GitHub Actions.
23+
24+
## Set up automated builds with GitHub Actions {#github-actions}
25+
26+
To push your Actor source code to the Apify platform and build it on every push, use the official [`apify/push-actor-action`](https://github.com/apify/push-actor-action) GitHub Action. It works similarly to running `apify push` with the Apify CLI, and gives you full control over your CI pipeline: you can run tests, manage multiple branches, and customize the workflow.
27+
28+
### Prerequisites
29+
30+
- Your Actor source code in a GitHub repository with a valid `.actor/actor.json` file.
31+
- An Apify API token. Find yours in [Apify Console](https://console.apify.com/settings/integrations) under **Settings** > **Integrations**.
32+
33+
### Step 1: Add your Apify token to GitHub secrets
34+
35+
1. Go to your GitHub repository.
36+
1. Select **Settings** > **Security and quality** > **Secrets and variables** > **Actions**.
37+
1. In the **Secrets** tab, go to **Repository secrets** and select **New repository secret**.
38+
1. Complete the following fields:
39+
40+
- **Name**: use `APIFY_TOKEN` as a name for your secret.
41+
- **Secret**: paste your Apify API token.
4342

44-
:::note API token
43+
### Step 2: Create a GitHub Actions workflow
4544

46-
Make sure you select the correct API token from the dropdown.
45+
In your repository, create a `.github/workflows` directory and add a workflow file. The following examples show common setups for production and beta branches.
4746

48-
:::
47+
<Tabs groupId="main">
48+
<TabItem value="latest.yml" label="latest.yml">
4949

50-
1. In your GitHub repository, go to Settings > Webhooks > Add webhook.
51-
1. Paste the API URL into the Payload URL field and add the webhook.
50+
Push to the Apify platform and build the Actor on every push to `main` or `master`:
5251

53-
![GitHub integration](./images/ci-github-integration.png)
54-
55-
Now your Actor will automatically rebuild on every push to the GitHub repository.
56-
57-
## Option 2: Set up automated builds and tests with GitHub Actions
58-
59-
1. Push your Actor to a GitHub repository.
60-
1. Get your Apify API token from the [Apify Console](https://console.apify.com/settings/integrations)
61-
62-
![Apify token in app](./images/ci-token.png)
63-
64-
1. Add your Apify token to GitHub secrets
65-
1. Go to your repository > Settings > Secrets and variables > Actions > New repository secret
66-
1. Name the secret and paste in your token
52+
```yaml
53+
name: Push and build latest version
54+
on:
55+
push:
56+
branches:
57+
- master
58+
- main
59+
jobs:
60+
push-actor:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v4
6764

68-
![Add Apify token to secrets](./images/ci-add-token.png)
65+
- name: Push Actor to Apify
66+
uses: apify/push-actor-action@v1
67+
with:
68+
token: ${{ secrets.APIFY_TOKEN }}
69+
```
6970
70-
1. Add the Build Actor API endpoint URL to GitHub secrets
71-
1. Go to your repository > Settings > Secrets and variables > Actions > New repository secret
72-
1. 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:
71+
</TabItem>
72+
<TabItem value="beta.yml" label="beta.yml">
7373
74-
:::note API token
74+
Push to the Apify platform and build a beta version on every push to `develop`:
7575

76-
Make sure you select the correct API token from the dropdown.
76+
```yaml
77+
name: Push and build beta version
78+
on:
79+
push:
80+
branches:
81+
- develop
82+
jobs:
83+
push-actor:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
7787
78-
:::
88+
- name: Push Actor to Apify
89+
uses: apify/push-actor-action@v1
90+
with:
91+
token: ${{ secrets.APIFY_TOKEN }}
92+
build-tag: beta
93+
```
7994

80-
```cURL
81-
https://api.apify.com/v2/actors/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=latest&waitForFinish=60
82-
```
95+
</TabItem>
96+
<TabItem value="test-and-push.yml" label="With tests">
8397

84-
1. Name the secret & paste in your API endpoint
98+
Run tests before pushing the Actor to the Apify platform:
8599

86-
![Add build Actor URL to secrets](./images/ci-add-build-url.png)
100+
```yaml
101+
name: Test and push latest version
102+
on:
103+
push:
104+
branches:
105+
- master
106+
- main
107+
jobs:
108+
test-and-push:
109+
runs-on: ubuntu-latest
110+
steps:
111+
- uses: actions/checkout@v4
87112
88-
1. Create GitHub Actions workflow files:
89-
1. In your repository, create the `.github/workflows` directory
90-
1. Add `latest.yml`. If you want, you can also add `beta.yml` to build Actors from the develop branch (or other branches).
113+
- name: Set up Node.js
114+
uses: actions/setup-node@v4
115+
with:
116+
node-version: 22
91117
92-
<Tabs groupId="main">
93-
<TabItem value="latest.yml" label="latest.yml">
118+
- name: Install dependencies and run tests
119+
run: npm install && npm run test
94120
95-
:::note Use your secret names
121+
- name: Push Actor to Apify
122+
id: push
123+
uses: apify/push-actor-action@v1
124+
with:
125+
token: ${{ secrets.APIFY_TOKEN }}
96126
97-
Make sure to use the exact secret names you set in the previous step.
127+
- name: Print build details
128+
run: |
129+
echo "Build ${{ steps.push.outputs.build-id }} finished with status ${{ steps.push.outputs.build-status }}"
130+
```
131+
132+
</TabItem>
133+
</Tabs>
134+
135+
For the full list of inputs (such as `actor-id`, `version`, and `working-directory`) and outputs, see the [`apify/push-actor-action` README](https://github.com/apify/push-actor-action).
136+
137+
## Trigger builds with a webhook {#api-webhook}
138+
139+
If you use Bitbucket, GitLab, or another Git hosting provider that supports webhooks, you can trigger Actor builds by calling the Apify build API on every push. This approach only triggers a build, it doesn't push your source code to the platform.
140+
141+
:::note Source code
142+
143+
When using the webhook approach, the Actor must have its source set to a Git repository in Apify Console. The webhook only triggers a build using the source already configured on the platform.
98144

99-
:::
100-
101-
```yaml
102-
name: Test and build latest version
103-
on:
104-
push:
105-
branches:
106-
- master
107-
- main
108-
jobs:
109-
test-and-build:
110-
runs-on: ubuntu-latest
111-
steps:
112-
# Install dependencies and run tests
113-
- uses: actions/checkout@v2
114-
- run: npm install && npm run test
115-
# Build latest version
116-
- uses: distributhor/workflow-webhook@v1
117-
env:
118-
webhook_url: ${{ secrets.BUILD_ACTOR_URL }}
119-
webhook_secret: ${{ secrets.APIFY_TOKEN }}
120-
121-
```
145+
:::
122146

123-
With this setup, pushing to the `main` or `master` branch tests the code and builds a new latest version.
147+
1. Go to your Actor's detail page in Apify Console.
148+
1. Go to the **API** tab.
149+
1. Select **API Endpoints** and copy the **Build Actor** API endpoint URL:
124150

125-
</TabItem>
126-
<TabItem value="beta.yml" label="beta.yml">
151+
```text
152+
https://api.apify.com/v2/actors/YOUR-ACTOR-NAME/builds?token=YOUR-TOKEN-HERE&version=0.0&tag=latest&waitForFinish=60
153+
```
127154

128-
:::note Use your secret names
155+
1. In your repository hosting provider, add a webhook that fires on push events and set the URL to the build API endpoint you copied.
129156

130-
Make sure to use the exact secret names you set in the previous step.
157+
For example, in GitHub, go to **Settings** > **Webhooks** > **Add webhook** and paste the URL into the **Payload URL** field.
131158

132-
:::
159+
![GitHub integration](./images/ci-github-integration.png)
133160

134-
```yaml
135-
name: Test and build beta version
136-
on:
137-
push:
138-
branches:
139-
- develop
140-
jobs:
141-
test-and-build:
142-
runs-on: ubuntu-latest
143-
steps:
144-
# Install dependencies and run tests
145-
- uses: actions/checkout@v2
146-
- run: npm install && npm run test
147-
# Build beta version
148-
- uses: distributhor/workflow-webhook@v1
149-
env:
150-
webhook_url: ${{ secrets.BUILD_ACTOR_URL }}
151-
webhook_secret: ${{ secrets.APIFY_TOKEN }}
161+
:::tip Bitbucket Pipelines
152162

153-
```
163+
For a more complete Bitbucket setup with automated tests, see the [Bitbucket CI guide](https://help.apify.com/en/articles/6988586-setting-up-continuous-integration-for-apify-actors-on-bitbucket).
154164

155-
With this setup, pushing to the `develop` branch tests the code and builds a new beta version.
165+
:::
156166

157-
</TabItem>
158-
</Tabs>
167+
## Use the Apify GitHub integration {#github-integration}
159168

160-
## Conclusion
169+
Apify Console includes a built-in [GitHub integration](/platform/integrations/github) that links an Actor directly to a GitHub repository. When you connect a repository, Apify automatically rebuilds the Actor on every push - no workflow files or webhook configuration needed.
161170

162-
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.
171+
This is the quickest way to get automated builds running, but it's less flexible than the GitHub Actions approach. It doesn't support running tests before building, managing multiple version tags from different branches, or customizing the build pipeline.
163172

164-
You can also integrate directly with GitHub, check out the [official Apify GitHub integration documentation](/platform/integrations/github).
173+
To set it up, see the [GitHub integration](/platform/integrations/github) documentation.

0 commit comments

Comments
 (0)