Skip to content

Instantly share code, notes, and snippets.

@balanza
Last active October 20, 2020 22:40
Show Gist options
  • Save balanza/75af6df1df1e514bd38c0a983e888a9e to your computer and use it in GitHub Desktop.
Save balanza/75af6df1df1e514bd38c0a983e888a9e to your computer and use it in GitHub Desktop.
Given a repo, check which commit were added to master after the last release
#!/bin/bash
bold=$(tput bold)
normal=$(tput sgr0)
# project name
REPO=$1
# github owner
GH_ORG=$2
# azure devops organization
AZ_ORG=$3
if [ -z "$AZ_ORG" ]; then
LATEST=v$(curl "https://raw.githubusercontent.com/$GH_ORG/$REPO/master/package.json" | jq .version | sed 's/"//g')
SOURCE="the current version in package.json"
else
LATEST=$(curl -Ls "https://dev.azure.com/$AZ_ORG/$REPO/_apis/build/builds?api-version=5.0&statusFilter=completed&resultFilter=succeeded" | jq '[.value[] | select(.sourceBranch=="refs/heads/master") | .sourceVersion ][0]' | sed 's/"//g')
SOURCE="the latest successful build on master branch"
fi
ITEMS=$(curl -Ls https://api.github.com/repos/$GH_ORG/$REPO/compare/$LATEST...master | jq ".commits[].commit.message" | sed 's/"//g' | sed 's/^/ • /g')
if [ -z "$ITEMS" ]; then
echo " ${bold}$REPO${normal} has no changes to be deployed."
else
echo " ${bold}$REPO${normal} has the following changes waiting to be deployed:"
echo "$ITEMS"
fi
echo ""
echo " latest version is ${bold}$LATEST${normal} calculated as ${bold}$SOURCE${normal}"
@balanza
Copy link
Author

balanza commented Oct 20, 2020

Usage

for project deployed using azure pipelines

bash <(curl -Ls https://gist.githubusercontent.com/balanza/75af6df1df1e514bd38c0a983e888a9e/raw/checkupdates.sh) repo github_owner azure_org

for project deployed without azure pipelines

bash <(curl -Ls https://gist.githubusercontent.com/balanza/75af6df1df1e514bd38c0a983e888a9e/raw/checkupdates.sh) repo github_owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment