Skip to content

Commit

Permalink
Fix symlink resolving issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonk committed Oct 4, 2021
1 parent 4a4afd0 commit 624704d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/dev/mock-curl-output.json
/dev/*.tgz
/dev/inform-slack/**
/test-results.tap
/dev/test-results.tap
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ adheres to [Semantic Versioning][semver].

## [Unreleased]

## [v1.0.2] - 2021-10-04

- Make it work correctly when you symlink to the `inform-slack` script

## [v1.0.1] - 2021-10-04

- Fix some release process issues

## [v1.0.0] - 2021-10-01

- First actual release

[Unreleased]: https://github.com/jasonk/inform-slack/compare/v1.0.0...HEAD
[Unreleased]: https://github.com/jasonk/inform-slack/compare/v1.0.2...HEAD
[v1.0.2]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.2
[v1.0.1]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.1
[v1.0.0]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.0
24 changes: 16 additions & 8 deletions bin/inform-slack
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/usr/bin/env bash
# https://github.com/jasonk/inform-slack

source "$(dirname "${BASH_SOURCE[0]}")/../lib/inform-slack.sh"
export INFORM_SLACK_VERSION="v1.0.2"

# If this script was sourced instead of executed then we don't run the
# main function, we just return from here and you can run it yourself
# later if you want
if ( return 0 2>/dev/null ); then return; fi
export INFORM_SLACK_SELF="$(realpath -P "${BASH_SOURCE[0]}")"
export INFORM_SLACK_DIR="$(cd -P "$(dirname "$INFORM_SLACK_SELF")/.." && pwd)"
source "$INFORM_SLACK_DIR/lib/inform-slack.sh"

# If the script was executed and not sourced, then we run it ourselves.
set -eo pipefail
inform_slack "$@"
if ( return 0 2>/dev/null ); then
# If this script was sourced instead of executed then we don't run
# the main function, we just return from here and you can run it
# yourself later if you want
INFORM_SLACK_SOURCED=true
return
else
# If the script was executed and not sourced, then we run it ourselves.
INFORM_SLACK_SOURCED=false
set -eo pipefail
inform_slack "$@"
fi
1 change: 0 additions & 1 deletion dev/Brewfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
brew 'bash'
brew 'coreutils'
brew 'pandoc'

brew 'zlib'
brew 'cmake'
Expand Down
32 changes: 16 additions & 16 deletions dev/Brewfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,35 @@
}
},
"coreutils": {
"version": "8.32",
"version": "9.0",
"bottle": {
"rebuild": 2,
"rebuild": 0,
"root_url": "https://ghcr.io/v2/homebrew/core",
"files": {
"arm64_big_sur": {
"cellar": "/opt/homebrew/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:e7d88d2b7a91a57dfd37c2ea14752d1bb116f25694eab1161d6e8088f7db5921",
"sha256": "e7d88d2b7a91a57dfd37c2ea14752d1bb116f25694eab1161d6e8088f7db5921"
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:875e9ec351a0624e65d19e742a7271fc409ce912fa4a4ad9147ab21eaa126bad",
"sha256": "875e9ec351a0624e65d19e742a7271fc409ce912fa4a4ad9147ab21eaa126bad"
},
"big_sur": {
"cellar": "/usr/local/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:371ec57703b3646e0113331308b6e03617c2a7f91e15e113380b605455daba20",
"sha256": "371ec57703b3646e0113331308b6e03617c2a7f91e15e113380b605455daba20"
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:6c6b84b32d923e26b1c67e8c9aee801f7ab2f0b9f94d9b455b784eb3a2dc575c",
"sha256": "6c6b84b32d923e26b1c67e8c9aee801f7ab2f0b9f94d9b455b784eb3a2dc575c"
},
"catalina": {
"cellar": "/usr/local/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:7a97ad96dfbe6abbb5c94424518a077e040af8a77d1946ca960a5f33cd237551",
"sha256": "7a97ad96dfbe6abbb5c94424518a077e040af8a77d1946ca960a5f33cd237551"
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:9b24df176ef9ec342e83af6880c27e0235e4fcc436d0143fb37eb24695de51a6",
"sha256": "9b24df176ef9ec342e83af6880c27e0235e4fcc436d0143fb37eb24695de51a6"
},
"mojave": {
"cellar": "/usr/local/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:10fbad2e35846c7e835cb979b5beb9edf07f3a9742ddcc3c28d9abd5fe9ccb1b",
"sha256": "10fbad2e35846c7e835cb979b5beb9edf07f3a9742ddcc3c28d9abd5fe9ccb1b"
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:6755e3bb94c35dae4ebbd525633691bc5ff1dc82a84f5b968b952d7be86652d7",
"sha256": "6755e3bb94c35dae4ebbd525633691bc5ff1dc82a84f5b968b952d7be86652d7"
},
"x86_64_linux": {
"cellar": "/home/linuxbrew/.linuxbrew/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:6d0ddc3ead1b8259a9a97b7bc9cc891cbc5a236a82afd51f224de16affea0b54",
"sha256": "6d0ddc3ead1b8259a9a97b7bc9cc891cbc5a236a82afd51f224de16affea0b54"
"url": "https://ghcr.io/v2/homebrew/core/coreutils/blobs/sha256:6ab4d61127fac0e193a82881b9262e3121ada87566f470abdf6a2b9c63ab6768",
"sha256": "6ab4d61127fac0e193a82881b9262e3121ada87566f470abdf6a2b9c63ab6768"
}
}
}
Expand Down Expand Up @@ -282,11 +282,11 @@
"macOS": "10.15.7"
},
"big_sur": {
"HOMEBREW_VERSION": "3.2.13-29-g1f3de1d",
"HOMEBREW_VERSION": "3.2.14-51-g1909d89",
"HOMEBREW_PREFIX": "/usr/local",
"Homebrew/homebrew-core": "d4c15892d82c979de446d716b53d51ced6e92bb8",
"CLT": "12.5.0.22.9",
"Xcode": "12.5",
"Homebrew/homebrew-core": "1c4ca36b5b0ea13c2b3d9e4bdd7b8ad26d0902ea",
"CLT": "13.0.0.0.1.1630607135",
"Xcode": "13.0",
"macOS": "11.5.2"
}
}
Expand Down
50 changes: 31 additions & 19 deletions dev/make-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ cd "$(dirname "$0")"

REPO="https://github.com/jasonk/inform-slack"

warn() { echo "$@" 1>&2; }
die() { warn "$@"; exit 1; }

# Executable Version
EV="$(../bin/inform-slack --version)"
# Changelog Info
Expand All @@ -17,36 +14,51 @@ CD="$(awk '{print $3}' <<<"$CI")"
# Today's Date
TD="$(date +%F)"

PROBLEMS=()
if git rev-parse -q --verify "refs/tags/$EV" >/dev/null; then
PROBLEMS+=( "Version $EV already tagged, did you forget to increment it?" )
fi

if [ "$TD" != "$CD" ]; then
die "Today is $TD, but latest Changelog entry is $CD"
PROBLEMS+=( "Today is $TD, but latest Changelog entry is $CD" )
fi
if [ "$CV" != "$EV" ]; then
die "Executable version is $EV, but Changelog version is $CV"
PROBLEMS+=( "Executable version is $EV, but Changelog version is $CV" )
fi

UR="$(grep -E '^\[Unreleased\]:' ../CHANGELOG.md)"
if [ -z "$UR" ]; then die "No [Unreleased] URL in CHANGELOG"; fi
if [ -z "$UR" ]; then
PROBLEMS+=( "No [Unreleased] URL in CHANGELOG" )
fi
if [ "$(basename "$UR")" != "${EV}...HEAD" ]; then
die "Wrong [Unreleased] URL in CHANGELOG";
PROBLEMS+=( "Wrong [Unreleased] URL in CHANGELOG" )
fi

if ! grep -qE "^\[$EV\]: $REPO/releases/tag/$EV$" ../CHANGELOG.md; then
die "No [$EV] tag in CHANGELOG";
PROBLEMS+=( "No [$EV] tag in CHANGELOG" )
fi

if git rev-parse -q --verify "refs/tags/$EV" >/dev/null; then
die "Version $EV is already tagged, did you remember to increment it?"
fi
#if [ -n "$(git status --porcelain=v1 2>/dev/null)" ]; then
# PROBLEMS+=( "The repo has uncommitted changes" )
#fi

if [ -n "$(git status --porcelain=v1 2>/dev/null)" ]; then
die "The repo has uncommitted changes"
if (( ${#PROBLEMS[@]} )); then
echo "Problems detected, cannot release:" 1>&2
for P in "${PROBLEMS[@]}"; do echo " - $P" 1>&2; done
exit 1
fi

git tag -a "$EV" -m "Release $EV"
git push origin "$EV"

rm -rf inform-slack
mkdir inform-slack
cp -a ../*.md ../LICENSE ../bin ../builders ../lib inform-slack
tar cvfz "inform-slack-${EV}.tgz" inform-slack
gh release create "$EV" -n '' -t '' "inform-slack-${EV}.tgz"
tar cfz "inform-slack-${EV}.tgz" inform-slack

if [ "$1" = "-n" ]; then
echo "Dry-run, not really releasing"
echo "git tag -a '$EV' -m 'Release $EV'"
echo "git push origin '$EV'"
echo "gh release create '$EV' -n '' -t '' 'inform-slack-${EV}.tgz'"
else
git tag -a "$EV" -m "Release $EV"
git push origin "$EV"
gh release create "$EV" -n '' -t '' "inform-slack-${EV}.tgz"
fi
6 changes: 3 additions & 3 deletions run-tests.sh → dev/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
cd "$(dirname "$0")/.."

if command -v kcov &>/dev/null; then
kcov --clean --bash-dont-parse-binary-dir \
--bash-parser=/usr/local/bin/bash \
--include-path="$(pwd)/lib,$(pwd)/bin,$(pwd)/builders" \
coverage bats test 2>/dev/null | tee test-results.tap
coverage bats test 2>/dev/null | tee dev/test-results.tap
else
bats test | tee test-results.tap
bats test | tee dev/test-results.tap
fi
31 changes: 10 additions & 21 deletions lib/inform-slack.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/usr/bin/env bash
# https://github.com/jasonk/inform-slack

export INFORM_SLACK_VERSION="v1.0.0"

# Defaults
: ${INFORM_SLACK_UNFURL_LINKS:=false}
: ${INFORM_SLACK_UNFURL_MEDIA:=false}
: ${INFORM_SLACK_LINK_NAMES:=false}
: ${INFORM_SLACK_REPLY_BROADCAST:=}

INFORM_SLACK_DIR="$(
cd "$( dirname "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd
)"
if [ -n "${INFORM_SLACK_BUILDERS:-}" ]; then
INFORM_SLACK_BUILDERS="$INFORM_SLACK_BUILDERS:$INFORM_SLACK_DIR/builders"
else
Expand Down Expand Up @@ -255,39 +250,33 @@ open-url() {
list-builders() {
local DIRS DIR
IFS=: read -ra DIRS <<<"$INFORM_SLACK_BUILDERS"
for DIR in "${DIRS[@]}"; do ls -1 "$DIR"; done | sort | uniq
for DIR in "${DIRS[@]}"; do ls -1 "$DIR"; done \
| sort | uniq | grep -v -E '\.md$'
}

show-help-file() {
local FILE="${1:-$0}" ; shift
local FILE="$(realpath -P "$1").md"
if [ -f "$FILE" ]; then
if command -v bat &>/dev/null; then
bat "$@" "$FILE"
bat -p "$FILE"
else
cat "$FILE"
fi
else
die "No help found ($FILE)"
die "No help found for $1 ($FILE)"
fi
}

help-builder() {
local BUILDER="$1"
local FILE="$(find-builder "$BUILDER").md"
if [ -f "$FILE" ]; then
show-help-file "$FILE"
else
die "No help found for builder '$BUILDER'"
fi
local BUILDER="$(find-builder "$1")"
show-help-file "$BUILDER"
}

usage() {
local ERROR="${1:-}"
FILE="$0.md"
if [ -n "$ERROR" ]; then warn "ERROR: $ERROR"; fi
if [ -f "$FILE" ]; then show-help-file "$FILE" -pp; fi
if [ -n "$ERROR" ]; then exit 1; fi
exit 0
show-help-file "$0"
if [ -n "$ERROR" ]; then exit 1; else exit 0; fi
}

message() {
Expand Down Expand Up @@ -348,7 +337,7 @@ inform_slack() {
esac
done

if [ -z "$MODE" ]; then usage 'error'; exit 1; fi
if [ -z "$MODE" ]; then usage "Must specify mode"; exit 1; fi

debug "MODE=$MODE"
"$MODE" "$@"
Expand Down

0 comments on commit 624704d

Please sign in to comment.