Skip to content

Instantly share code, notes, and snippets.

@sdjnes
Created December 20, 2022 15:07
Show Gist options
  • Save sdjnes/a600b68322ca163d2cea17c2ec138a20 to your computer and use it in GitHub Desktop.
Save sdjnes/a600b68322ca163d2cea17c2ec138a20 to your computer and use it in GitHub Desktop.
#!/bin/bash
GITHUB_ORG=""
GITHUB_REPO=""
# If the commit message contains [skip ci] then don't run
if [[ "$VERCEL_GIT_COMMIT_MESSAGE" == *"[skip ci]"* ]]; then
echo "⏭️ skipping ([skip ci] in commit message)"
exit 0
fi
# If these are the same then a manual redeploy was run
if [[ ! -z "$VERCEL_GIT_PREVIOUS_SHA" && ! -z "$VERCEL_GIT_COMMIT_SHA" && "$VERCEL_GIT_PREVIOUS_SHA" == "$VERCEL_GIT_COMMIT_SHA" ]]; then
echo "🔄 redeploying"
exit 1
fi
# Add git repo origin
echo "Adding origin"
git remote add origin https://[email protected]/$GITHUB_ORG/$GITHUB_REPO
echo "Fetching origin/main"
# Get a sensible number of commits from main so it's not slow
git fetch origin main --depth=30
echo "Calculating base"
# For the base to compare changes against, use the last built commit hash as long as it exists in the git tree ("git cat-file -e...")
# Otherwise use main as the base
BASE=$([[ ! -z "$VERCEL_GIT_PREVIOUS_SHA" ]] && git cat-file -e $VERCEL_GIT_PREVIOUS_SHA && echo $VERCEL_GIT_PREVIOUS_SHA || echo "origin/main")
# Take the project name from the CLI arguments
PROJECT=$1
echo "Base: $BASE"
echo "Project: $PROJECT"
npx nx-ignore $PROJECT --base=$BASE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment