Ignore build step ignores content changes too #285
Replies: 8 comments 19 replies
|
Or could there be maybe a system environment variable that one could use to detect in the ignore-script whether this was triggered by a certain deployment hook and then always build, ignoring the type of the latest code changes? |
|
Is there any update on this? Have you guys figured any workarounds? |
|
We have the same problem with our monorepo. |
|
I have contacted vercel support. |
|
This seems to be still an issue, making Of course one could rely on the Vercel CLI only, but I find the GitHub deploy hooks very approachable, when called from CMS. We have a different workaround now. We just spun up a small Redis DB at upstash.com, which is free and set/check the flag there, calling #!/bin/sh
# control-vercel-deployments.sh
if [ $# -lt 2 ]
then
echo "Not enough arguments provided. Provide \"ENABLE\" or \"CHECK\" commands and the Vercel project to control deployment."
# Vercel considers exit code 0 as "no deployment necessary"
# See here: https://vercel.com/docs/platform/projects#ignored-build-step
exit 0
fi
case $1 in
CHECK)
echo "Checking if Vercel deployment for project \"$2\" is currently allowed."
DEPLOYMENT_FLAG=$(curl -s "$UPSTASH_DATABASE_URL/get/$2" -H "Authorization: Bearer $UPSTASH_BEARER_TOKEN")
echo "DEPLOYMENT_FLAG: $DEPLOYMENT_FLAG"
if [ "$DEPLOYMENT_FLAG" = '{"result":null}' ]; then
echo "DEPLOYMENT_FLAG is not set. Deployment not allowed."
exit 0
elif [ "$DEPLOYMENT_FLAG" = '{"result":"true"}' ]; then
echo "DEPLOYMENT_FLAG is set. Deployment allowed. Deleting flag."
DELETION_RESPONSE=$(curl -s "$UPSTASH_DATABASE_URL/del/$2" -H "Authorization: Bearer $UPSTASH_BEARER_TOKEN")
if [ "$DELETION_RESPONSE" = '{"result":1}' ]; then
echo "Flag successfully deleted after check."
fi
# Vercel considers exit code 1 as "deployment needed"
exit 1
else
echo "DEPLOYMENT_FLAG contains invalid value. Deleting it and aborting."
curl -s "$UPSTASH_DATABASE_URL/del/$2" -H "Authorization: Bearer $UPSTASH_BEARER_TOKEN"
exit 0
fi
;;
ENABLE)
echo "Enabling Vercel deployment for project \"$2\" by setting DEPLOYMENT_FLAG."
RESPONSE=$(curl -s "$UPSTASH_DATABASE_URL/set/$2/true" -H "Authorization: Bearer $UPSTASH_BEARER_TOKEN")
echo "RESPONSE: $RESPONSE"
exit 0
;;
*)
echo "First argument must be CHECK or ENABLE."
exit 0
;;
esac |
|
This solution works well for us! You just need a Vercel API access token. // vercel-ignore-build.js
const https = require("https");
let vercelEnv = process.env.VERCEL_ENV;
const options = {
hostname: 'api.vercel.com',
port: 443,
path: '/v5/now/deployments?limit=5&teamId=[YOUR_TEAM_ID]',
method: 'GET',
headers: {
'Authorization': `Bearer ${process.env.VERCEL_API_ACCESS_TOKEN}`
}
}
let data = '';
const req = https.request(options, res => {
res.on('data', d => {
data += d.toString();
})
res.on('end', d => {
let parsedData = JSON.parse(data);
let prodRunningFromDeployHook;
try {
prodRunningFromDeployHook = parsedData.deployments.find(({state, meta, target}) => state === 'BUILDING' && target === 'production' && meta.deployHookId === '[YOUR_DEPLOY_HOOK_ID]')
} catch(e) {
console.log('e: ', e);
process.exit(0);
}
if (vercelEnv === 'production' && !prodRunningFromDeployHook) {
console.log('🛑 - Build cancelled');
process.exit(0);
} else {
console.log('✅ - Build can proceed');
process.exit(1);
}
})
})
req.on('error', error => {
console.error(error)
})
req.end()Alternatively you could use |
|
There has got to be a simpler solution to this? This seems like a fairly common use case and would be solved with an environment variable such as Going with the highlighted workaround for now, but would love to have a native ability to do this! |
|
Any updates on this? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
It is recommended to set the ignore-build-step-configuration for monorepos to something like
git diff HEAD^ HEAD --quiet frontend/to run only on changes, that affect the directoryfrontend.Similar provisions are necessary for some CI/CD pipelines too.
Now if the latest commit, say for example "API change xyz..." was in the folder
/api, the build is skipped. If we now have a content update in our CMS or API-Backend and trigger a SSG-rebuild at Vercel via deploy hook, this deployment is skipped, because of the last code update being in another part of the monorepo and all subsequent deploy hook calls (content changes) will be skipped until a new commit affectsfrontendagain.This can't be intentional, can it?
All reactions