Skip to content

Commit

Permalink
feat(v3): update to version 3 of Dorametrix usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelvesavuori committed Jun 11, 2023
1 parent 5795602 commit c699f62
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
35 changes: 1 addition & 34 deletions deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit c699f62

Please sign in to comment.