From d587b77b4b04c2476f3da75775e8fa0c378c153d Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Fri, 2 Dec 2022 08:09:40 +0800 Subject: [PATCH 1/4] chore(dev): add Language Server Protocol implementation for R --- shell.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/shell.nix b/shell.nix index 86f16d5..a7a9438 100644 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,7 @@ let devDependencies = [ pkgs.rPackages.devtools + pkgs.rPackages.languageserver pkgs.rPackages.roxygen2 ]; From 56603baa8fc70226c6318bf4ef814936549c0747 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Fri, 2 Dec 2022 08:15:12 +0800 Subject: [PATCH 2/4] refactor(style): format the code using lsp document format provider ... and run a few chores. --- R/base.R | 32 +++++++++++++++++++++++++------- man/RocketBase.Rd | 3 ++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/R/base.R b/R/base.R index d05c5fe..d04aad6 100644 --- a/R/base.R +++ b/R/base.R @@ -44,7 +44,8 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint private$setup() }, - #' @description Prints rudimentary information about the remote PocketBase API instance. + #' @description Prints rudimentary information about the remote + #' PocketBase API instance. info = function() { cat(sprintf("PocketBase Instance URL: %s\n", self$url)) }, @@ -73,8 +74,8 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint self$bare <- crul::HttpClient$new( url = self$url, headers = list( - Authorization=sprintf("%s", private$token), - "User-Agent"=private$useragent() + Authorization = sprintf("%s", private$token), + "User-Agent" = private$useragent() ) ) }, @@ -84,16 +85,26 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint ## Build the HTTP client: client <- crul::HttpClient$new(url = self$url) + ## Define authentication endpoint path: + path <- "/api/admins/auth-with-password" + + ## Define credentials payload: + credentials <- list( + identity = private$identity, + password = private$password + ) + ## Issue the authentication request and get a response: - response <- client$post("/api/admins/auth-with-password", body=list(identity=private$identity, password=private$password)) + response <- client$post(path, body = credentials) - ## Check if response status is 200. If not, raise error as it implies that authentication has failed. + ## If response status is not 200, raise error as it implies + ## failed authentication: if (response$status_code != 200) { stop("Authentication failed.") } ## Parse the content of the response: - content <- jsonlite::fromJSON(response$parse(encoding="UTF-8")) + content <- jsonlite::fromJSON(response$parse(encoding = "UTF-8")) ## Return the authentication token: content$token @@ -101,7 +112,14 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint ## Builds the user-agent string. useragent = function() { - sprintf( "rocketbase/%s (%s; on:%s)", utils::packageVersion("rocketbase"), Sys.info()["sysname"], Sys.info()["nodename"]) + ## Get package version: + version <- utils::packageVersion("rocketbase") + + ## Get operating system: + sysname <- Sys.info()["sysname"] + + ## Build the "User-Agent" header value: + sprintf("rocketbase/%s (%s)", version, sysname) } ) ) diff --git a/man/RocketBase.Rd b/man/RocketBase.Rd index c524aad..89681e3 100644 --- a/man/RocketBase.Rd +++ b/man/RocketBase.Rd @@ -88,7 +88,8 @@ client <- rocketbase::RocketBase$new( \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-RocketBase-info}{}}} \subsection{Method \code{info()}}{ -Prints rudimentary information about the remote PocketBase API instance. +Prints rudimentary information about the remote +PocketBase API instance. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{RocketBase$info()}\if{html}{\out{
}} } From 2141eb319cdc8cd36a7bdb0217bd66281d41766b Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Fri, 2 Dec 2022 08:23:37 +0800 Subject: [PATCH 3/4] chore(dev): integrate git-chglog --- .Rbuildignore | 1 + .chglog/CHANGELOG.tpl.md | 56 ++++++++++++++++++++++++++++++++++++++++ .chglog/config.yml | 28 ++++++++++++++++++++ NEWS.md | 17 ++++++++++++ shell.nix | 1 + 5 files changed, 103 insertions(+) create mode 100755 .chglog/CHANGELOG.tpl.md create mode 100755 .chglog/config.yml create mode 100644 NEWS.md diff --git a/.Rbuildignore b/.Rbuildignore index 88dbd38..beed977 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ +^.chglog ^.vscode ^LICENSE\.md$ ^nix diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md new file mode 100755 index 0000000..5683d03 --- /dev/null +++ b/.chglog/CHANGELOG.tpl.md @@ -0,0 +1,56 @@ +{{ if .Versions -}} + +## [Unreleased] + +{{ if .Unreleased.CommitGroups -}} +{{ range .Unreleased.CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} + +{{ range .Versions }} + +## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }} +{{ range .CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end -}} + +{{- if .RevertCommits -}} +### Reverts +{{ range .RevertCommits -}} +- {{ .Revert.Header }} +{{ end }} +{{ end -}} + +{{- if .MergeCommits -}} +### Pull Requests +{{ range .MergeCommits -}} +- {{ .Header }} +{{ end }} +{{ end -}} + +{{- if .NoteGroups -}} +{{ range .NoteGroups -}} +### {{ .Title }} +{{ range .Notes }} +{{ .Body }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} + +{{- if .Versions }} +[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD +{{ range .Versions -}} +{{ if .Tag.Previous -}} +[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }} +{{ end -}} +{{ end -}} +{{ end -}} \ No newline at end of file diff --git a/.chglog/config.yml b/.chglog/config.yml new file mode 100755 index 0000000..f7ad724 --- /dev/null +++ b/.chglog/config.yml @@ -0,0 +1,28 @@ +style: github +template: CHANGELOG.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/telostat/rocketbase +options: + commits: + # filters: + # Type: + # - feat + # - fix + # - perf + # - refactor + commit_groups: + # title_maps: + # feat: Features + # fix: Bug Fixes + # perf: Performance Improvements + # refactor: Code Refactoring + header: + pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$" + pattern_maps: + - Type + - Scope + - Subject + notes: + keywords: + - BREAKING CHANGE \ No newline at end of file diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..295b1a6 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,17 @@ + +## [Unreleased] + + + +## 0.0.0.9000 - 2022-12-02 +### Chore +- **dev:** add Language Server Protocol implementation for R + +### Feat +- init codebase with bare API client implementation + +### Refactor +- **style:** format the code using lsp document format provider + + +[Unreleased]: https://github.com/telostat/rocketbase/compare/0.0.0.9000...HEAD diff --git a/shell.nix b/shell.nix index a7a9438..24c5159 100644 --- a/shell.nix +++ b/shell.nix @@ -21,6 +21,7 @@ in pkgs.mkShell { buildInputs = [ thisR + pkgs.git-chglog pkgs.pocketbase ]; From 60e02b97335a47ddcf3fab128f8872de51834b4b Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Fri, 2 Dec 2022 08:26:48 +0800 Subject: [PATCH 4/4] chore(dev): add release script --- .Rbuildignore | 1 + README.md | 15 +++++++++ release.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100755 release.sh diff --git a/.Rbuildignore b/.Rbuildignore index beed977..3a072c5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,5 +2,6 @@ ^.vscode ^LICENSE\.md$ ^nix +^release.sh ^shell.nix$ ^tmp diff --git a/README.md b/README.md index 224ecf6..ea830c1 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,21 @@ my_data <- jsonlite::fromJSON(response$parse(encoding = "UTF-8")) print(my_data) ``` +## Releasing + +Make sure that your `main` branch is up to date: + +```sh +git checkout main +git pull +``` + +Then, run the release script with new version information: + +```sh +./release.sh -n +``` + ## License This work is licensed under MIT license. See [LICENSE](./LICENSE.md). diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..ddb2c44 --- /dev/null +++ b/release.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +## Stop on errors: +set -eo pipefail + +## Helper function to print log messages. +_log() { + echo "[RELEASE LOG]" "${@}" +} + +## Helper function to print errors. +_error() { + echo 1>&2 "[RELEASE ERROR]" "${@}" +} + +## Helper function to print usage. +_usage() { + echo "Usage: $0 [-h] -n " +} + +## Declare variables: +_version="" + +## Parse command line arguments: +while getopts "n:h" o; do + case "${o}" in + n) + _version="${OPTARG}" + ;; + h) + _usage + exit 0 + ;; + *) + _usage 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +_log "Checking variables..." +if [ -z "${_version}" ]; then + _usage 1>&2 + exit 1 +else + _log "Version is \"${_version}\". Proceeding..." +fi + +_log "Checking git repository state..." +if [[ -z "$(git status --porcelain)" ]]; then + _log "Git repository is clean. Proceeding..." +else + _error "Git repository is not clean. Aborting..." + exit 1 +fi + +_log "Updating application version..." +sed -i -E "s/^Version:([ ]+).*/Version:\\1${_version}/g" DESCRIPTION + +_log "Generating changelog..." +git-chglog --output NEWS.md --next-tag "${_version}" + +_log "Staging changes..." +git add NEWS.md DESCRIPTION + +_log "Committing changes..." +git commit -m "chore(release): ${_version}" + +_log "Tagging version..." +git tag -a -m "Release ${_version}" "${_version}" + +_log "Pushing changes to remote..." +git push --follow-tags origin main + +_log "Creating the release..." +gh release create "${_version}" --title "${_version}" --generate-notes + +_log "Updating application version for development..." +sed -i -E "s/^Version:([ ]+).*/Version:\\1${_version}.9000/g" DESCRIPTION + +_log "Staging changes..." +git add DESCRIPTION + +_log "Committing changes..." +git commit -m "chore: bump development version to ${_version}.9000" + +_log "Pushing changes to remote..." +git push + +_log "Finished!"