From 62157895525962818cf21a34382f7aee2cbef04c Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Fri, 5 Dec 2025 21:44:53 +1100 Subject: [PATCH] Updated notification variables. --- .lagoon.yml | 6 +++++ .../docs/content/workflows/notifications.mdx | 25 +++++++++++++++++ .vortex/docs/content/workflows/variables.mdx | 15 +++++++---- .../hooks/library/notify-deployment.sh | 4 +++ .../hosting_lagoon/.lagoon.yml | 6 +++++ .../hooks/library/notify-deployment.sh | 4 +++ .../hosting_project_name___lagoon/.lagoon.yml | 6 +++++ .../provision_database_lagoon/.lagoon.yml | 6 +++++ .vortex/tests/bats/unit/notify-email.bats | 15 ++++++++--- .vortex/tests/bats/unit/notify-github.bats | 21 +++++++++++++-- .vortex/tests/bats/unit/notify-jira.bats | 6 +++++ .vortex/tests/bats/unit/notify-newrelic.bats | 6 +++++ .vortex/tests/bats/unit/notify-slack.bats | 21 +++++++++++++-- .vortex/tests/bats/unit/notify-webhook.bats | 8 ++++++ .vortex/tests/bats/unit/notify.bats | 6 +++++ .../tests/manual/try-email-notification.sh | 7 ++++- .../tests/manual/try-github-notification.sh | 14 +++++----- .vortex/tests/manual/try-jira-notification.sh | 7 ++++- .../tests/manual/try-newrelic-notification.sh | 9 +++++-- .../tests/manual/try-slack-notification.sh | 7 ++++- .../tests/manual/try-webhook-notification.sh | 7 ++++- hooks/library/notify-deployment.sh | 4 +++ scripts/vortex/notify-github.sh | 14 +++++----- scripts/vortex/notify-jira.sh | 9 ++++--- scripts/vortex/notify-newrelic.sh | 20 +++++++++----- scripts/vortex/notify.sh | 27 ++++++++++++++++++- 26 files changed, 239 insertions(+), 41 deletions(-) diff --git a/.lagoon.yml b/.lagoon.yml index 5207db64e..8eff54155 100644 --- a/.lagoon.yml +++ b/.lagoon.yml @@ -27,6 +27,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=pre_deployment @@ -92,6 +95,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=post_deployment diff --git a/.vortex/docs/content/workflows/notifications.mdx b/.vortex/docs/content/workflows/notifications.mdx index df3ac6f23..3f94bb605 100644 --- a/.vortex/docs/content/workflows/notifications.mdx +++ b/.vortex/docs/content/workflows/notifications.mdx @@ -36,6 +36,31 @@ channel-specific settings. | `VORTEX_NOTIFY_PROJECT` | No | `VORTEX_PROJECT` | `.env` | Notification project name | | `VORTEX_NOTIFY_SKIP` | No | | Hosting | Notification skip flag (set to `1` to skip notifications) | +## Deployment context variables + +These variables provide deployment context information used by notification +channels. They must be set by the hosting environment (e.g., Lagoon, Acquia) +before calling the notification script. + +| Variable | Required | Description | +|---------------------------|----------|-----------------------------------------------------------------| +| `VORTEX_NOTIFY_BRANCH` | **Yes** | Git branch name (used for GitHub API and JIRA issue extraction) | +| `VORTEX_NOTIFY_SHA` | **Yes** | Git commit SHA (used for New Relic revision tracking) | +| `VORTEX_NOTIFY_PR_NUMBER` | No | Pull request number (empty for branch deployments) | +| `VORTEX_NOTIFY_LABEL` | **Yes** | Human-readable deployment label for display | + +### Branch vs PR deployment examples + +The following table shows how these variables differ between branch and PR deployments: + +| Variable | Branch deployment | PR deployment | +|----------------------------|-----------------------------|-----------------------------------| +| `VORTEX_NOTIFY_BRANCH` | `main` | `feature/PROJ-123-add-feature` | +| `VORTEX_NOTIFY_SHA` | `abc123def456` | `def789abc012` | +| `VORTEX_NOTIFY_PR_NUMBER` | *(empty)* | `123` | +| `VORTEX_NOTIFY_LABEL` | `main` | `PR-123` | + + ## Message templates and tokens Most notification channels support customizable message templates using replacement tokens: diff --git a/.vortex/docs/content/workflows/variables.mdx b/.vortex/docs/content/workflows/variables.mdx index cf575cc06..23def63cd 100644 --- a/.vortex/docs/content/workflows/variables.mdx +++ b/.vortex/docs/content/workflows/variables.mdx @@ -257,6 +257,7 @@ The list below is automatically generated with [Shellvar](https://github.com/ale | `VORTEX_LAGOONCLI_PATH` | Location of the Lagoon CLI binary. | `/tmp` | `scripts/vortex/deploy-lagoon.sh`, `scripts/vortex/task-custom-lagoon.sh` | | `VORTEX_LAGOONCLI_VERSION` | Lagoon CLI version to use. | `v0.32.0` | `scripts/vortex/deploy-lagoon.sh`, `scripts/vortex/task-custom-lagoon.sh` | | `VORTEX_LAGOON_PRODUCTION_BRANCH` | Dedicated branch to identify the production environment. | `main` | `.env` | +| `VORTEX_NOTIFY_BRANCH` | Notification git branch name. | `UNDEFINED` | `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_CHANNELS` | The channels of the notifications.

