This tool helps with the process of collecting commits and sending them to Sentry as a new release while deploying from Laravel Envoyer.
Sentry can associate a series of git commits to a release by providing a starting hash and ending hash. With Envoyer it can be a bit tricky since the .git
repository isn't deployed with the site. By using the following combination of deployment hooks we are able to capture the two required hashes and gain the benefits of commit tracking in Sentry.
composer require zaengle/envoyer-sentry-release-notifier
Inside your config/sentry.php
file add the getCommitHash()
helper provided by this package.
<?php
use Zaengle\EnvoyerSentryReleaseNotifier\EnvoyerSentryReleaseNotifier;
return [
// capture release as git sha
'release' => app(EnvoyerSentryReleaseNotifier::class)->getCommitHash(),
// rest of config...
];
Once your project is set up with Sentry, add the following deployment hooks to Envoyer. You will need to run one deployment with only the Write Git Hash
hook enabled so that your initial .commit_hash
file will be present for future releases.
After Envoyer activates a new release we need to write the hash to a file so it's available for the next release, where it will be used as the commit_hash_previous
"
echo "{{ sha }}" > {{release}}/.commit_hash
NOTE - This command will need to be run one time before activating any of the other hooks so the initial .commit_hash
file is created for subsequent steps.
yes | cp -f {{project}}/current/.commit_hash {{release}}/.commit_hash_previous
echo "{{ sha }}" > {{release}}/.commit_hash
export SENTRY_BEARER_TOKEN="MyBearerToken"
export SENTRY_PROJECT="my-sentry-project-name"
export ENVIRONMENT="develop"
export PREVIOUS_SHA=`tail {{release}}/.commit_hash_previous`
cd {{ release }}
curl https://sentry.io/api/0/organizations/zaengle/releases/ \
-H "Authorization: Bearer ${SENTRY_BEARER_TOKEN}" \
-X POST \
-H "Content-Type:application/json" \
-d "{
\"environment\":\"${ENVIRONMENT}\",
\"version\":\"{{sha}}\",
\"refs\":[{
\"repository\":\"zaengle/my-repository-name\",
\"commit\":\"{{sha}}\",
\"previousCommit\": \"${PREVIOUS_SHA}\"
}],
\"projects\": [\"my-sentry-project-name\"]
}"
curl https://sentry.io/api/0/organizations/zaengle/releases/{{sha}}/deploys/ \
-X POST \
-H "Authorization: Bearer ${SENTRY_BEARER_TOKEN}" \
-H 'Content-Type: application/json' \
-d "
{
\"environment\": \"${ENVIRONMENT}\",
\"name\": \"{{release}}\"
}"
The MIT License (MIT). Please see License File for more information.