Skip to content

Commit

Permalink
feat: add RELEASE_ prefix to SLACK env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Nov 10, 2024
1 parent 80a0840 commit 79f29f5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ RELEASE_EXTRA_CONFIRMATION='{"src/dev":"Are you sure sure?"}'
RELEASE_EXTRA_RUN_COMMANDS='{"src/dev":"echo api call... && sleep 1 && echo done"}'

# slack
SLACK_CHANNEL_ID=
SLACK_OAUTH_TOKEN=
RELEASE_SLACK_CHANNEL_ID=
RELEASE_SLACK_OAUTH_TOKEN=

#######################
# INTERNAL DEV TOOLING
Expand Down
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,67 @@ Examples:

## Env variables

### RELEASE_SOURCE_BRANCH
> Note: you can (optionally) use `RELEASE_` as prefix for all env keys.
> Useful if you want to distinguish visually the origin of that env key-value.
> Eg: Using `SOURCE_BRANCH` will be equivalent to `RELEASE_SOURCE_BRANCH`.
### BRANCHES

#### SOURCE_BRANCH

The default source branch that you want to use for your releases.

> Default: `main`
### RELEASE_TARGET_BRANCH
#### TARGET_BRANCH

The default target branch that you want to use for your releases.

> Default: `prod`
### RELEASE_DEVELOPMENT_BRANCH
#### DEVELOPMENT_BRANCH

If you have a different develop branch from the source branch, you can also define it here.

> Default: `main`
### RELEASE_SUCCESSFUL_TEXT
### SLACK

Display a text at the very end of the release.
Useful to have a link directly to the releases page to validate everything was good.
#### SLACK_CHANNEL_ID

The Slack channel ID where to publish the changelog message.

> Example: SLACK_CHANNEL_ID=#your-channel
#### SLACK_OAUTH_TOKEN

> Example: RELEASE_SUCCESSFUL_TEXT=https://github.com/Purpose-Green/release/releases
The Slack oauth token with the right of writing into your channel.

### RELEASE_EXTRA_CONFIRMATION
> Example: SLACK_CHANNEL_ID=xoxb-123-456-ABC789
### EXTRA

#### EXTRA_CONFIRMATION

Force asking for a new dialog when a filepath is found on such a directly (the key).
The value is the question forced to be asked. It must be [y/Y] to continue the release.

> Example: RELEASE_EXTRA_CONFIRMATION='{"migrations": "Migrations found! Remember to create a DB backup!"}'
> Example: EXTRA_CONFIRMATION='{"migrations": "Migrations found! Remember to create a DB backup!"}'
### RELEASE_EXTRA_RUN_COMMANDS
#### EXTRA_RUN_COMMANDS

Run a command when a filepath is found on such a directory (the key).
The commands will be executed only once, even if multiple files are affected.
How? After running a command, this will be saved on memory to avoid running the same command twice.

> Example: RELEASE_EXTRA_RUN_COMMANDS='{"migrations": "api_call_to_create_DB_backup"}'
> Example: EXTRA_RUN_COMMANDS='{"migrations": "api_call_to_create_DB_backup"}'
### SUCCESSFUL_TEXT

Display a text at the very end of the release.
Useful to have a link directly to the releases page to validate everything was good.

> Example: SUCCESSFUL_TEXT=https://github.com/Purpose-Green/release/releases
## Demo

Expand Down
4 changes: 4 additions & 0 deletions src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ _DEFAULT_SOURCE_BRANCH="main"
_DEFAULT_TARGET_BRANCH="prod"
_DEFAULT_DEVELOPMENT_BRANCH="main"
_DEFAULT_SUCCESSFUL_TEXT=""
_DEFAULT_SLACK_CHANNEL_ID=""
_DEFAULT_SLACK_OAUTH_TOKEN=""

: "${RELEASE_SOURCE_BRANCH:=${SOURCE_BRANCH:=$_DEFAULT_SOURCE_BRANCH}}"
: "${RELEASE_TARGET_BRANCH:=${TARGET_BRANCH:=$_DEFAULT_TARGET_BRANCH}}"
: "${RELEASE_DEVELOPMENT_BRANCH:=${DEVELOPMENT_BRANCH:=$_DEFAULT_DEVELOPMENT_BRANCH}}"
: "${RELEASE_SUCCESSFUL_TEXT:=${SUCCESSFUL_TEXT:=$_DEFAULT_SUCCESSFUL_TEXT}}"
: "${RELEASE_SLACK_CHANNEL_ID:=${SLACK_CHANNEL_ID:=$_DEFAULT_SLACK_CHANNEL_ID}}"
: "${RELEASE_SLACK_OAUTH_TOKEN:=${SLACK_OAUTH_TOKEN:=$_DEFAULT_SLACK_OAUTH_TOKEN}}"

function env::run_extra_confirmation() {
local changed_files=$1
Expand Down
6 changes: 3 additions & 3 deletions src/slack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# shellcheck disable=SC2155
function slack::notify() {
if [[ -z "${SLACK_CHANNEL_ID:-}" || -z "${SLACK_OAUTH_TOKEN:-}" ]]; then
if [[ -z "${RELEASE_SLACK_CHANNEL_ID:-}" || -z "${RELEASE_SLACK_OAUTH_TOKEN:-}" ]]; then
echo -e "${COLOR_CYAN}Slack configuration missing." \
"Check your .env for SLACK_CHANNEL_ID & SLACK_OAUTH_TOKEN${COLOR_RESET}"
"Check your .env for RELEASE_SLACK_CHANNEL_ID & RELEASE_SLACK_OAUTH_TOKEN${COLOR_RESET}"
return
fi

Expand All @@ -22,7 +22,7 @@ function slack::notify() {

local slack_message=$(cat <<EOF
{
"channel": "$SLACK_CHANNEL_ID",
"channel": "$RELEASE_SLACK_CHANNEL_ID",
"unfurl_links": false,
"unfurl_media": false,
"blocks": [
Expand Down

0 comments on commit 79f29f5

Please sign in to comment.