-
-
Save SoftCreatR/e5d3771a56c840db63340d7981f16609 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# === Configuration === | |
GITHUB_USER="USER" | |
REPO_NAME="REPO" | |
BRANCH="main" | |
LAST_COMMIT_FILE=".last_commit" | |
# GitHub API URL for the branch | |
GIT_URL="https://github.com/${GITHUB_USER}/${REPO_NAME}.git" | |
# Fetch the latest remote SHA | |
LATEST_COMMIT_SHA=$(git ls-remote "$GIT_URL" "$BRANCH" | awk '{print $1}') | |
if [[ -z "$LATEST_COMMIT_SHA" ]]; then | |
echo "Error: couldn't retrieve SHA" | |
exit 1 | |
fi | |
# If no SHA is stored yet, store it and notify | |
if [[ ! -f "$LAST_COMMIT_FILE" ]]; then | |
echo "$LATEST_COMMIT_SHA" > "$LAST_COMMIT_FILE" | |
echo "First run – Commit SHA stored: $LATEST_COMMIT_SHA" | |
exit 0 | |
fi | |
# Load previously known SHA | |
LAST_KNOWN_COMMIT=$(<"$LAST_COMMIT_FILE") | |
# Compare | |
if [[ "$LATEST_COMMIT_SHA" != "$LAST_KNOWN_COMMIT" ]]; then | |
echo "New commit found: $LATEST_COMMIT_SHA" | |
echo "$LATEST_COMMIT_SHA" > "$LAST_COMMIT_FILE" | |
else | |
echo "No new commit – everything is up to date." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment