-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix: move files to build cache after files are uploaded instead of copying them before uploads #753
Changes from 13 commits
1844993
0deac07
d1154ad
9fbce46
083fc2f
cb01d0c
a82a6a5
482a491
a60b5d7
30ecbf5
4bd1abb
7f6b7d7
1f942aa
16bed3d
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ jobs: | |
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '*' | ||
node-version: '18' | ||
- name: Global Node packages cache | ||
uses: actions/cache@v3 | ||
with: | ||
|
@@ -29,7 +29,7 @@ jobs: | |
key: | ||
ubuntu-build-${{ env.cache-name }}-${{ | ||
hashFiles('plugin/test/fixtures/**/package.json') }}-node-modules | ||
- run: npm install -g netlify-cli | ||
- run: npm install -g netlify-cli@18.0.0 | ||
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. there seems to be regression in latest version of cli (18.0.1) that result in skipping rewrites to I suspect it's caused by netlify/cli#6994 and reported in https://netlify.slack.com/archives/C07686YAY13/p1737134106866159?thread_ts=1736521386.323879&cid=C07686YAY13 |
||
- run: npm ci | ||
- run: cd plugin && npm ci && npm run build | ||
- run: npm test | ||
|
@@ -56,7 +56,7 @@ jobs: | |
key: | ||
macOS-build-${{ env.cache-name }}-${{ | ||
hashFiles('plugin/test/fixtures/**/package.json') }}-node-modules | ||
- run: npm install -g netlify-cli | ||
- run: npm install -g netlify-cli@18.0.0 | ||
- run: npm ci | ||
- run: cd plugin && npm ci && npm run build | ||
- run: npm test |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ export async function onPreBuild({ | |
constants, | ||
utils, | ||
netlifyConfig, | ||
}): Promise<void> { | ||
}: NetlifyPluginOptions): Promise<void> { | ||
const { PUBLISH_DIR } = constants | ||
// Print a helpful message if the publish dir is misconfigured | ||
if (!PUBLISH_DIR || process.cwd() === path.resolve(PUBLISH_DIR)) { | ||
|
@@ -115,14 +115,11 @@ The plugin no longer uses this and it should be deleted to avoid conflicts.\n`) | |
|
||
export async function onPostBuild({ | ||
constants: { PUBLISH_DIR, FUNCTIONS_DIST }, | ||
utils, | ||
}): Promise<void> { | ||
}: NetlifyPluginOptions): Promise<void> { | ||
if (shouldSkip(PUBLISH_DIR)) { | ||
return | ||
} | ||
|
||
await saveCache({ publish: PUBLISH_DIR, utils }) | ||
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. Now that we are moving the cache around, not just copying, if we only save the cache on successful builds are we essentially clearing the cache on failed build? Is it potentially worth keeping this save cache here? 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. Thanks for catching this - I spent most time on this PR fixing tests (after not touching this repo for months) and this did slip. Overall I don't want to introduce changes to failed builds behavior, so I'm gonna investigate what is exact behavior now (wether we store or not cache on failed builds) and ensure this behavior is preserved 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. Ok. There might be separate thing here to maybe start storing cache on failed builds, but this is out of scope for this PR. 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. Ahh, I think I missed what the most important bit here - when we restore cache - we now move the files out and not just copy them - so if build fails - the cache location no longer has original cache files which would possibly result in subsequent build losing any of previous caches. The part I'm not sure about is wether we do upload that cache on failed builds and will look into that now 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. It seems like we don't actually store cache from cache location on failed builds either, so this is still preserving the behavior. BuildBot build command stage would fail on build failure and this would result in subsequent stages not running anymore (save cache is one of last stages after build command) |
||
|
||
const cacheDir = normalizedCacheDir(PUBLISH_DIR) | ||
|
||
const neededFunctions = await getNeededFunctions(cacheDir) | ||
|
@@ -132,11 +129,16 @@ export async function onPostBuild({ | |
} | ||
} | ||
|
||
export async function onSuccess({ constants: { PUBLISH_DIR } }) { | ||
export async function onSuccess({ | ||
constants: { PUBLISH_DIR }, | ||
utils, | ||
}: NetlifyPluginOptions) { | ||
if (shouldSkip(PUBLISH_DIR)) { | ||
return | ||
} | ||
|
||
await saveCache({ publish: PUBLISH_DIR, utils }) | ||
|
||
// Pre-warm the lambdas as downloading the datastore file can take a while | ||
if (shouldSkipBundlingDatastore()) { | ||
const FETCH_TIMEOUT = 5000 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,7 @@ exports.runTests = function runTests(env, host) { | |
expect(result).toEqual({ | ||
amIJSON: true, | ||
}) | ||
expect(res.headers.get('content-type')).toEqual('application/json') | ||
expect(res.headers.get('content-type')).toMatch(/^application\/json/) | ||
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. Just out of curiosity, is this just a preference or is there a hidden reason for this change? 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 was seeing those assertion failures ( https://github.com/netlify/netlify-plugin-gatsby/actions/runs/12813658707/job/35728241714#step:9:1832 )
so I adjusted assertions to ensure |
||
}) | ||
test(`returns json correctly via send`, async () => { | ||
const res = await fetchTwice(`${host}/api/i-am-json-too`) | ||
|
@@ -124,14 +124,14 @@ exports.runTests = function runTests(env, host) { | |
expect(result).toEqual({ | ||
amIJSON: true, | ||
}) | ||
expect(res.headers.get('content-type')).toEqual('application/json') | ||
expect(res.headers.get('content-type')).toMatch(/^application\/json/) | ||
}) | ||
test(`returns boolean correctly via send`, async () => { | ||
const res = await fetchTwice(`${host}/api/i-am-false`) | ||
const result = await res.json() | ||
|
||
expect(result).toEqual(false) | ||
expect(res.headers.get('content-type')).toEqual('application/json') | ||
expect(res.headers.get('content-type')).toMatch(/^application\/json/) | ||
}) | ||
test(`returns status correctly via send`, async () => { | ||
const res = await fetchTwice(`${host}/api/i-am-status`) | ||
|
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.
gatsby v3 which is tested doesn't work on newer nodes - https://github.com/netlify/netlify-plugin-gatsby/actions/runs/12812982624/job/35725952139#step:9:950