Skip to content

Commit

Permalink
Extend config locations (#114)
Browse files Browse the repository at this point in the history
* Allow sealog to be configured in project.clj

* Allow sealog to be configured in the .wallbrew directory

* Update docs

* Add alternative config locations

* [Format] Auto-formatting

---------

Co-authored-by: nnichols <[email protected]>
  • Loading branch information
nnichols and nnichols authored Oct 13, 2024
1 parent 53ffa6d commit a702fc1
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .bouncer/config.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:comment "The default configuration for Wall Brew projects."
:project-rules {:license {:comment "https://github.com/Wall-Brew-Co/open-source?tab=readme-ov-file#licensing"
:disabled false}
:plugins {:disabled false,
:plugins {:disabled false
:available-plugins [{:comment "https://github.com/Wall-Brew-Co/rebroadcast?tab=readme-ov-file#sealog-configuration"
:plugin-name "com.wallbrew/lein-sealog"
:plugin-version "1.6.0"}
Expand Down
12 changes: 12 additions & 0 deletions .sealog/changes/1-8-0.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{:version {:major 1
:minor 8
:patch 0}
:version-type :semver3
:changes {:added ["Support for loading configuration from `project.clj`."
"Support for loading configuration from `.wallbrew/sealog/config.edn`."]
:changed []
:deprecated []
:removed []
:fixed []
:security []}
:timestamp "2024-10-13T16:09:40.636206814Z"}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Table of Contents

* [1.8.0 - 2024-10-13](#180---2024-10-13)
* [1.7.0 - 2024-09-21](#170---2024-09-21)
* [1.6.0 - 2024-05-03](#160---2024-05-03)
* [1.5.0 - 2024-05-03](#150---2024-05-03)
Expand All @@ -18,6 +19,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [1.0.1 - 2022-10-23](#101---2022-10-23)
* [1.0.0 - 2022-10-23](#100---2022-10-23)

## 1.8.0 - 2024-10-13

* Added
* Support for loading configuration from `project.clj`.
* Support for loading configuration from `.wallbrew/sealog/config.edn`.

## 1.7.0 - 2024-09-21

* Fixed
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

.PHONY: version/major version/minor version/patch changelog/render
MAKE = make

# These are the locations of the directories we'll use
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Sealog is available as a leiningen plugin and can be downloaded from [clojars](h
To install Sealog, add the following in your `:plugins` list in your `project.clj` file:

```clj
[com.wallbrew/lein-sealog "1.4.0"]
[com.wallbrew/lein-sealog "1.7.0"]
```

The first time you invoke this plugin, Leiningen will automatically fetch the dependency for you.
Expand All @@ -39,11 +39,11 @@ From the root of your project directory, you may invoke the following commands:
* `check` - To validate Sealog's configuration, changelog entry files, the changelog, and the project version
* `help` - To view the help text of sealog or any command

Most commands will accept several options, which can be configured by the command line arguments passed in or by a configuration file located at `.sealog/config.edn`.
Most commands will accept several options, which can be configured by the command line arguments passed in or in [project configuration](#configuration).
In all cases, the options will follow this order of precedence:

1. Arguments passed by command line
2. Values stored in `.sealog/config.edn`
2. Values stored in configuration
3. Default values in Sealog's implementation

### Initialize Sealog
Expand Down Expand Up @@ -337,7 +337,13 @@ Empty change lists may be kept for consistency or removed.

Many of Sealog's commands may be modified at execution time with additional arguments.
Long-term decisions, such as where the Changelog should be written to, can also be configured in a static file.
As of version `1.1.0`, Sealog will inspect the local `.sealog/config.edn` file for configuration.
As of version `1.7.0`, Sealog will inspect the following locations for configuration.
The first location found will be used, and the others will be ignored:

- The `:sealog` key in the project's `project.clj` file
- The `.sealog/config.edn` file, relative to the project's root
- The `.wallbrew/sealog/config.edn` file, relative to the project's root
- The default configuration that would be written by `lein sealog init`

Sealog will create this file while executing `lein sealog init` if no prior Sealog configuration file is detected.
The file will be created with the defaults outlined in this README.
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<groupId>com.wallbrew</groupId>
<artifactId>lein-sealog</artifactId>
<packaging>jar</packaging>
<version>1.7.0</version>
<version>1.8.0</version>
<name>lein-sealog</name>
<description>A Leiningen plugin for managing your changelog.</description>
<url>https://github.com/Wall-Brew-Co/common-beer-format</url>
<url>https://github.com/Wall-Brew-Co/lein-sealog</url>
<licenses>
<license>
<name>MIT</name>
Expand All @@ -20,7 +20,7 @@
<url>https://github.com/Wall-Brew-Co/lein-sealog</url>
<connection>scm:git:git://github.com/Wall-Brew-Co/lein-sealog.git</connection>
<developerConnection>scm:git:ssh://[email protected]/Wall-Brew-Co/lein-sealog.git</developerConnection>
<tag>31ce3c975205b4a4e2f213e5b7a24cf60b9e9c56</tag>
<tag>604d39fea1862e1c45710b238e5ecec831567913</tag>
</scm>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.wallbrew/lein-sealog "1.7.0"
(defproject com.wallbrew/lein-sealog "1.8.0"
:description "A Leiningen plugin for managing your changelog."
:url "https://github.com/Wall-Brew-Co/lein-sealog"
:license {:name "MIT"
Expand Down
8 changes: 4 additions & 4 deletions src/leiningen/sealog.clj
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
(let [command (first args)
options (rest args)]
(case command
"init" (sealog/init options)
"bump" (sealog/bump-version options)
"render" (sealog/render-changelog options)
"insert" (sealog/insert-entry options)
"init" (sealog/init project options)
"bump" (sealog/bump-version project options)
"render" (sealog/render-changelog project options)
"insert" (sealog/insert-entry project options)
"version" (sealog/display-version project options)
"check" (sealog/check project options)
"help" (help options)
Expand Down
55 changes: 28 additions & 27 deletions src/leiningen/sealog/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
This namespace contains the public functions that are called by the leiningen"
(:require [leiningen.core.main :as main]
[leiningen.sealog.impl :as impl]
[leiningen.sealog.impl.io :as io]
[leiningen.sealog.types.changelog :as changelog]
[leiningen.sealog.types.commands :as commands]))


(defn init
"Create a new changelog directory."
[_opts]
(let [configuration (impl/load-config!)]
(if (impl/sealog-configured?)
[project _options]
(let [configuration (impl/load-config! project)]
(if (impl/sealog-configured? project)
(main/info "Sealog configuration found.")
(impl/configure! configuration))
(if (impl/sealog-initialized? configuration)
Expand All @@ -22,52 +23,52 @@

(defn render-changelog
"Render the changelog to the target file."
[opts]
(let [configuration (impl/load-config!)
filepath (or (first opts) (:changelog-filename configuration))
[project options]
(let [configuration (impl/load-config! project)
filepath (or (first options) (:changelog-filename configuration))
changelog (impl/load-changelog-entry-directory! configuration)
sorted-changelog (changelog/sort-changelog-descending changelog)
changes (impl/render-changelog sorted-changelog)]
(impl/write-file! filepath changes)
(io/write-file! filepath changes)
(main/info (format "Wrote changelog to: %s" filepath))))


(defn bump-version
"Create a new changelog entry for the version bump."
[opts]
(let [configuration (impl/load-config!)
[project options]
(let [configuration (impl/load-config! project)
changelog-directory (:changelog-entry-directory configuration)
bump-type (keyword (or (first opts) "patch"))
bump-type (keyword (or (first options) "patch"))
changelog (impl/load-changelog-entry-directory! configuration)
new-entry (update (changelog/bump changelog bump-type) :timestamp str)
new-file (str changelog-directory (changelog/render-filename new-entry))]
(impl/write-edn-file! new-file new-entry configuration)
(io/write-edn-file! new-file new-entry configuration)
(println (format "Created new changelog entry: %s" new-file))))


(defn insert-entry
"Insert a note of a specified change type into the most current change file."
[opts]
(let [change-type (first opts)
change-notes (rest opts)]
[project options]
(let [change-type (first options)
change-notes (rest options)]
(if (commands/valid-insert-command? change-type change-notes)
(let [configuration (impl/load-config!)
(let [configuration (impl/load-config! project)
changelog-directory (:changelog-entry-directory configuration)
changelog (impl/load-changelog-entry-directory! configuration)
latest-changelog-entry (changelog/max-version changelog)
updated-changelog-entry (changelog/insert latest-changelog-entry change-type change-notes)
updated-entry-filename (str changelog-directory (changelog/render-filename updated-changelog-entry))]
(impl/write-edn-file! updated-entry-filename updated-changelog-entry configuration)
(println (format "Updated changelog entries: %s" updated-entry-filename)))
(System/exit 1))))
(io/write-edn-file! updated-entry-filename updated-changelog-entry configuration)
(main/info (format "Updated changelog entries: %s" updated-entry-filename)))
(main/exit 1))))


(defn display-version
"Display information about the current version."
[project opts]
(let [version-source (first opts)]
[project options]
(let [version-source (first options)]
(if (commands/valid-version-command? version-source)
(let [configuration (impl/load-config!)
(let [configuration (impl/load-config! project)
changelog (impl/load-changelog-entry-directory! configuration)
latest-changelog-entry (changelog/max-version changelog)
sealog-version (changelog/render-version latest-changelog-entry)
Expand All @@ -77,14 +78,14 @@
"sealog" (main/info sealog-version)
(do (main/info (str "project.clj: " leiningen-version))
(main/info (str "sealog: " sealog-version)))))
(System/exit 1))))
(main/exit 1))))


(defn check
"Check the current configuration, changelog entries, and the current project version."
[project _opts]
(if (impl/valid-configuration?)
(let [configuration (impl/load-config!)
(if (impl/valid-configuration? project)
(let [configuration (impl/load-config! project)
some-changelog-entries? (impl/changelog-entry-directory-is-not-empty? configuration)
all-changelog-entries-valid? (impl/changelog-directory-only-contains-valid-files? configuration)
same-version-type? (impl/all-changelog-entries-use-same-version-type? configuration)
Expand All @@ -97,6 +98,6 @@
changelog-rendered? (impl/rendered-changelog-contains-all-changelog-entries? configuration)]
(if (and versions-match? changelog-rendered?)
(main/info "All checks passed")
(System/exit 1)))
(System/exit 1)))
(System/exit 1)))
(main/exit 1)))
(main/exit 1)))
(main/exit 1)))
Loading

0 comments on commit a702fc1

Please sign in to comment.