Skip to content

Commit

Permalink
Add dev server logs (#2212)
Browse files Browse the repository at this point in the history
This saves the dev server logs as artifacts and cleans up the dev server
canister look up & logs a bit.
  • Loading branch information
nmattia authored Jan 18, 2024
1 parent b0dc3d4 commit 6fac7e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/canister-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ jobs:
# Make sure that one failing test does not cancel all other matrix jobs
fail-fast: false

env:
# Suffix used for tagging artifacts
artifact_suffix: ${{ contains(matrix.domain, 'internetcomputer') && 'current' || 'legacy' }}-${{ matrix.device }}-${{ matrix.shard }}

steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-node
Expand Down Expand Up @@ -536,7 +540,7 @@ jobs:
- name: Run dev server
id: dev-server-start
run: |
TLS_DEV_SERVER=1 NO_HOT_RELOAD=1 npm run dev&
TLS_DEV_SERVER=1 NO_HOT_RELOAD=1 npm run dev | tee -a > dev-server-logs.txt &
dev_server_pid=$!
echo "dev_server_pid=$dev_server_pid" >> "$GITHUB_OUTPUT"
Expand All @@ -556,11 +560,19 @@ jobs:
if: ${{ always() }}
run: kill ${{ steps.dev-server-start.outputs.dev_server_pid }}

- name: Archive dev server logs
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: dev-server-logs-${{ env.artifact_suffix }}
path: dev-server-logs.txt
if-no-files-found: ignore

- name: Archive test failures
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: e2e-test-failures-${{ matrix.device }}-${{ matrix.shard }}
name: e2e-test-failures-${{ env.artifact_suffix }}
path: test-failures/*
if-no-files-found: ignore

Expand Down
9 changes: 4 additions & 5 deletions src/vite-plugins/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isNullish, nonNullish } from "@dfinity/utils";
import { execSync } from "child_process";
import { minify } from "html-minifier-terser";
import httpProxy from "http-proxy";
import { extname } from "path";
Expand Down Expand Up @@ -136,6 +135,7 @@ export const replicaForwardPlugin = ({
const canisterId = readCanisterId({
canisterName: matchingRule.canisterName,
});
console.log("Host matches forward rule", host);
return forwardToReplica({ canisterId });
}

Expand All @@ -155,17 +155,16 @@ export const replicaForwardPlugin = ({
) /* fast check for principal-ish */
) {
// Assume the principal-ish thing is a canister ID
console.log("Domain matches list to forward", domain);
return forwardToReplica({ canisterId: subdomain });
}

// Try to read the canister ID of a potential canister called <subdomain>
// and if found forward to that
if (nonNullish(subdomain) && domain === "localhost") {
try {
const canisterId = execSync(`dfx canister id ${subdomain}`)
.toString()
.trim();
console.log("Forwarding to", canisterId);
const canisterId = readCanisterId({ canisterName: subdomain });
console.log("Subdomain is a canister", subdomain, canisterId);
return forwardToReplica({ canisterId });
} catch {}
}
Expand Down

0 comments on commit 6fac7e2

Please sign in to comment.