A combination of comma-separated values: email,slack,newrelic,github,jira,webhook | `email` | `.env`, `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_EMAIL_ENVIRONMENT_URL` | Email notification environment URL. | `${VORTEX_NOTIFY_ENVIRONMENT_URL}` | `scripts/vortex/notify-email.sh` | | `VORTEX_NOTIFY_EMAIL_EVENT` | Email notification event type. Can be 'pre_deployment' or 'post_deployment'. | `post_deployment` | `scripts/vortex/notify-email.sh` | @@ -268,24 +269,25 @@ The list below is automatically generated with [Shellvar](https://github.com/ale | `VORTEX_NOTIFY_EMAIL_RECIPIENTS` | Email address(es) to send notifications to.

Applies to email notifications.

Multiple names can be specified as a comma-separated list of email addresses with optional names in the format "email|name". Example: "to1@example.com|Jane Doe, to2@example.com|John Doe" | `webmaster@your-site-domain.example|Webmaster` | `.env`, `scripts/vortex/notify-email.sh` | | `VORTEX_NOTIFY_ENVIRONMENT_URL` | Notification environment URL (where the site was deployed). | `UNDEFINED` | `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_EVENT` | Notification event type.

Can be 'pre_deployment' or 'post_deployment'. | `post_deployment` | `scripts/vortex/notify.sh` | +| `VORTEX_NOTIFY_GITHUB_BRANCH` | GitHub notification git branch name. This will be used as the 'ref' parameter in GitHub's Deployment API. | `${VORTEX_NOTIFY_BRANCH}` | `scripts/vortex/notify-github.sh` | | `VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE` | GitHub notification environment type: production, uat, dev, pr. Used as the 'environment' parameter in GitHub's Deployment API. | `PR` | `scripts/vortex/notify-github.sh` | | `VORTEX_NOTIFY_GITHUB_ENVIRONMENT_URL` | GitHub notification deployment environment URL. | `${VORTEX_NOTIFY_ENVIRONMENT_URL}` | `scripts/vortex/notify-github.sh` | | `VORTEX_NOTIFY_GITHUB_EVENT` | GitHub notification event type. Can be 'pre_deployment' or 'post_deployment'. | `${VORTEX_NOTIFY_EVENT}` | `scripts/vortex/notify-github.sh` | -| `VORTEX_NOTIFY_GITHUB_LABEL` | GitHub notification deployment label (branch name, PR number, or custom identifier). This will be used as the 'ref' parameter in GitHub's Deployment API. | `${VORTEX_NOTIFY_LABEL}` | `scripts/vortex/notify-github.sh` | | `VORTEX_NOTIFY_GITHUB_REPOSITORY` | GitHub notification repository in owner/repo format. | `UNDEFINED` | `scripts/vortex/notify-github.sh` | | `VORTEX_NOTIFY_GITHUB_TOKEN` | GitHub notification personal access token. | `${GITHUB_TOKEN}` | `scripts/vortex/notify-github.sh`, `ACQUIA ENVIRONMENT`, `LAGOON ENVIRONMENT` | | `VORTEX_NOTIFY_JIRA_ASSIGNEE_EMAIL` | JIRA notification assignee email address.

If left empty - no assignment will be performed. | `UNDEFINED` | `scripts/vortex/notify-jira.sh` | +| `VORTEX_NOTIFY_JIRA_BRANCH` | JIRA notification git branch name (used for issue extraction). | `${VORTEX_NOTIFY_BRANCH}` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_ENDPOINT` | JIRA notification API endpoint. | `https://jira.atlassian.com` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_ENVIRONMENT_URL` | JIRA notification environment URL. | `${VORTEX_NOTIFY_ENVIRONMENT_URL}` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_EVENT` | JIRA notification event type. Can be 'pre_deployment' or 'post_deployment'. | `post_deployment` | `scripts/vortex/notify-jira.sh` | -| `VORTEX_NOTIFY_JIRA_LABEL` | JIRA notification deployment label (branch name, PR number, or custom identifier). | `${VORTEX_NOTIFY_LABEL}` | `scripts/vortex/notify-jira.sh` | +| `VORTEX_NOTIFY_JIRA_LABEL` | JIRA notification deployment label (human-readable identifier for display). | `${VORTEX_NOTIFY_LABEL}` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_LOGIN_URL` | JIRA notification login URL. | `${VORTEX_NOTIFY_LOGIN_URL}` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_MESSAGE` | JIRA notification message template (will be converted to ADF format). Available tokens: %project%, %label%, %timestamp%, %environment_url%, %login_url% | `UNDEFINED` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_PROJECT` | JIRA notification project name. | `${VORTEX_NOTIFY_PROJECT}` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_TOKEN` | JIRA notification API token.

@see https://www.vortextemplate.com/docs/workflows/notifications#jira | `UNDEFINED` | `scripts/vortex/notify-jira.sh`, `ACQUIA ENVIRONMENT`, `LAGOON ENVIRONMENT` | | `VORTEX_NOTIFY_JIRA_TRANSITION` | JIRA notification state to transition to.

If left empty - no transition will be performed. | `UNDEFINED` | `scripts/vortex/notify-jira.sh` | | `VORTEX_NOTIFY_JIRA_USER_EMAIL` | JIRA user email address. | `user@example.com` | `.env`, `scripts/vortex/notify-jira.sh` | -| `VORTEX_NOTIFY_LABEL` | Notification deployment label (branch name, PR number, or custom identifier). | `UNDEFINED` | `scripts/vortex/notify.sh` | +| `VORTEX_NOTIFY_LABEL` | Notification deployment label (human-readable identifier for display). | `UNDEFINED` | `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_LOGIN_URL` | Notification login URL (defaults to ENVIRONMENT_URL/user/login if not provided). | `UNDEFINED` | `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_NEWRELIC_APIKEY` | NewRelic API key, usually of type 'USER'.

@see https://www.vortextemplate.com/docs/workflows/notifications#new-relic | `UNDEFINED` | `ACQUIA ENVIRONMENT`, `LAGOON ENVIRONMENT` | | `VORTEX_NOTIFY_NEWRELIC_APPID` | New Relic notification application ID (auto-discovered if not provided).

Will be discovered automatically from application name if not provided. | `UNDEFINED` | `scripts/vortex/notify-newrelic.sh` | @@ -295,13 +297,16 @@ The list below is automatically generated with [Shellvar](https://github.com/ale | `VORTEX_NOTIFY_NEWRELIC_ENDPOINT` | New Relic notification API endpoint. | `https://api.newrelic.com/v2` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_NEWRELIC_ENVIRONMENT_URL` | New Relic notification environment URL. | `${VORTEX_NOTIFY_ENVIRONMENT_URL}` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_NEWRELIC_EVENT` | New Relic notification event type. Can be 'pre_deployment' or 'post_deployment'. | `post_deployment` | `scripts/vortex/notify-newrelic.sh` | -| `VORTEX_NOTIFY_NEWRELIC_LABEL` | New Relic notification deployment label (branch name, PR number, or custom identifier). | `${VORTEX_NOTIFY_LABEL}` | `scripts/vortex/notify-newrelic.sh` | +| `VORTEX_NOTIFY_NEWRELIC_LABEL` | New Relic notification deployment label (human-readable identifier for display). | `${VORTEX_NOTIFY_LABEL}` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_NEWRELIC_LOGIN_URL` | New Relic notification login URL. | `${VORTEX_NOTIFY_LOGIN_URL}` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_NEWRELIC_PROJECT` | New Relic notification project name. | `${VORTEX_NOTIFY_PROJECT}` | `scripts/vortex/notify-newrelic.sh` | -| `VORTEX_NOTIFY_NEWRELIC_REVISION` | New Relic notification deployment revision. If not provided, will be auto-generated as [LABEL]-[TIMESTAMP] for uniqueness. | `UNDEFINED` | `scripts/vortex/notify-newrelic.sh` | +| `VORTEX_NOTIFY_NEWRELIC_REVISION` | New Relic notification deployment revision. If not provided, will use SHA if available, otherwise auto-generated. | `UNDEFINED` | `scripts/vortex/notify-newrelic.sh` | +| `VORTEX_NOTIFY_NEWRELIC_SHA` | New Relic notification git commit SHA. | `${VORTEX_NOTIFY_SHA}` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_NEWRELIC_USER` | New Relic notification user performing deployment. | `Deployment robot` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_NEWRELIC_USER_KEY` | New Relic notification User API Key.

To obtain your User API Key: `1`. Log in to New Relic `2`. Click on your profile icon (bottom left) `3`. Go to "API keys" `4`. Create or copy an existing "User key" `5`. The key format is: NRAK-XXXXXXXXXXXXXXXXXXXXXX

@see https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#user-key @see https://www.vortextemplate.com/docs/workflows/notifications#new-relic | `${NEWRELIC_USER_KEY}` | `scripts/vortex/notify-newrelic.sh` | | `VORTEX_NOTIFY_PROJECT` | Notification project name. | `${VORTEX_PROJECT}` | `scripts/vortex/notify.sh` | +| `VORTEX_NOTIFY_PR_NUMBER` | Notification pull request number. | `UNDEFINED` | `scripts/vortex/notify.sh` | +| `VORTEX_NOTIFY_SHA` | Notification git commit SHA. | `UNDEFINED` | `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_SKIP` | Notification skip flag. | `UNDEFINED` | `scripts/vortex/notify.sh` | | `VORTEX_NOTIFY_SLACK_CHANNEL` | Slack notification target channel (optional, overrides webhook default). Format: #channel-name or @username | `UNDEFINED` | `scripts/vortex/notify-slack.sh` | | `VORTEX_NOTIFY_SLACK_ENVIRONMENT_URL` | Slack notification environment URL. | `${VORTEX_NOTIFY_ENVIRONMENT_URL}` | `scripts/vortex/notify-slack.sh` | diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/notify-deployment.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/notify-deployment.sh index 10f4d7268..74e58ddd4 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/notify-deployment.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_acquia/hooks/library/notify-deployment.sh @@ -9,6 +9,7 @@ set -e site="${1}" target_env="${2}" branch="${3}" +ref="${4}" # Custom domain name for the environment, including subdomain. # Examples: "dev.example.com", "test.example.com", "www.example.com" @@ -25,6 +26,9 @@ if [ -n "${VORTEX_NOTIFY_ENVIRONMENT_DOMAIN}" ]; then fi export VORTEX_NOTIFY_PROJECT="${site}" +export VORTEX_NOTIFY_BRANCH="${branch}" +export VORTEX_NOTIFY_SHA="${ref}" +export VORTEX_NOTIFY_PR_NUMBER="" export VORTEX_NOTIFY_LABEL="${branch}" export VORTEX_NOTIFY_ENVIRONMENT_URL="${url}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/.lagoon.yml b/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/.lagoon.yml index 6d8291918..6d07a7ec8 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/.lagoon.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/.lagoon.yml @@ -26,6 +26,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=pre_deployment @@ -77,6 +80,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=post_deployment diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/notify-deployment.sh b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/notify-deployment.sh index 10f4d7268..74e58ddd4 100755 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/notify-deployment.sh +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___acquia/hooks/library/notify-deployment.sh @@ -9,6 +9,7 @@ set -e site="${1}" target_env="${2}" branch="${3}" +ref="${4}" # Custom domain name for the environment, including subdomain. # Examples: "dev.example.com", "test.example.com", "www.example.com" @@ -25,6 +26,9 @@ if [ -n "${VORTEX_NOTIFY_ENVIRONMENT_DOMAIN}" ]; then fi export VORTEX_NOTIFY_PROJECT="${site}" +export VORTEX_NOTIFY_BRANCH="${branch}" +export VORTEX_NOTIFY_SHA="${ref}" +export VORTEX_NOTIFY_PR_NUMBER="" export VORTEX_NOTIFY_LABEL="${branch}" export VORTEX_NOTIFY_ENVIRONMENT_URL="${url}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/.lagoon.yml b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/.lagoon.yml index 6d8291918..6d07a7ec8 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/.lagoon.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/.lagoon.yml @@ -26,6 +26,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=pre_deployment @@ -77,6 +80,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=post_deployment diff --git a/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/.lagoon.yml b/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/.lagoon.yml index 6d8291918..6d07a7ec8 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/.lagoon.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/.lagoon.yml @@ -26,6 +26,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=pre_deployment @@ -77,6 +80,9 @@ tasks: command: | export VORTEX_NOTIFY_PROJECT=$LAGOON_PROJECT export VORTEX_NOTIFY_ENVIRONMENT_URL=$LAGOON_ROUTE + export VORTEX_NOTIFY_BRANCH="${LAGOON_PR_HEAD_BRANCH:-$LAGOON_GIT_BRANCH}" + export VORTEX_NOTIFY_SHA="${LAGOON_GIT_SHA}" + export VORTEX_NOTIFY_PR_NUMBER="${LAGOON_PR_NUMBER:-}" export VORTEX_NOTIFY_LABEL="$LAGOON_GIT_BRANCH" [ -n "$LAGOON_PR_NUMBER" ] && export VORTEX_NOTIFY_LABEL="PR-${LAGOON_PR_NUMBER}" export VORTEX_NOTIFY_EVENT=post_deployment diff --git a/.vortex/tests/bats/unit/notify-email.bats b/.vortex/tests/bats/unit/notify-email.bats index 138dcafde..858c68e1c 100644 --- a/.vortex/tests/bats/unit/notify-email.bats +++ b/.vortex/tests/bats/unit/notify-email.bats @@ -13,6 +13,8 @@ load ../_helper.bash export VORTEX_NOTIFY_PROJECT="testproject" export DRUPAL_SITE_EMAIL="testproject@example.com" export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com|John Doe, jane@example.com|Jane Doe, jim@example.com" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -40,7 +42,10 @@ load ../_helper.bash export VORTEX_NOTIFY_PROJECT="testproject" export DRUPAL_SITE_EMAIL="testproject@example.com" export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com|John Doe, jane@example.com|Jane Doe" - export VORTEX_NOTIFY_LABEL="develop" + export VORTEX_NOTIFY_BRANCH="feature/my-pr-branch" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh assert_success @@ -51,8 +56,8 @@ load ../_helper.bash assert_output_contains "Notification email(s) sent to: john@example.com, jane@example.com" assert_output_contains "Finished email notification." - assert_output_contains 'testproject deployment notification of develop' - assert_output_contains 'Site testproject develop has been deployed' + assert_output_contains 'testproject deployment notification of PR-123' + assert_output_contains 'Site testproject PR-123 has been deployed' assert_output_contains "and is available at https://develop.testproject.com." assert_output_contains "Finished dispatching notifications." @@ -68,6 +73,8 @@ load ../_helper.bash export VORTEX_NOTIFY_PROJECT="testproject" export DRUPAL_SITE_EMAIL="testproject@example.com" export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -90,6 +97,8 @@ load ../_helper.bash export VORTEX_NOTIFY_PROJECT="test'); file_put_contents('/tmp/injected_email_test', 'HACKED'); //" export DRUPAL_SITE_EMAIL="testproject@example.com" export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://example.com" diff --git a/.vortex/tests/bats/unit/notify-github.bats b/.vortex/tests/bats/unit/notify-github.bats index 79d15d0d9..b383f129e 100644 --- a/.vortex/tests/bats/unit/notify-github.bats +++ b/.vortex/tests/bats/unit/notify-github.bats @@ -26,6 +26,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="existingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="existingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -44,7 +46,7 @@ load ../_helper.bash declare -a STEPS=( "Started dispatching notifications." "Started GitHub notification for pre_deployment event." - "@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"existingbranch\", \"environment\": \"PR\", \"auto_merge\": false, \"required_contexts\": []} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}" + "@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"feature/my-pr-branch\", \"environment\": \"PR\", \"auto_merge\": false, \"required_contexts\": []} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}" "Marked deployment as started." "Finished GitHub notification for pre_deployment event." "Finished dispatching notifications." @@ -56,7 +58,10 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" - export VORTEX_NOTIFY_LABEL="existingbranch" + export VORTEX_NOTIFY_BRANCH="feature/my-pr-branch" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh assert_success @@ -86,6 +91,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="existingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="existingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -114,6 +121,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="nonexistingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="nonexistingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -145,6 +154,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="post_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="existingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="existingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -176,6 +187,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="post_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="existingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="existingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -205,6 +218,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="post_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="nonexistingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="nonexistingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -235,6 +250,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="post_deployment" export VORTEX_NOTIFY_GITHUB_TOKEN="token12345" export VORTEX_NOTIFY_GITHUB_REPOSITORY="myorg/myrepo" + export VORTEX_NOTIFY_BRANCH="existingbranch" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="existingbranch" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh diff --git a/.vortex/tests/bats/unit/notify-jira.bats b/.vortex/tests/bats/unit/notify-jira.bats index 4723d5fa3..e0ad142e9 100644 --- a/.vortex/tests/bats/unit/notify-jira.bats +++ b/.vortex/tests/bats/unit/notify-jira.bats @@ -43,6 +43,8 @@ load ../_helper.bash export VORTEX_NOTIFY_JIRA_USER_EMAIL="john.doe@example.com" export VORTEX_NOTIFY_JIRA_TOKEN="token12345" export VORTEX_NOTIFY_JIRA_PROJECT="PROJ" + export VORTEX_NOTIFY_BRANCH="feature/proj-1234-some-description" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="feature/proj-1234-some-description" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_LOGIN_URL="https://develop.testproject.com/user/login" @@ -64,6 +66,8 @@ load ../_helper.bash export VORTEX_NOTIFY_JIRA_USER_EMAIL="john.doe@example.com" export VORTEX_NOTIFY_JIRA_TOKEN="token12345" export VORTEX_NOTIFY_JIRA_PROJECT="PROJ" + export VORTEX_NOTIFY_BRANCH="feature/proj-1234-some-description" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="feature/proj-1234-some-description" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" run ./scripts/vortex/notify.sh @@ -101,6 +105,8 @@ load ../_helper.bash export VORTEX_NOTIFY_JIRA_USER_EMAIL="john.doe@example.com" export VORTEX_NOTIFY_JIRA_TOKEN="token12345" export VORTEX_NOTIFY_JIRA_PROJECT="test'); file_put_contents('/tmp/injected_jira_test', 'HACKED'); //" + export VORTEX_NOTIFY_BRANCH="feature/proj-1234-test" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="feature/proj-1234-test" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://example.com" diff --git a/.vortex/tests/bats/unit/notify-newrelic.bats b/.vortex/tests/bats/unit/notify-newrelic.bats index ec41d1fc1..c72592479 100644 --- a/.vortex/tests/bats/unit/notify-newrelic.bats +++ b/.vortex/tests/bats/unit/notify-newrelic.bats @@ -19,6 +19,8 @@ load ../_helper.bash export VORTEX_NOTIFY_PROJECT="testproject" export VORTEX_NOTIFY_NEWRELIC_USER_KEY="key1234" export VORTEX_NOTIFY_EMAIL_RECIPIENTS="john@example.com|John Doe,jane@example.com|Jane Doe" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://test.example.com" @@ -58,6 +60,8 @@ load ../_helper.bash export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_PROJECT="testproject" export VORTEX_NOTIFY_NEWRELIC_USER_KEY="key1234" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://test.example.com" run ./scripts/vortex/notify.sh @@ -85,6 +89,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="newrelic" export VORTEX_NOTIFY_PROJECT="test'); file_put_contents('/tmp/injected_newrelic_test', 'HACKED'); //" export VORTEX_NOTIFY_NEWRELIC_USER_KEY="key1234" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://test.example.com" diff --git a/.vortex/tests/bats/unit/notify-slack.bats b/.vortex/tests/bats/unit/notify-slack.bats index 4194ce3b9..a006bf6de 100644 --- a/.vortex/tests/bats/unit/notify-slack.bats +++ b/.vortex/tests/bats/unit/notify-slack.bats @@ -14,6 +14,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_SLACK_WEBHOOK="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX" @@ -41,7 +43,10 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_PROJECT="testproject" - export VORTEX_NOTIFY_LABEL="feature-123" + export VORTEX_NOTIFY_BRANCH="feature/feature-123" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://pr-123.testproject.com" export VORTEX_NOTIFY_SLACK_WEBHOOK="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX" @@ -52,7 +57,7 @@ load ../_helper.bash assert_output_contains "Started Slack notification." assert_output_contains "Notification sent to Slack." assert_output_contains "Project: testproject" - assert_output_contains 'Deployment: feature-123' + assert_output_contains 'Deployment: PR-123' assert_output_contains "Environment URL: https://pr-123.testproject.com" assert_output_contains "Finished Slack notification." assert_output_contains "Finished dispatching notifications." @@ -69,6 +74,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_SLACK_LOGIN_URL="https://develop.testproject.com/user/login" @@ -94,6 +101,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" # No VORTEX_NOTIFY_SLACK_WEBHOOK set @@ -117,6 +126,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_SLACK_WEBHOOK="https://hooks.slack.com/services/INVALID" @@ -140,6 +151,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_SLACK_WEBHOOK="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX" @@ -167,6 +180,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_SLACK_WEBHOOK="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX" @@ -193,6 +208,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="slack" export VORTEX_NOTIFY_SLACK_WEBHOOK="https://hooks.slack.com/services/TEST/HOOK" export VORTEX_NOTIFY_PROJECT="test'); file_put_contents('/tmp/injected_slack_test', 'HACKED'); //" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://example.com" diff --git a/.vortex/tests/bats/unit/notify-webhook.bats b/.vortex/tests/bats/unit/notify-webhook.bats index a8246c08e..e166b7da6 100644 --- a/.vortex/tests/bats/unit/notify-webhook.bats +++ b/.vortex/tests/bats/unit/notify-webhook.bats @@ -14,6 +14,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="webhook" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" @@ -44,6 +46,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="webhook" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" @@ -64,6 +68,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="webhook" export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" export VORTEX_NOTIFY_WEBHOOK_URL="https://example-webhook-url.com" @@ -91,6 +97,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="webhook" export VORTEX_NOTIFY_WEBHOOK_URL="https://example.com/webhook" export VORTEX_NOTIFY_PROJECT="test'); file_put_contents('/tmp/injected_webhook_test', 'HACKED'); //" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://example.com" diff --git a/.vortex/tests/bats/unit/notify.bats b/.vortex/tests/bats/unit/notify.bats index 928f12904..411a23553 100644 --- a/.vortex/tests/bats/unit/notify.bats +++ b/.vortex/tests/bats/unit/notify.bats @@ -32,6 +32,8 @@ load ../_helper.bash pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 export VORTEX_NOTIFY_EVENT="customevent" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://test.example.com" run ./scripts/vortex/notify.sh @@ -56,6 +58,8 @@ load ../_helper.bash export VORTEX_NOTIFY_CHANNELS="email,slack,github,newrelic,webhook,jira" export VORTEX_NOTIFY_EVENT="pre_deployment" export VORTEX_NOTIFY_PROJECT="testproject" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://test.example.com" @@ -120,6 +124,8 @@ load ../_helper.bash pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 export VORTEX_NOTIFY_CHANNELS="customtype" + export VORTEX_NOTIFY_BRANCH="develop" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="develop" export VORTEX_NOTIFY_ENVIRONMENT_URL="https://test.example.com" run ./scripts/vortex/notify.sh diff --git a/.vortex/tests/manual/try-email-notification.sh b/.vortex/tests/manual/try-email-notification.sh index 8732066c2..4ec25d057 100755 --- a/.vortex/tests/manual/try-email-notification.sh +++ b/.vortex/tests/manual/try-email-notification.sh @@ -32,10 +32,15 @@ SCENARIO="${1:-branch}" if [ "${SCENARIO}" = "pr" ]; then echo "Testing PR deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project with PR" - export VORTEX_NOTIFY_LABEL="feature-123" + export VORTEX_NOTIFY_BRANCH="feature/PROJ-123-test-feature" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" else echo "Testing branch deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project" + export VORTEX_NOTIFY_BRANCH="main" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="main" fi diff --git a/.vortex/tests/manual/try-github-notification.sh b/.vortex/tests/manual/try-github-notification.sh index 2fdadb560..6e7c40a29 100755 --- a/.vortex/tests/manual/try-github-notification.sh +++ b/.vortex/tests/manual/try-github-notification.sh @@ -48,17 +48,19 @@ SCENARIO="${1:-pre}" if [ "${SCENARIO}" = "post" ]; then echo "Testing post-deployment notification (updates deployment status)" export VORTEX_NOTIFY_EVENT="post_deployment" - export VORTEX_NOTIFY_PROJECT="Test Project" - export VORTEX_NOTIFY_LABEL="feature/test-github-notification-do-not-merge" - export VORTEX_NOTIFY_ENVIRONMENT_URL="https://pr-${PR_NUMBER}.example.com" else echo "Testing pre-deployment notification (creates deployment)" export VORTEX_NOTIFY_EVENT="pre_deployment" - export VORTEX_NOTIFY_PROJECT="Test Project" - export VORTEX_NOTIFY_LABEL="feature/test-github-notification-do-not-merge" - export VORTEX_NOTIFY_ENVIRONMENT_URL="https://pr-${PR_NUMBER}.example.com" fi +# Set deployment context variables +export VORTEX_NOTIFY_PROJECT="Test Project" +export VORTEX_NOTIFY_BRANCH="feature/test-github-notification-do-not-merge" +export VORTEX_NOTIFY_SHA="abc123def456" +export VORTEX_NOTIFY_PR_NUMBER="${PR_NUMBER}" +export VORTEX_NOTIFY_LABEL="PR-${PR_NUMBER}" +export VORTEX_NOTIFY_ENVIRONMENT_URL="https://pr-${PR_NUMBER}.example.com" + # Set required environment variables export VORTEX_NOTIFY_CHANNELS=github export VORTEX_NOTIFY_GITHUB_TOKEN="${GITHUB_TOKEN}" diff --git a/.vortex/tests/manual/try-jira-notification.sh b/.vortex/tests/manual/try-jira-notification.sh index f25258aee..be2ea36db 100755 --- a/.vortex/tests/manual/try-jira-notification.sh +++ b/.vortex/tests/manual/try-jira-notification.sh @@ -48,10 +48,15 @@ SCENARIO="${1:-branch}" if [ "${SCENARIO}" = "pr" ]; then echo "Testing PR deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project with PR" - export VORTEX_NOTIFY_LABEL="feature/${JIRA_ISSUE}-test-notification" + export VORTEX_NOTIFY_BRANCH="feature/${JIRA_ISSUE}-test-notification" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" else echo "Testing branch deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project" + export VORTEX_NOTIFY_BRANCH="feature/${JIRA_ISSUE}-test-notification" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="feature/${JIRA_ISSUE}-test-notification" fi diff --git a/.vortex/tests/manual/try-newrelic-notification.sh b/.vortex/tests/manual/try-newrelic-notification.sh index 3580e884e..531b43a45 100755 --- a/.vortex/tests/manual/try-newrelic-notification.sh +++ b/.vortex/tests/manual/try-newrelic-notification.sh @@ -44,11 +44,16 @@ SCENARIO="${1:-branch}" if [ "${SCENARIO}" = "pr" ]; then echo "Testing PR deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project with PR" - export VORTEX_NOTIFY_LABEL="feature-123" - NEWRELIC_APP_NAME="${NEWRELIC_APP_NAME:-Test Project with PR-feature-123}" + export VORTEX_NOTIFY_BRANCH="feature/PROJ-123-test-feature" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" + NEWRELIC_APP_NAME="${NEWRELIC_APP_NAME:-Test Project with PR-PR-123}" else echo "Testing branch deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project" + export VORTEX_NOTIFY_BRANCH="main" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="main" NEWRELIC_APP_NAME="${NEWRELIC_APP_NAME:-Test Project-main}" fi diff --git a/.vortex/tests/manual/try-slack-notification.sh b/.vortex/tests/manual/try-slack-notification.sh index e7e5990e4..c072e7af3 100755 --- a/.vortex/tests/manual/try-slack-notification.sh +++ b/.vortex/tests/manual/try-slack-notification.sh @@ -40,10 +40,15 @@ SCENARIO="${1:-branch}" if [ "${SCENARIO}" = "pr" ]; then echo "Testing PR deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project with PR" - export VORTEX_NOTIFY_LABEL="feature-123" + export VORTEX_NOTIFY_BRANCH="feature/PROJ-123-test-feature" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" else echo "Testing branch deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project" + export VORTEX_NOTIFY_BRANCH="main" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="main" fi diff --git a/.vortex/tests/manual/try-webhook-notification.sh b/.vortex/tests/manual/try-webhook-notification.sh index 60c93f6da..5cfe167d8 100755 --- a/.vortex/tests/manual/try-webhook-notification.sh +++ b/.vortex/tests/manual/try-webhook-notification.sh @@ -40,10 +40,15 @@ SCENARIO="${1:-branch}" if [ "${SCENARIO}" = "pr" ]; then echo "Testing PR deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project with PR" - export VORTEX_NOTIFY_LABEL="feature-123" + export VORTEX_NOTIFY_BRANCH="feature/PROJ-123-test-feature" + export VORTEX_NOTIFY_SHA="abc123def456" + export VORTEX_NOTIFY_PR_NUMBER="123" + export VORTEX_NOTIFY_LABEL="PR-123" else echo "Testing branch deployment notification" export VORTEX_NOTIFY_PROJECT="Test Project" + export VORTEX_NOTIFY_BRANCH="main" + export VORTEX_NOTIFY_SHA="abc123def456" export VORTEX_NOTIFY_LABEL="main" fi diff --git a/hooks/library/notify-deployment.sh b/hooks/library/notify-deployment.sh index 10f4d7268..74e58ddd4 100755 --- a/hooks/library/notify-deployment.sh +++ b/hooks/library/notify-deployment.sh @@ -9,6 +9,7 @@ set -e site="${1}" target_env="${2}" branch="${3}" +ref="${4}" # Custom domain name for the environment, including subdomain. # Examples: "dev.example.com", "test.example.com", "www.example.com" @@ -25,6 +26,9 @@ if [ -n "${VORTEX_NOTIFY_ENVIRONMENT_DOMAIN}" ]; then fi export VORTEX_NOTIFY_PROJECT="${site}" +export VORTEX_NOTIFY_BRANCH="${branch}" +export VORTEX_NOTIFY_SHA="${ref}" +export VORTEX_NOTIFY_PR_NUMBER="" export VORTEX_NOTIFY_LABEL="${branch}" export VORTEX_NOTIFY_ENVIRONMENT_URL="${url}" diff --git a/scripts/vortex/notify-github.sh b/scripts/vortex/notify-github.sh index 26515d9a8..b179d6db6 100755 --- a/scripts/vortex/notify-github.sh +++ b/scripts/vortex/notify-github.sh @@ -22,9 +22,9 @@ VORTEX_NOTIFY_GITHUB_TOKEN="${VORTEX_NOTIFY_GITHUB_TOKEN:-${GITHUB_TOKEN-}}" # GitHub notification repository in owner/repo format. VORTEX_NOTIFY_GITHUB_REPOSITORY="${VORTEX_NOTIFY_GITHUB_REPOSITORY:-}" -# GitHub notification deployment label (branch name, PR number, or custom identifier). +# GitHub notification git branch name. # This will be used as the 'ref' parameter in GitHub's Deployment API. -VORTEX_NOTIFY_GITHUB_LABEL="${VORTEX_NOTIFY_GITHUB_LABEL:-${VORTEX_NOTIFY_LABEL:-}}" +VORTEX_NOTIFY_GITHUB_BRANCH="${VORTEX_NOTIFY_GITHUB_BRANCH:-${VORTEX_NOTIFY_BRANCH:-}}" # GitHub notification event type. Can be 'pre_deployment' or 'post_deployment'. VORTEX_NOTIFY_GITHUB_EVENT="${VORTEX_NOTIFY_GITHUB_EVENT:-${VORTEX_NOTIFY_EVENT:-}}" @@ -53,7 +53,7 @@ for cmd in php curl; do command -v "${cmd}" >/dev/null || { [ -z "${VORTEX_NOTIFY_GITHUB_TOKEN}" ] && fail "Missing required value for VORTEX_NOTIFY_GITHUB_TOKEN" && exit 1 [ -z "${VORTEX_NOTIFY_GITHUB_REPOSITORY}" ] && fail "Missing required value for VORTEX_NOTIFY_GITHUB_REPOSITORY" && exit 1 -[ -z "${VORTEX_NOTIFY_GITHUB_LABEL}" ] && fail "Missing required value for VORTEX_NOTIFY_GITHUB_LABEL" && exit 1 +[ -z "${VORTEX_NOTIFY_GITHUB_BRANCH}" ] && fail "Missing required value for VORTEX_NOTIFY_GITHUB_BRANCH" && exit 1 [ -z "${VORTEX_NOTIFY_GITHUB_EVENT}" ] && fail "Missing required value for VORTEX_NOTIFY_GITHUB_EVENT" && exit 1 [ -z "${VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE}" ] && fail "Missing required value for VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE" && exit 1 @@ -78,7 +78,7 @@ extract_json_value() { if [ "${VORTEX_NOTIFY_GITHUB_EVENT}" = "pre_deployment" ]; then info "GitHub pre-deployment notification summary:" note "Repository : ${VORTEX_NOTIFY_GITHUB_REPOSITORY}" - note "Label (ref) : ${VORTEX_NOTIFY_GITHUB_LABEL}" + note "Branch (ref) : ${VORTEX_NOTIFY_GITHUB_BRANCH}" note "Environment Type: ${VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE}" note "Event : ${VORTEX_NOTIFY_GITHUB_EVENT}" @@ -88,7 +88,7 @@ if [ "${VORTEX_NOTIFY_GITHUB_EVENT}" = "pre_deployment" ]; then -H "Accept: application/vnd.github.v3+json" \ -s \ "https://api.github.com/repos/${VORTEX_NOTIFY_GITHUB_REPOSITORY}/deployments" \ - -d "{\"ref\":\"${VORTEX_NOTIFY_GITHUB_LABEL}\", \"environment\": \"${VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE}\", \"auto_merge\": false, \"required_contexts\": []}")" + -d "{\"ref\":\"${VORTEX_NOTIFY_GITHUB_BRANCH}\", \"environment\": \"${VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE}\", \"auto_merge\": false, \"required_contexts\": []}")" deployment_id="$(echo "${payload}" | extract_json_value "id" || true)" @@ -109,7 +109,7 @@ else -H "Authorization: token ${VORTEX_NOTIFY_GITHUB_TOKEN}" \ -H "Accept: application/vnd.github.v3+json" \ -s \ - "https://api.github.com/repos/${VORTEX_NOTIFY_GITHUB_REPOSITORY}/deployments?ref=${VORTEX_NOTIFY_GITHUB_LABEL}")" + "https://api.github.com/repos/${VORTEX_NOTIFY_GITHUB_REPOSITORY}/deployments?ref=${VORTEX_NOTIFY_GITHUB_BRANCH}")" deployment_id="$(echo "${payload}" | extract_json_first_value "id" || true)" @@ -122,7 +122,7 @@ else info "GitHub post-deployment notification summary:" note "Repository : ${VORTEX_NOTIFY_GITHUB_REPOSITORY}" - note "Label (ref) : ${VORTEX_NOTIFY_GITHUB_LABEL}" + note "Branch (ref) : ${VORTEX_NOTIFY_GITHUB_BRANCH}" note "Environment Type : ${VORTEX_NOTIFY_GITHUB_ENVIRONMENT_TYPE}" note "Environment URL : ${VORTEX_NOTIFY_GITHUB_ENVIRONMENT_URL}" note "Deployment ID : ${deployment_id}" diff --git a/scripts/vortex/notify-jira.sh b/scripts/vortex/notify-jira.sh index 5ccbcffb1..d9ab4065e 100755 --- a/scripts/vortex/notify-jira.sh +++ b/scripts/vortex/notify-jira.sh @@ -27,7 +27,10 @@ VORTEX_NOTIFY_JIRA_USER_EMAIL="${VORTEX_NOTIFY_JIRA_USER_EMAIL:-}" # @see https://www.vortextemplate.com/docs/workflows/notifications#jira VORTEX_NOTIFY_JIRA_TOKEN="${VORTEX_NOTIFY_JIRA_TOKEN:-}" -# JIRA notification deployment label (branch name, PR number, or custom identifier). +# JIRA notification git branch name (used for issue extraction). +VORTEX_NOTIFY_JIRA_BRANCH="${VORTEX_NOTIFY_JIRA_BRANCH:-${VORTEX_NOTIFY_BRANCH:-}}" + +# JIRA notification deployment label (human-readable identifier for display). VORTEX_NOTIFY_JIRA_LABEL="${VORTEX_NOTIFY_JIRA_LABEL:-${VORTEX_NOTIFY_LABEL:-}}" # JIRA notification environment URL. @@ -128,8 +131,8 @@ extract_issue() { } task "Extracting issue" -issue="$(extract_issue "${VORTEX_NOTIFY_JIRA_LABEL}")" -[ "${issue}" = "" ] && pass "Deployment label ${VORTEX_NOTIFY_JIRA_LABEL} does not contain issue number." && exit 0 +issue="$(extract_issue "${VORTEX_NOTIFY_JIRA_BRANCH}")" +[ "${issue}" = "" ] && pass "Branch ${VORTEX_NOTIFY_JIRA_BRANCH} does not contain issue number." && exit 0 note "Found issue ${issue}." task "Creating API token" diff --git a/scripts/vortex/notify-newrelic.sh b/scripts/vortex/notify-newrelic.sh index f742454a5..ea8389b07 100755 --- a/scripts/vortex/notify-newrelic.sh +++ b/scripts/vortex/notify-newrelic.sh @@ -25,11 +25,14 @@ VORTEX_NOTIFY_NEWRELIC_PROJECT="${VORTEX_NOTIFY_NEWRELIC_PROJECT:-${VORTEX_NOTIF # @see https://www.vortextemplate.com/docs/workflows/notifications#new-relic VORTEX_NOTIFY_NEWRELIC_USER_KEY="${VORTEX_NOTIFY_NEWRELIC_USER_KEY:-${NEWRELIC_USER_KEY:-}}" -# New Relic notification deployment label (branch name, PR number, or custom identifier). +# New Relic notification deployment label (human-readable identifier for display). VORTEX_NOTIFY_NEWRELIC_LABEL="${VORTEX_NOTIFY_NEWRELIC_LABEL:-${VORTEX_NOTIFY_LABEL:-}}" +# New Relic notification git commit SHA. +VORTEX_NOTIFY_NEWRELIC_SHA="${VORTEX_NOTIFY_NEWRELIC_SHA:-${VORTEX_NOTIFY_SHA:-}}" + # New Relic notification deployment revision. -# If not provided, will be auto-generated as [LABEL]-[TIMESTAMP] for uniqueness. +# If not provided, will use SHA if available, otherwise auto-generated. VORTEX_NOTIFY_NEWRELIC_REVISION="${VORTEX_NOTIFY_NEWRELIC_REVISION:-}" # New Relic notification environment URL. @@ -86,11 +89,16 @@ for cmd in curl; do command -v "${cmd}" >/dev/null || { info "Started New Relic notification." -# Auto-generate revision if not provided (LABEL-YYYYMMDD-HHMMSS for uniqueness). +# Auto-generate revision if not provided. +# Use SHA if available, otherwise fall back to LABEL-TIMESTAMP. if [ -z "${VORTEX_NOTIFY_NEWRELIC_REVISION}" ]; then - revision_date=$(date '+%Y%m%d') - revision_time=$(date '+%H%M%S') - VORTEX_NOTIFY_NEWRELIC_REVISION="${VORTEX_NOTIFY_NEWRELIC_LABEL}-${revision_date}-${revision_time}" + if [ -n "${VORTEX_NOTIFY_NEWRELIC_SHA}" ]; then + VORTEX_NOTIFY_NEWRELIC_REVISION="${VORTEX_NOTIFY_NEWRELIC_SHA}" + else + revision_date=$(date '+%Y%m%d') + revision_time=$(date '+%H%M%S') + VORTEX_NOTIFY_NEWRELIC_REVISION="${VORTEX_NOTIFY_NEWRELIC_LABEL}-${revision_date}-${revision_time}" + fi note "Auto-generated revision: ${VORTEX_NOTIFY_NEWRELIC_REVISION}" fi diff --git a/scripts/vortex/notify.sh b/scripts/vortex/notify.sh index 3c5e1f504..cce0ceefa 100755 --- a/scripts/vortex/notify.sh +++ b/scripts/vortex/notify.sh @@ -27,7 +27,16 @@ VORTEX_NOTIFY_SKIP="${VORTEX_NOTIFY_SKIP:-}" # Notification project name. VORTEX_NOTIFY_PROJECT="${VORTEX_NOTIFY_PROJECT:-${VORTEX_PROJECT:-}}" -# Notification deployment label (branch name, PR number, or custom identifier). +# Notification git branch name. +VORTEX_NOTIFY_BRANCH="${VORTEX_NOTIFY_BRANCH:-}" + +# Notification git commit SHA. +VORTEX_NOTIFY_SHA="${VORTEX_NOTIFY_SHA:-}" + +# Notification pull request number. +VORTEX_NOTIFY_PR_NUMBER="${VORTEX_NOTIFY_PR_NUMBER:-}" + +# Notification deployment label (human-readable identifier for display). VORTEX_NOTIFY_LABEL="${VORTEX_NOTIFY_LABEL:-}" # Notification environment URL (where the site was deployed). @@ -51,6 +60,8 @@ info "Started dispatching notifications." [ -n "${VORTEX_NOTIFY_SKIP:-}" ] && pass "Skipping dispatching notifications." && exit 0 # Validate required variables. +[ -z "${VORTEX_NOTIFY_BRANCH}" ] && fail "Missing required value for VORTEX_NOTIFY_BRANCH" && exit 1 +[ -z "${VORTEX_NOTIFY_SHA}" ] && fail "Missing required value for VORTEX_NOTIFY_SHA" && exit 1 [ -z "${VORTEX_NOTIFY_LABEL}" ] && fail "Missing required value for VORTEX_NOTIFY_LABEL" && exit 1 [ -z "${VORTEX_NOTIFY_ENVIRONMENT_URL}" ] && fail "Missing required value for VORTEX_NOTIFY_ENVIRONMENT_URL" && exit 1 @@ -60,6 +71,9 @@ if [ -z "${VORTEX_NOTIFY_LOGIN_URL}" ]; then fi # Export variables so notification scripts can use them. +export VORTEX_NOTIFY_BRANCH +export VORTEX_NOTIFY_SHA +export VORTEX_NOTIFY_PR_NUMBER export VORTEX_NOTIFY_LABEL export VORTEX_NOTIFY_ENVIRONMENT_URL export VORTEX_NOTIFY_LOGIN_URL @@ -69,6 +83,17 @@ if [ "${VORTEX_NOTIFY_EVENT}" != "pre_deployment" ] && [ "${VORTEX_NOTIFY_EVENT} fail "Unsupported event ${VORTEX_NOTIFY_EVENT} provided." && exit 1 fi +info "Notification summary:" +note "Project : ${VORTEX_NOTIFY_PROJECT}" +note "Branch : ${VORTEX_NOTIFY_BRANCH}" +note "SHA : ${VORTEX_NOTIFY_SHA}" +note "PR Number : ${VORTEX_NOTIFY_PR_NUMBER:-}" +note "Label : ${VORTEX_NOTIFY_LABEL}" +note "Environment URL: ${VORTEX_NOTIFY_ENVIRONMENT_URL}" +note "Login URL : ${VORTEX_NOTIFY_LOGIN_URL}" +note "Event : ${VORTEX_NOTIFY_EVENT}" +note "Channels : ${VORTEX_NOTIFY_CHANNELS}" + if [ -z "${VORTEX_NOTIFY_CHANNELS##*email*}" ]; then ./scripts/vortex/notify-email.sh "$@" fi