-
Notifications
You must be signed in to change notification settings - Fork 2
Fix/deployment integration tests #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3de2db4
prod invocation integration test
godronus da09047
Merge pull request #107 from G-Core/fix/deployment-integration-tests
godronus 9391181
fix secret assignment
godronus b95c0ba
Merge branch 'alpha' into fix/deployment-integration-tests
godronus 984e157
Update .github/scripts/prod-invocation/create-test-app.js
godronus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { execSync } from 'child_process'; | ||
|
|
||
| const TEST_APP_SOURCE_FILE_PATH = './integration-tests/test-application/test-app.js'; | ||
| const TEST_APP_WASM_FILE_PATH = './integration-tests/test-application/test-app.wasm'; | ||
|
|
||
| export default async ({ github, context, core }) => { | ||
| // Ensure this is running in GitHub Actions | ||
| if (!process.env.GITHUB_ENV) { | ||
| throw new Error( | ||
| 'GITHUB_ENV is not defined. This script must be run in a GitHub Actions environment.', | ||
| ); | ||
| } | ||
|
|
||
| const workspaceDir = process.env.GITHUB_WORKSPACE || process.cwd(); | ||
|
|
||
| // Build the test app code into a wasm binary | ||
| const buildResponse = execSync( | ||
| './bin/fastedge-build.js --input ' + | ||
| TEST_APP_SOURCE_FILE_PATH + | ||
| ' --output ' + | ||
| TEST_APP_WASM_FILE_PATH, | ||
| { encoding: 'utf8', cwd: workspaceDir }, | ||
| ); | ||
|
|
||
| core.info(`Build output: ${buildResponse}`); | ||
|
|
||
| if (!buildResponse.includes('Build success!!')) { | ||
| throw new Error('Failed to build test application into wasm binary'); | ||
| } | ||
|
|
||
| core.info(`Test application built into wasm binary at ${TEST_APP_WASM_FILE_PATH}`); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| const MAX_RETRIES = 3; | ||
| const INITIAL_WAIT_FOR_DEPLOYMENT_SECONDS = 15; | ||
| const RETRY_DELAY_SECONDS = 5; | ||
| const DATA_IS_VALID = 'DATA_IS_VALID'; | ||
|
|
||
| const sleep = (secs = RETRY_DELAY_SECONDS) => | ||
| new Promise((resolve) => setTimeout(resolve, secs * 1000)); | ||
|
|
||
| const isResponseDataValid = (data, build_sha) => { | ||
| if (data.build_sha !== build_sha) { | ||
| return `prod environment build_sha mismatch: expected ${build_sha}, got ${data.build_sha}`; | ||
| } | ||
|
|
||
| return DATA_IS_VALID; | ||
| }; | ||
|
|
||
| export default async ({ github, context, core }) => { | ||
| // Ensure this is running in GitHub Actions | ||
| if (!process.env.GITHUB_ENV) { | ||
| throw new Error( | ||
| 'GITHUB_ENV is not defined. This script must be run in a GitHub Actions environment.', | ||
| ); | ||
| } | ||
|
|
||
| const appUrl = process.env.APP_URL; | ||
| const build_sha = context.sha; | ||
|
|
||
godronus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Give the production environment some time to update with the new test application | ||
| await sleep(INITIAL_WAIT_FOR_DEPLOYMENT_SECONDS); | ||
|
|
||
| for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) { | ||
| // Pause between attempts | ||
| await sleep(RETRY_DELAY_SECONDS); | ||
godronus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| const res = await fetch(appUrl); | ||
| if (res.status !== 200) { | ||
| throw new Error(`prod environment bad response: ${res.status}`); | ||
| } | ||
| const data = await res.json(); | ||
| core.info(`Response data: ${JSON.stringify(data)}`); | ||
|
|
||
| // validate response data matches what we expect | ||
| const validationResult = isResponseDataValid(data, build_sha); | ||
| if (validationResult === DATA_IS_VALID) { | ||
| // Response is as we expected | ||
| break; | ||
| } | ||
|
|
||
| throw new Error(validationResult); | ||
| } catch (error) { | ||
| // Log the error and retry again after a delay | ||
| core.warning(`Attempt ${attempt} failed: ${error.message}`); | ||
|
|
||
| if (attempt === MAX_RETRIES) { | ||
| // If we've reached the max retries, re-throw an error to kill the workflow | ||
| throw new Error( | ||
| `Test application invocation failed after ${MAX_RETRIES} attempts: ${error.message}`, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| core.info(`Test application invocation succeeded with status 200 and valid response data.`); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| name: Build and run application | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| VAULT_TOKEN: | ||
| required: true | ||
|
|
||
| jobs: | ||
| live-test-invocation: | ||
| runs-on: [self-hosted, ubuntu-22-04, regular] | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node Environment | ||
| uses: ./.github/setup-node | ||
|
|
||
| - name: Clean up test-app.wasm | ||
| shell: bash | ||
| run: | | ||
| rm -f ./integration-tests/test-application/test-app.wasm | ||
|
|
||
| - name: Restore build cache | ||
| id: restore-build-cache | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: | | ||
| lib/ | ||
| bin/ | ||
| types/ | ||
| key: ${{ runner.os }}-libs-artifact-${{ github.sha }} | ||
|
|
||
| - name: Ensure build folders are valid | ||
| shell: bash | ||
| run: | | ||
| if [ ! -d "lib" ] || [ ! -d "bin" ] || [ ! -d "types" ]; then | ||
| echo "Build folders are missing. Please run the build-libs workflow before releasing." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Create and build test application | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| const script = await import('${{ github.workspace }}/.github/scripts/prod-invocation/create-test-app.js') | ||
| await script.default({github, context, core}) | ||
|
|
||
| - name: Import Secrets | ||
| uses: hashicorp/vault-action@v3 | ||
| id: secrets | ||
| with: | ||
| url: https://puppet-vault.gc.onl | ||
| token: ${{ secrets.VAULT_TOKEN }} | ||
| secrets: | | ||
| secret/project_fastedge/team_account/prod token | PROD_GCORE_API_TOKEN ; | ||
| secret/project_fastedge/team_account/prod hostname | PROD_GCORE_API_HOSTNAME ; | ||
| secret/project_fastedge/team_account/preprod token | PREPROD_GCORE_API_TOKEN ; | ||
| secret/project_fastedge/team_account/preprod hostname | PREPROD_GCORE_API_HOSTNAME ; | ||
|
|
||
| - name: Decipher test environment from branch | ||
| id: env-check | ||
| shell: bash | ||
| run: | | ||
| if [ "${{ github.ref }}" == "refs/heads/main" ]; then | ||
| echo "Run against production environment" | ||
| echo "is_prod=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Run in preprod environment" | ||
| echo "is_prod=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Debug env-check | ||
| shell: bash | ||
| run: | | ||
| echo "is_prod ${{ steps.env-check.outputs.is_prod }}" | ||
|
|
||
| - name: Deploy Test App to Gcore | ||
| id: deploy-app | ||
| uses: gcore-github-actions/fastedge/deploy-app@v1 | ||
| with: | ||
| api_key: | ||
| ${{ steps.env-check.outputs.is_prod == 'true' && | ||
| steps.secrets.outputs.PROD_GCORE_API_TOKEN || | ||
| steps.secrets.outputs.PREPROD_GCORE_API_TOKEN }} | ||
| api_url: | ||
| ${{ steps.env-check.outputs.is_prod == 'true' && | ||
| steps.secrets.outputs.PROD_GCORE_API_HOSTNAME || | ||
| steps.secrets.outputs.PREPROD_GCORE_API_HOSTNAME }} | ||
| wasm_file: integration-tests/test-application/test-app.wasm | ||
| app_name: 'fastedge-sdk-js-test-app' | ||
| comment: 'Deployed by prod-invocation workflow' | ||
| env: | | ||
| BUILD_SHA=${{ github.sha }} | ||
|
|
||
| - name: Invoke test application | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| APP_URL: ${{ steps.deploy-app.outputs.app_url }} | ||
| with: | ||
| script: | | ||
| const script = await import('${{ github.workspace }}/.github/scripts/prod-invocation/invoke-test-app.js') | ||
| await script.default({github, context, core}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { getEnv } from 'fastedge::env'; | ||
|
|
||
| async function eventHandler(event) { | ||
| const build_sha = getEnv('BUILD_SHA'); | ||
|
|
||
| return Response.json({ | ||
| message: 'app running on production', | ||
| build_sha: `${build_sha}`, | ||
| }); | ||
| } | ||
|
|
||
| addEventListener('fetch', (event) => { | ||
| event.respondWith(eventHandler(event)); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.