diff --git a/deployment.sh b/deployment.sh index 63f1475..5f2f1e8 100755 --- a/deployment.sh +++ b/deployment.sh @@ -31,40 +31,7 @@ if [ -z "$REPO" ]; then echo "Dorametrix error: REPO is not set! Exiting..." && CURRENT_GIT_SHA=$(git log --pretty=format:'%H' -n 1) echo "ℹ️ CURRENT_GIT_SHA --> $CURRENT_GIT_SHA" -# Get commit ID of last production deployment -LAST_PROD_DEPLOY=$(curl "$ENDPOINT/lastdeployment?product=$REPO_NAME" -H 'Authorization: "$API_KEY"' | jq '.id' -r) - -# If no LAST_PROD_DEPLOY is found, then very defensively assume that the first commit is most recent deployment -if [[ -z "$LAST_PROD_DEPLOY" ]] || [[ "$LAST_PROD_DEPLOY" == "null" ]]; then - echo "⚠️ Dorametrix warning: Could not find a value for LAST_PROD_DEPLOY. Setting LAST_PROD_DEPLOY to the value of the first commit." - LAST_PROD_DEPLOY=$(git rev-list HEAD | tail -n 1) -fi -echo "ℹ️ LAST_PROD_DEPLOY --> $LAST_PROD_DEPLOY" - -echo "Verifying that commits exist..." -if ! git --no-pager log $LAST_PROD_DEPLOY..$CURRENT_GIT_SHA --decorate=short --pretty=oneline; then - echo "🔥 Dorametrix error: Unable to find the expected commits in working tree! Exiting..." - exit 1 -fi - -# Get all commits between current work and last production deployment then put result in local TXT file -git log $LAST_PROD_DEPLOY..$CURRENT_GIT_SHA --pretty=format:'{%n ^^^^id^^^^: ^^^^%H^^^^,%n ^^^^timeCreated^^^^: ^^^^%ct^^^^%n },' | sed 's/"/\\"/g' | sed 's/\^^^^/"/g' | sed "$ s/,$//" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' | awk 'BEGIN { print("[") } { print($0) } END { print("]") }' >commits.json - -# Use TXT output to set variable with list of commits -CHANGES=$(cat commits.json | jq '[.[] | { id: .id, timeCreated: .timeCreated }]') -echo "ℹ️ CHANGES --> $CHANGES" -CHANGES_LENGTH=$(echo $CHANGES | jq '. | length' -r) -echo "ℹ️ CHANGES_LENGTH --> $CHANGES_LENGTH" - -# Remove the scratch TXT file -rm commits.json - -if [[ $CHANGES_LENGTH -eq 0 ]]; then - echo "🔥 Dorametrix error: No changes detected. Exiting..." - exit 1 -fi - # Call Dorametrix and create deployment event with Git changes -curl -X POST $ENDPOINT/event?authorization="$API_KEY" -d '{ "eventType": "deployment", "repo": "'$REPO_NAME'", "changes": '"$CHANGES"' }' -H "Content-Type: application/json" +curl -X POST $ENDPOINT/event?authorization="$API_KEY" -d '{ "eventType": "deployment", "repo": "'$REPO_NAME'", "changeSha": '"$CURRENT_GIT_SHA"' }' -H "Content-Type: application/json" echo -e "\n✅ Dorametrix deployment script has finished successfully!" diff --git a/package.json b/package.json index bd5868e..12cc418 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dorametrix-action", - "version": "1.0.0", + "version": "3.0.0", "description": "Conveniently create a deployment event in Dorametrix.", "main": "deployment.sh", "homepage": "https://github.com/mikaelvesavuori/dorametrix-action",