Skip to content

Commit 09cfd83

Browse files
authored
Merge branch 'main' into fastly-tests
2 parents 7a8bc54 + da475cc commit 09cfd83

34 files changed

+12359
-307
lines changed

.github/workflows/build_akamai.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build and Test Akamai
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-akamai
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build-core:
17+
uses: ./.github/workflows/build_core.yml
18+
19+
akamai:
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 15
22+
needs: build-core
23+
defaults:
24+
run:
25+
working-directory: ./bindings/akamai
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Use Node.js 22.x
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 22.x
32+
cache: 'npm'
33+
- uses: actions/download-artifact@v4
34+
with:
35+
name: core-library-artifacts
36+
path: dist
37+
- run: echo "Current directory - $(pwd)"
38+
- run: npm ci
39+
- run: npm run build
40+
# TODO: fix tests
41+
#- run: npm test
42+
- uses: actions/upload-artifact@v4
43+
with:
44+
name: akamai-artifacts
45+
path: bindings/akamai/dist/*

.github/workflows/build_cloudflare.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
workflow_call:
1010

1111
concurrency:
12-
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-cloudflare
1313
cancel-in-progress: true
1414

1515
jobs:

.github/workflows/build_core.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
workflow_dispatch:
55
workflow_call:
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-core
9+
cancel-in-progress: true
10+
711
jobs:
812
build-and-test:
913
runs-on: ubuntu-latest

.github/workflows/build_fastly.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
workflow_call:
1010

1111
concurrency:
12-
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-fastly
1313
cancel-in-progress: true
1414

1515
jobs:
@@ -43,11 +43,10 @@ jobs:
4343
sudo dpkg -i fastly_10.15.0_linux_amd64.deb
4444
sudo apt-get update
4545
sudo apt-get install -y --fix-missing
46-
- run: npm i
46+
- run: npm ci
4747
- run: npm run build
4848
- uses: actions/upload-artifact@v4
4949
with:
5050
name: fastly-artifacts
5151
path: bindings/fastly/dist/*
52-
# TODO: fix tests
53-
# - run: npm test
52+
- run: npm test
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Integration Test Akamai
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-integrate-akamai
8+
cancel-in-progress: true
9+
10+
jobs:
11+
build:
12+
uses: ./.github/workflows/build_akamai.yml
13+
14+
deploy:
15+
runs-on: ubuntu-latest
16+
needs: [build]
17+
defaults:
18+
run:
19+
working-directory: ./bindings/akamai
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Use Node.js 22.x
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 22.x
26+
cache: 'npm'
27+
- run: npm ci
28+
- uses: actions/download-artifact@v4
29+
with:
30+
name: akamai-artifacts
31+
path: bindings/akamai/dist
32+
- run: wget https://github.com/akamai/cli/releases/download/v1.6.0/akamai-v1.6.0-linuxamd64
33+
- run: chmod +x akamai-v1.6.0-linuxamd64
34+
- run: mv akamai-v1.6.0-linuxamd64 /usr/local/bin/akamai
35+
- run: printf "${{ secrets.AKAMAI_EDGERC }}" >> ~/.edgerc
36+
- run: akamai install edgeworkers # edgeworkers subcommand must be explicitly installed
37+
- run: echo ::add-mask::${{ secrets.AKAMAI_EMAIL }}
38+
- name: Get Next Version
39+
id: get-next-version
40+
run: |
41+
latest_version=$(akamai ew list-versions --edgerc ~/.edgerc --jsonout ${{ secrets.AKAMAI_INTEGRATION_EW_ID }} | jq -r .data[-1].version)
42+
echo latest version: $latest_version
43+
next_version=$(awk -F. '{printf "%s.%s.%s", $1, $2, $3+1}' <<< "$latest_version")
44+
echo next version: $next_version
45+
echo "LATEST_VERSION=$latest_version" >> "$GITHUB_OUTPUT"
46+
echo "NEXT_VERSION=$next_version" >> "$GITHUB_OUTPUT"
47+
- name: Produce Bundle
48+
run: |
49+
echo "{\"edgeworker-version\": \"${{ steps.get-next-version.outputs.NEXT_VERSION }}\"}" > dist/bundle.json
50+
npm run pack
51+
echo package created.
52+
akamai ew validate dist/akamai.tgz
53+
- name: Upload Bundle
54+
run: akamai ew upload --edgerc ~/.edgerc --jsonout --bundle dist/akamai.tgz ${{ secrets.AKAMAI_INTEGRATION_EW_ID }}
55+
- name: Activate Bundle
56+
run: akamai ew activate --edgerc ~/.edgerc --jsonout ${{ secrets.AKAMAI_INTEGRATION_EW_ID }} staging ${{ steps.get-next-version.outputs.NEXT_VERSION }}
57+
- name: Wait for Activation
58+
run: |
59+
timeout=600
60+
start_time=$(date +%s)
61+
while true; do
62+
out=$(akamai ew status --edgerc ~/.edgerc --jsonout ${{ secrets.AKAMAI_INTEGRATION_EW_ID }} --versionId ${{ steps.get-next-version.outputs.NEXT_VERSION }})
63+
if [[ $(echo $out | jq -r .data[0].status) == "COMPLETE" ]]; then
64+
echo "Akamai activation completed successfully."
65+
break
66+
fi
67+
if (( $(date +%s) - $start_time >= $timeout )); then
68+
echo "Akamai activation timeout out after $timeout seconds. Status: $(echo $out | jq .data[0].status), expected COMPLETE."
69+
break
70+
fi
71+
echo "Deployment status: $(echo $out | jq .data[0].status). Sleeping"
72+
sleep 10
73+
done
74+
- name: Set Properties
75+
run: echo TODO
76+
- name: Run Integraiton Test
77+
run: echo TODO

.github/workflows/integration_cloudflare.yaml

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,67 @@ on:
44
workflow_dispatch:
55

66
concurrency:
7-
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
7+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-integrate-cloudflare
88
cancel-in-progress: true
99

1010
jobs:
1111
build:
1212
uses: ./.github/workflows/build_cloudflare.yml
1313

14-
setup:
14+
deploy:
1515
runs-on: ubuntu-latest
16+
needs: [build]
17+
defaults:
18+
run:
19+
working-directory: ./bindings/cloudflare
1620
steps:
1721
- uses: actions/checkout@v4
1822
- name: Use Node.js 22.x
1923
uses: actions/setup-node@v4
2024
with:
2125
node-version: 22.x
2226
cache: 'npm'
23-
24-
cloudflare:
25-
runs-on: ubuntu-latest
26-
needs: [build, setup]
27-
defaults:
28-
run:
29-
working-directory: ./bindings/cloudflare
30-
strategy:
31-
matrix:
32-
node-version: [22.x]
33-
steps:
27+
- run: npm ci
3428
- uses: actions/download-artifact@v4
3529
with:
3630
name: cloudflare-artifacts
37-
path: bindings/cloudflare/dist/*
38-
- name: Deploy to Cloudflare
31+
path: bindings/cloudflare/dist
32+
- uses: cloudflare/wrangler-action@v3
33+
with:
34+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
35+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
36+
workingDirectory: ./bindings/cloudflare
37+
command: deploy dist/cloudflare_worker.js --no-bundle
38+
secrets: |
39+
API_KEY
40+
PROJECT_NUMBER
41+
ACTION_SITE_KEY
42+
SESSION_SITE_KEY
43+
CHALLENGE_PAGE_SITE_KEY
44+
EXPRESS_SITE_KEY
45+
SESSION_JS_INSTALL_PATH
46+
ENDPOINT
3947
env:
40-
CF_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }}
41-
CF_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
42-
run: npm run deploy:nobuild
43-
#- name: Run Integration Tests
44-
# run: ./integration_test.sh
48+
API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
49+
PROJECT_NUMBER: ${{ secrets.CLOUDFLARE_PROJECT_NUMBER }}
50+
ACTION_SITE_KEY: ${{ secrets.CLOUDFLARE_ACTION_SITE_KEY }}
51+
SESSION_SITE_KEY: ${{ secrets.CLOUDFLARE_SESSION_SITE_KEY }}
52+
CHALLENGE_PAGE_SITE_KEY: ${{ secrets.CLOUDFLARE_CHALLENGE_PAGE_SITE_KEY }}
53+
EXPRESS_SITE_KEY: ${{ secrets.CLOUDFLARE_EXPRESS_SITE_KEY }}
54+
SESSION_JS_INSTALL_PATH: ${{ secrets.CLOUDFLARE_SESSION_JS_INSTALL_PATH }}
55+
ENDPOINT: ${{secrets.CLOUDFLARE_ENDPOINT}}
56+
test:
57+
runs-on: ubuntu-latest
58+
needs: [deploy]
59+
steps:
60+
- uses: actions/checkout@v4
61+
- name: Use Node.js 22.x
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: 22.x
65+
cache: 'npm'
66+
- run: npm ci --prefix integration
67+
- name: Run Integration Tests
68+
run: |
69+
cd ./integration
70+
npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ bindings/**/dist/*
44
bindings/**/pkg/*
55
bindings/**/bin/*
66
bindings/**/node_modules/*
7+
.DS_Store

.prettierrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
{}
1+
{
2+
"printWidth": 80,
3+
"singleQuote": false,
4+
"semi": true,
5+
"useTabs": true
6+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# reCAPTCHA WAF (Edge Compute) Library
22

33
[![Build and Test Core Library](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_core.yml/badge.svg)](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_core.yml)
4+
[![Build and Test Akamai Binding](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_akamai.yml/badge.svg)](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_akamai.yml)
45
[![Build and Test Cloudflare Binding](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_cloudflare.yml/badge.svg)](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_cloudflare.yml)
56
[![Build and Test Fastly Binding](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_fastly.yml/badge.svg)](https://github.com/GoogleCloudPlatform/recaptcha-waf/actions/workflows/build_fastly.yml)
67

0 commit comments

Comments
 (0)