-
Notifications
You must be signed in to change notification settings - Fork 83
feat: write metadata file #5875
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
Changes from all commits
0886925
49fcc66
78066cd
d4af2d2
607f14f
3591097
616511d
1cdda62
ad595f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default async () => new Response("Hello") | ||
|
|
||
| export const config = { path: "/hello" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { readdir, readFile, rm, stat, writeFile } from 'fs/promises' | ||
| import { resolve } from 'path' | ||
| import { join, resolve } from 'path' | ||
| import { version as nodeVersion } from 'process' | ||
| import { fileURLToPath } from 'url' | ||
|
|
||
| import { Fixture, normalizeOutput, removeDir, getTempName } from '@netlify/testing' | ||
| import { Fixture, normalizeOutput, removeDir, getTempName, unzipFile } from '@netlify/testing' | ||
| import test from 'ava' | ||
| import { pathExists } from 'path-exists' | ||
| import semver from 'semver' | ||
|
|
@@ -204,3 +204,39 @@ if (semver.gte(nodeVersion, '16.9.0')) { | |
| t.true(app2FunctionsDist.includes('worker.zip')) | ||
| }) | ||
| } | ||
|
|
||
| test('Functions: creates metadata file', async (t) => { | ||
| const fixture = await new Fixture('./fixtures/v2').withCopyRoot({ git: false }) | ||
| const build = await fixture | ||
| .withFlags({ | ||
| branch: 'my-branch', | ||
| cwd: fixture.repositoryRoot, | ||
| featureFlags: { zisi_add_metadata_file: true }, | ||
| }) | ||
| .runWithBuildAndIntrospect() | ||
|
|
||
| t.true(build.success) | ||
|
|
||
| const functionsDistPath = resolve(fixture.repositoryRoot, '.netlify/functions') | ||
| const functionsDistFiles = await readdir(functionsDistPath) | ||
|
|
||
| t.true(functionsDistFiles.includes('manifest.json')) | ||
| t.true(functionsDistFiles.includes('test.zip')) | ||
|
|
||
| const unzipPath = join(functionsDistPath, `.netlify-test-${Date.now()}`) | ||
|
|
||
| await unzipFile(join(functionsDistPath, 'test.zip'), unzipPath) | ||
|
|
||
| const functionFiles = await readdir(unzipPath) | ||
|
|
||
| t.true(functionFiles.includes('___netlify-bootstrap.mjs')) | ||
| t.true(functionFiles.includes('___netlify-entry-point.mjs')) | ||
| t.true(functionFiles.includes('___netlify-metadata.json')) | ||
| t.true(functionFiles.includes('test.mjs')) | ||
|
|
||
| const metadata = JSON.parse(await readFile(join(unzipPath, '___netlify-metadata.json'), 'utf8')) | ||
|
|
||
| t.is(semver.valid(metadata.bootstrap_version), metadata.bootstrap_version) | ||
| t.is(metadata.branch, 'my-branch') | ||
| t.is(metadata.version, 1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should we also delete the unzipped file? or will it get cleaned up eventually?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these directories are being cleaned up at the moment. I think that's okay since in the context of an ephemeral CI it sometimes does more harm than good, as you need to spend time deleting a bunch of files. I think it would be nice to do it optionally for a local dev setup, but I'd rather handle that more holistically as part of the Something for us to consider! |
||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { mkdir } from 'fs/promises' | ||
| import { platform } from 'process' | ||
|
|
||
| import { execa } from 'execa' | ||
|
|
||
| export const unzipFile = async function (path: string, dest: string): Promise<void> { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've extracted this function from
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to update |
||
| await mkdir(dest, { recursive: true }) | ||
|
|
||
| if (platform === 'win32') { | ||
| await execa('tar', ['-xf', path, '-C', dest]) | ||
| } else { | ||
| await execa('unzip', ['-o', path, '-d', dest]) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export interface MetadataFile { | ||
| bootstrap_version?: string | ||
| branch?: string | ||
| version: number | ||
| } | ||
|
|
||
| export const getMetadataFile = (bootstrapVersion?: string, branch?: string): MetadataFile => ({ | ||
| bootstrap_version: bootstrapVersion, | ||
| branch, | ||
| version: 1, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really related to the metadata file, but it's good to use the imported types from zip-it-and-ship-it.