Skip to content

Commit

Permalink
Merge pull request #187 from tegonal/feature/sbt-publish-to-sonatype
Browse files Browse the repository at this point in the history
introduce sbt-publish-to-sonatype
  • Loading branch information
robstoll authored Apr 11, 2024
2 parents 6b8fbca + 24cc154 commit 7d87a14
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ body:
- releasing/prepare-next-dev-cycle-template.sh
- releasing/release-files.sh
- releasing/release-template.sh
- releasing/sbt-publish-to-sonatype.sh
- releasing/sneak-peek-banner.sh
- releasing/toggle-sections.sh
- releasing/update-version-common-steps.sh
Expand Down
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ The scripts are ordered by topic:
- [Release Template](#release-template)
- [Prepare Next Dev Cycle Template](#prepare-next-dev-cycle-template)
- [git Pre-Release checks](#git-pre-release-checks)
- [Update Version common steps](#update-version-common-release-steps)
- [sbt sonatype publish](#sbt-publish-to-sonatype)
- [Update Version common steps](#update-version-common-steps)
- [Update Version in README](#update-version-in-readme)
- [Update Version in bash scripts](#update-version-in-bash-scripts)
- [Update Version in issue templates](#update-version-in-issue-templates)
Expand Down Expand Up @@ -178,7 +179,7 @@ jobs:
jobs:
steps:
- name: install shellspec v0.28.1
- name: install shellspec
run: ./lib/tegonal-scripts/src/ci/install-shellspec.sh
# and most likely as well
- name: run shellspec
Expand Down Expand Up @@ -743,6 +744,52 @@ source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
</releasing-pre-release-checks-git>
## SBT Sonatype publish
Assumes you have configured your sbt project to publish to sonatype (or any other repo) where you have defined to
use SONATYPE_USER and SONATYPE_PW as env vars for your credentials. I.e. your build.sbt file will contain something like:
```sbt
credentials += Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sys.env.getOrElse("SONATYPE_USER", ""),
sys.env.getOrElse("SONATYPE_PW", "")
)
```
This script asks to fill in those to env vars if not already given an calls `sbt publishSigned` afterwards passing
them in without exporting them.
Full example:
<releasing-sbt-publish-to-sonatype>
<!-- auto-generated, do not modify here but in src/releasing/sbt-publish-to-sonatype.sh.doc -->
```bash
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
# Assumes tegonal's scripts were fetched with gt - adjust location accordingly
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
# ask for SONATYPE_USER and SONATYPE_PW (unless already exported beforehand) and calls sbt publishSigned
"$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"
# predefine SONATYPE_USER, asks for SONATYPE_PW (unless already exported beforehand) and calls sbt publishSigned
SONATYPE_USER="kshjwo2" "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"
# if you use it in combination with other files, then you might want to source it instead
sourceOnce "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"
# and then call the function
sbtPublishToSonatype
SONATYPE_USER="kshjwo2" sbtPublishToSonatype
```
</releasing-sbt-publish-to-sonatype>
## Update Version Common Steps
Performs several `releasing` scripts defined in the following sections:
Expand Down Expand Up @@ -1206,6 +1253,15 @@ sourceOnce "$dir_of_tegonal_scripts/utility/ask.sh"
if askYesOrNo "shall I say hello"; then
echo "hello"
fi
function noAnswerCallback {
echo "hm... no answer, I am sad :("
}
timeoutInSeconds=30
readArgs='' # i.e. no additional args passed to read
answer='default value used if there is no answer'
askWithTimeout "some question" "$timeoutInSeconds" noAnswerCallback answer "$readArgs"
echo "$answer"
```
</utility-ask>
Expand Down
2 changes: 1 addition & 1 deletion src/ci/install-shellspec.doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

jobs:
steps:
- name: install shellspec v0.28.1
- name: install shellspec
run: ./lib/tegonal-scripts/src/ci/install-shellspec.sh
# and most likely as well
- name: run shellspec
Expand Down
2 changes: 1 addition & 1 deletion src/ci/install-shellspec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# jobs:
# steps:
# - name: install shellspec v0.28.1
# - name: install shellspec
# run: ./lib/tegonal-scripts/src/ci/install-shellspec.sh
# # and most likely as well
# - name: run shellspec
Expand Down
19 changes: 19 additions & 0 deletions src/releasing/sbt-publish-to-sonatype.doc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
# Assumes tegonal's scripts were fetched with gt - adjust location accordingly
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"

# ask for SONATYPE_USER and SONATYPE_PW (unless already exported beforehand) and calls sbt publishSigned
"$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"

# predefine SONATYPE_USER, asks for SONATYPE_PW (unless already exported beforehand) and calls sbt publishSigned
SONATYPE_USER="kshjwo2" "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"

# if you use it in combination with other files, then you might want to source it instead
sourceOnce "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"

# and then call the function
sbtPublishToSonatype
SONATYPE_USER="kshjwo2" sbtPublishToSonatype
77 changes: 77 additions & 0 deletions src/releasing/sbt-publish-to-sonatype.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
#
# __ __
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <[email protected]>
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
# /___/ Please report bugs and contribute back your improvements
#
# Version: v3.2.0-SNAPSHOT
####### Description #############
#
# Checks if (env) var SONATYPE_USER and SONATYPE_PW is set and if not ask the user to input them (via stdin).
# Afterwards it calls `sbt publishSigned` passing the variables without exporting them.
#
####### Usage ###################
#
# #!/usr/bin/env bash
# set -euo pipefail
# shopt -s inherit_errexit
# # Assumes tegonal's scripts were fetched with gt - adjust location accordingly
# dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
# source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
#
# # ask for SONATYPE_USER and SONATYPE_PW (unless already exported beforehand) and calls sbt publishSigned
# "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"
#
# # predefine SONATYPE_USER, asks for SONATYPE_PW (unless already exported beforehand) and calls sbt publishSigned
# SONATYPE_USER="kshjwo2" "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"
#
# # if you use it in combination with other files, then you might want to source it instead
# sourceOnce "$dir_of_tegonal_scripts/releasing/sbt-publish-to-sonatype.sh"
#
# # and then call the function
# sbtPublishToSonatype
# SONATYPE_USER="kshjwo2" sbtPublishToSonatype
#
###################################
set -euo pipefail
shopt -s inherit_errexit
unset CDPATH
export TEGONAL_SCRIPTS_VERSION='v3.2.0-SNAPSHOT'

if ! [[ -v dir_of_tegonal_scripts ]]; then
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.."
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
fi
sourceOnce "$dir_of_tegonal_scripts/utility/log.sh"
sourceOnce "$dir_of_tegonal_scripts/utility/ask.sh"

function sbtPublishToSonatype() {
local askWithTimeout=60

# shellcheck disable=SC2317 # called by name
function sbtPublishToSonatype_noAnswerCallback() {
printf "\n"
die "no user interaction after %s seconds, stop publish process'." "askWithTimeout"
}

if ! [[ -v SONATYPE_USER ]] || [[ -z "$SONATYPE_USER" ]]; then
askWithTimeout "Please enter the sonatype user token (input is hidden -- will be written to SONATYPE_USER):" \
"$askWithTimeout" sbtPublishToSonatype_noAnswerCallback SONATYPE_USER "-s"
else
logInfo "SONATYPE_USER already defined"
fi

if ! [[ -v SONATYPE_PW ]] || [[ -z "$SONATYPE_PW" ]]; then
askWithTimeout "Please enter the sonatype access token (input is hidden -- will be written to SONATYPE_PW):" \
"$askWithTimeout" sbtPublishToSonatype_noAnswerCallback SONATYPE_PW "-s"
else
logInfo "$SONATYPE_PW already defined"
fi
printf "\n"
SONATYPE_PW="$SONATYPE_PW" SONATYPE_USER="$SONATYPE_USER" sbt publishSigned
}

${__SOURCED__:+return}
sbtPublishToSonatype "$@"
9 changes: 9 additions & 0 deletions src/utility/ask.doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ sourceOnce "$dir_of_tegonal_scripts/utility/ask.sh"
if askYesOrNo "shall I say hello"; then
echo "hello"
fi

function noAnswerCallback {
echo "hm... no answer, I am sad :("
}
timeoutInSeconds=30
readArgs='' # i.e. no additional args passed to read
answer='default value used if there is no answer'
askWithTimeout "some question" "$timeoutInSeconds" noAnswerCallback answer "$readArgs"
echo "$answer"
9 changes: 9 additions & 0 deletions src/utility/ask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
# echo "hello"
# fi
#
# function noAnswerCallback {
# echo "hm... no answer, I am sad :("
# }
# timeoutInSeconds=30
# readArgs='' # i.e. no additional args passed to read
# answer='default value used if there is no answer'
# askWithTimeout "some question" "$timeoutInSeconds" noAnswerCallback answer "$readArgs"
# echo "$answer"
#
###################################
set -euo pipefail
shopt -s inherit_errexit
Expand Down

0 comments on commit 7d87a14

Please sign in to comment.