From dc8dd57711daa1e5655fdf3d78cfdeb4b7b86823 Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 09:44:10 +0100 Subject: [PATCH 01/15] feat: auto-trigger code sample testing --- .github/workflows/test-code-samples.yaml | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test-code-samples.yaml diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml new file mode 100644 index 000000000..b6a9c73cc --- /dev/null +++ b/.github/workflows/test-code-samples.yaml @@ -0,0 +1,36 @@ +# When some files in the code_samples folder change, we want to run an Apify Actor and pass it the branch name, if possible, so it can test the samples +name: Test Code Samples + +on: + push: + paths: + - 'apify-api/openapi/code_samples/**' + pull_request: + paths: + - 'apify-api/openapi/code_samples/**' + +jobs: + call-apify-actor: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Get current branch name + id: get-branch-name + run: echo "branch_name=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV + + - name: Call Code Sample Tester Actor + env: + APIFY_TOKEN: ${{ secrets.APIFY_TOKEN }} + BRANCH_NAME: ${{ env.branch_name }} + run: | + curl -X POST "https://api.apify.com/v2/actors/X8D0L4wfpO8fCL1uL/runs" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $APIFY_TOKEN" \ + -d '{ + "input": { + "branchName": "'"$BRANCH_NAME"'" + } + }' From 601bea489a7e97ceed5dcd9573205ae5c4a3c45c Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 09:46:41 +0100 Subject: [PATCH 02/15] add test change --- apify-api/openapi/code_samples/javascript/test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 apify-api/openapi/code_samples/javascript/test.js diff --git a/apify-api/openapi/code_samples/javascript/test.js b/apify-api/openapi/code_samples/javascript/test.js new file mode 100644 index 000000000..e69de29bb From e66f118a23bdc674d38a13fe6e710d58acfa68da Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 09:48:06 +0100 Subject: [PATCH 03/15] fix URL --- .github/workflows/test-code-samples.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index b6a9c73cc..f37992f75 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -26,7 +26,7 @@ jobs: APIFY_TOKEN: ${{ secrets.APIFY_TOKEN }} BRANCH_NAME: ${{ env.branch_name }} run: | - curl -X POST "https://api.apify.com/v2/actors/X8D0L4wfpO8fCL1uL/runs" \ + curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/runs" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $APIFY_TOKEN" \ -d '{ From e0b3896865a7cd496636a541d448ebcd181ec54f Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 09:49:24 +0100 Subject: [PATCH 04/15] fix action --- .github/workflows/test-code-samples.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index f37992f75..01fbb480c 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -26,11 +26,11 @@ jobs: APIFY_TOKEN: ${{ secrets.APIFY_TOKEN }} BRANCH_NAME: ${{ env.branch_name }} run: | - curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/runs" \ + curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $APIFY_TOKEN" \ -d '{ "input": { - "branchName": "'"$BRANCH_NAME"'" + "branch": "'"$BRANCH_NAME"'" } }' From 09189e356a6dab41c0f8f03b4a6c5fa5fa538dbe Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 09:54:54 +0100 Subject: [PATCH 05/15] test samples change --- .github/workflows/test-code-samples.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index 01fbb480c..810a4002a 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -1,5 +1,4 @@ -# When some files in the code_samples folder change, we want to run an Apify Actor and pass it the branch name, if possible, so it can test the samples -name: Test Code Samples +name: Test API Docs Code Samples on: push: @@ -23,7 +22,7 @@ jobs: - name: Call Code Sample Tester Actor env: - APIFY_TOKEN: ${{ secrets.APIFY_TOKEN }} + APIFY_TOKEN: apify_api_2x75M2AvgF4pvx2iYfjESi5cBZdtjy2eAZNP BRANCH_NAME: ${{ env.branch_name }} run: | curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ From 80c5e4dcc6a0d68ab312a4225c8e5976fcdb488b Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 09:57:50 +0100 Subject: [PATCH 06/15] improve curl request --- .github/workflows/test-code-samples.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index 810a4002a..d8ea12c6d 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -28,8 +28,4 @@ jobs: curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $APIFY_TOKEN" \ - -d '{ - "input": { - "branch": "'"$BRANCH_NAME"'" - } - }' + -d '{ "branch": "'"$BRANCH_NAME"'" }' From 13b6d3ebf19f1995c1f754c9bd7548f5e4769102 Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 10:22:00 +0100 Subject: [PATCH 07/15] fix: add proper example --- .github/workflows/test-code-samples.yaml | 2 +- .../openapi/code_samples/javascript/actorRun_put.js | 12 ++++++++++++ apify-api/openapi/code_samples/javascript/test.js | 0 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 apify-api/openapi/code_samples/javascript/actorRun_put.js delete mode 100644 apify-api/openapi/code_samples/javascript/test.js diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index d8ea12c6d..34c1d5a65 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -22,7 +22,7 @@ jobs: - name: Call Code Sample Tester Actor env: - APIFY_TOKEN: apify_api_2x75M2AvgF4pvx2iYfjESi5cBZdtjy2eAZNP + APIFY_TOKEN: apify_api_Hh2OPyR6MPVJ6te8pkfe27vS09aL1f2lquSt BRANCH_NAME: ${{ env.branch_name }} run: | curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ diff --git a/apify-api/openapi/code_samples/javascript/actorRun_put.js b/apify-api/openapi/code_samples/javascript/actorRun_put.js new file mode 100644 index 000000000..9aef10b16 --- /dev/null +++ b/apify-api/openapi/code_samples/javascript/actorRun_put.js @@ -0,0 +1,12 @@ +import { ApifyClient } from 'apify-client'; + +const apifyClient = new ApifyClient({ + token: '', +}); +const updatedRun = await apifyClient + .run('') + .update({ + statusMessage: 'Actor has finished', + }); + +console.log(updatedRun); diff --git a/apify-api/openapi/code_samples/javascript/test.js b/apify-api/openapi/code_samples/javascript/test.js deleted file mode 100644 index e69de29bb..000000000 From f5121c0b85099ed2b9f8f3f178619902d5ce901f Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 10:23:59 +0100 Subject: [PATCH 08/15] fixes --- .github/workflows/test-code-samples.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index 34c1d5a65..3823e8c3d 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -9,7 +9,7 @@ on: - 'apify-api/openapi/code_samples/**' jobs: - call-apify-actor: + run-code-sample-tests: runs-on: ubuntu-latest steps: @@ -22,7 +22,7 @@ jobs: - name: Call Code Sample Tester Actor env: - APIFY_TOKEN: apify_api_Hh2OPyR6MPVJ6te8pkfe27vS09aL1f2lquSt + APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} BRANCH_NAME: ${{ env.branch_name }} run: | curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ From 9becceae09f2ab0923ea45d9da411f103e3b50de Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 10:47:52 +0100 Subject: [PATCH 09/15] fail workflow if run fails --- .github/workflows/test-code-samples.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index 3823e8c3d..ef637dce0 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -25,7 +25,7 @@ jobs: APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} BRANCH_NAME: ${{ env.branch_name }} run: | - curl -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ + curl --fail-with-body -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $APIFY_TOKEN" \ -d '{ "branch": "'"$BRANCH_NAME"'" }' From 68bc6d5e25dd472fb45a48888387b6419d8695b0 Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 11:45:27 +0100 Subject: [PATCH 10/15] test updated branch name getter --- .github/workflows/test-code-samples.yaml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index ef637dce0..a7361855c 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -13,17 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Get current branch name - id: get-branch-name - run: echo "branch_name=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV - - name: Call Code Sample Tester Actor env: - APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} - BRANCH_NAME: ${{ env.branch_name }} + # APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} + APIFY_TOKEN: apify_api_cUpIjxWrtMdy6Ctqnz9PhYyTjdqWcI4tjFTr + BRANCH_NAME: ${{ github.ref_name }} run: | curl --fail-with-body -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ From b52772fc12aa3b76c5cb3d19af93f0befbeab0a4 Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 11:46:36 +0100 Subject: [PATCH 11/15] add change to trigger flow --- apify-api/openapi/code_samples/javascript/act_builds_get.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apify-api/openapi/code_samples/javascript/act_builds_get.js b/apify-api/openapi/code_samples/javascript/act_builds_get.js index e70e1bf29..998f4dee1 100644 --- a/apify-api/openapi/code_samples/javascript/act_builds_get.js +++ b/apify-api/openapi/code_samples/javascript/act_builds_get.js @@ -6,6 +6,6 @@ const apifyClient = new ApifyClient({ const { items } = await apifyClient .actor('') .builds() - .list(); + .list('test'); console.log(items); From 25008d7de1b77a5d283a98653100c53cb1510d3f Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 11:49:34 +0100 Subject: [PATCH 12/15] update branch getter --- .github/workflows/test-code-samples.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index a7361855c..e1916a18b 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -17,7 +17,7 @@ jobs: env: # APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} APIFY_TOKEN: apify_api_cUpIjxWrtMdy6Ctqnz9PhYyTjdqWcI4tjFTr - BRANCH_NAME: ${{ github.ref_name }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} run: | curl --fail-with-body -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ From cccf9bb5c274fd880483aa69408ece1c90e29e52 Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 12:00:10 +0100 Subject: [PATCH 13/15] get repo owner in test action --- .github/workflows/test-code-samples.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index e1916a18b..9f6e001c3 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -18,8 +18,9 @@ jobs: # APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} APIFY_TOKEN: apify_api_cUpIjxWrtMdy6Ctqnz9PhYyTjdqWcI4tjFTr BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + REPO_OWNER: ${{ github.repository_owner }} run: | curl --fail-with-body -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $APIFY_TOKEN" \ - -d '{ "branch": "'"$BRANCH_NAME"'" }' + -d '{ "branch": "'"$BRANCH_NAME"'", "repoOwner": "'"$REPO_OWNER"'" }' From c6875c424c691f637353ee361b7d37a3875cc343 Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 12:04:37 +0100 Subject: [PATCH 14/15] try get forked repo name --- .github/workflows/test-code-samples.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index 9f6e001c3..e31737fa8 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -18,7 +18,7 @@ jobs: # APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} APIFY_TOKEN: apify_api_cUpIjxWrtMdy6Ctqnz9PhYyTjdqWcI4tjFTr BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - REPO_OWNER: ${{ github.repository_owner }} + REPO_OWNER: ${{ github.actor }} run: | curl --fail-with-body -X POST "https://api.apify.com/v2/acts/X8D0L4wfpO8fCL1uL/run-sync" \ -H "Content-Type: application/json" \ From 984161c985c8f78a36fa784b761746f06a7864ee Mon Sep 17 00:00:00 2001 From: Mihails Date: Fri, 20 Dec 2024 12:07:46 +0100 Subject: [PATCH 15/15] remove test data --- .github/workflows/test-code-samples.yaml | 3 +-- apify-api/openapi/code_samples/javascript/act_builds_get.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-code-samples.yaml b/.github/workflows/test-code-samples.yaml index e31737fa8..bdff08340 100644 --- a/.github/workflows/test-code-samples.yaml +++ b/.github/workflows/test-code-samples.yaml @@ -15,8 +15,7 @@ jobs: steps: - name: Call Code Sample Tester Actor env: - # APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} - APIFY_TOKEN: apify_api_cUpIjxWrtMdy6Ctqnz9PhYyTjdqWcI4tjFTr + APIFY_TOKEN: ${{ secrets.CODE_SAMPLE_TESTER_ACTOR_TOKEN }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} REPO_OWNER: ${{ github.actor }} run: | diff --git a/apify-api/openapi/code_samples/javascript/act_builds_get.js b/apify-api/openapi/code_samples/javascript/act_builds_get.js index 998f4dee1..e70e1bf29 100644 --- a/apify-api/openapi/code_samples/javascript/act_builds_get.js +++ b/apify-api/openapi/code_samples/javascript/act_builds_get.js @@ -6,6 +6,6 @@ const apifyClient = new ApifyClient({ const { items } = await apifyClient .actor('') .builds() - .list('test'); + .list(); console.log(items);