From fb351196decbb8aec9339318615720480b8d4db6 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 10 Jun 2024 17:22:11 +0200 Subject: [PATCH] refactor: IPFS_NS_MAP from gateway-conformance v6 no need to generate env from json, a fixture in desired format is alreadt provided, and we no longer mix subdomains with dnslink tests, whcih also simplifies code --- .github/workflows/gateway-conformance.yml | 11 +++++++++-- packages/gateway-conformance/src/conformance.spec.ts | 5 ++++- .../gateway-conformance/src/fixtures/kubo-mgmt.ts | 8 ++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/gateway-conformance.yml b/.github/workflows/gateway-conformance.yml index 8d2f9fe4..921b8000 100644 --- a/.github/workflows/gateway-conformance.yml +++ b/.github/workflows/gateway-conformance.yml @@ -7,9 +7,16 @@ on: pull_request: workflow_dispatch: +env: + GATEWAY_CONFORMANCE_VERSION: '7b222e6a73b82f05651aec3824ef139628198949' # TODO: switch to v0.6 + jobs: gateway-conformance: runs-on: ubuntu-latest + strategy: + matrix: + # We have to use matrix because 'uses' does not support env interpolation directly + version: [${{ env.GATEWAY_CONFORMANCE_VERSION || 'latest' }}] steps: # 1, Setup Node, install npm dependencies, and build all packages/* # see https://github.com/ipdxco/unified-github-workflows/blob/3a1a7870ce5967163d8f5c8210b8ad50b2e659aa/.github/workflows/js-test-and-release.yml#L28-L34 @@ -23,12 +30,12 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: 1.21.x + go-version: 1.22.x # 3. Download the gateway-conformance fixtures using ipfs/gateway-conformance action # This will prevent us from needing to install `docker` on the github runner - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.5.1 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@{{ matrix.version }} # working-directory: ./packages/gateway-conformance with: output: ./packages/gateway-conformance/dist/src/fixtures/data/gateway-conformance-fixtures diff --git a/packages/gateway-conformance/src/conformance.spec.ts b/packages/gateway-conformance/src/conformance.spec.ts index c59d0db8..101ca9d2 100644 --- a/packages/gateway-conformance/src/conformance.spec.ts +++ b/packages/gateway-conformance/src/conformance.spec.ts @@ -9,6 +9,9 @@ import { Agent, setGlobalDispatcher } from 'undici' const logger = prefixLogger('gateway-conformance') +// The version used in CI check is set in .github/workflows/gateway-conformance.yml +const GATEWAY_CONFORMANCE_VERSION = process.env.GATEWAY_CONFORMANCE_VERSION ?? 'latest' + interface TestConfig { name: string spec?: string @@ -316,7 +319,7 @@ describe('@helia/verified-fetch - gateway conformance', function () { log('Using custom gateway-conformance binary at %s', binaryPath) return } - const { stdout, stderr } = await execa('go', ['install', 'github.com/ipfs/gateway-conformance/cmd/gateway-conformance@latest'], { reject: true }) + const { stdout, stderr } = await execa('go', ['install', `github.com/ipfs/gateway-conformance/cmd/gateway-conformance@${GATEWAY_CONFORMANCE_VERSION}`], { reject: true }) log(stdout) log.error(stderr) }) diff --git a/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts b/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts index 8a88c6bc..d1dd81aa 100644 --- a/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts +++ b/packages/gateway-conformance/src/fixtures/kubo-mgmt.ts @@ -53,7 +53,7 @@ function getExecaOptions ({ cwd, ipfsNsMap, kuboRepoDir }: { cwd?: string, ipfsN async function downloadFixtures (force = false): Promise { if (!force) { // if the fixtures are already downloaded, we don't need to download them again - const allFixtures = await fg.glob([`${GWC_FIXTURES_PATH}/**/*.car`, `${GWC_FIXTURES_PATH}/**/*.ipns-record`, `${GWC_FIXTURES_PATH}/dnslinks.json`]) + const allFixtures = await fg.glob([`${GWC_FIXTURES_PATH}/**/*.car`, `${GWC_FIXTURES_PATH}/**/*.ipns-record`, `${GWC_FIXTURES_PATH}/dnslinks.IPFS_NS_MAP`]) if (allFixtures.length > 0) { log('Fixtures already downloaded') return @@ -106,11 +106,7 @@ export async function loadFixtures (kuboRepoDir: string): Promise { await datastore.put(dhtKey, dhtRecord.serialize()) } - const json = await readFile(`${GWC_FIXTURES_PATH}/dnslinks.json`, 'utf-8') - const { subdomains, domains } = JSON.parse(json) - const subdomainDnsLinks = Object.entries(subdomains).map(([key, value]) => `${key}.localhost%3A${3441}:${value}`).join(',') - const domainDnsLinks = Object.entries(domains).map(([key, value]) => `${key}:${value}`).join(',') - const ipfsNsMap = `${domainDnsLinks},${subdomainDnsLinks}` + const ipfsNsMap = await readFile(`${GWC_FIXTURES_PATH}/dnslinks.IPFS_NS_MAP`, 'utf-8') return ipfsNsMap }