Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
2026-10-16 Mats Lidell <matsl@gnu.org>

* hypb-release.el (hypb-release-version-file-list): Rename variable as
it is now a list of lists.
(hypb-release--replace-version): Replaces the version number based on
a given pattern
(hypb-release-update-version): Use hypb-release-update-version.
(hypb-release-update-hyperbole-version-header): Add pattern.

* test/MANIFEST: Add hypb-release-tests.el.

* test/hypb-release-tests.el: New test file for hypb-release.el.
(hypb-release-tests--replace-version):
(hypb-release-tests--update-version): Test cases.

* man/hyperbole.texi: Use EDITION and VERSION variables.

* Makefile (release-pre): Use remote for fetching and creating release
branch. Use underscore in branch name.

Expand Down
90 changes: 58 additions & 32 deletions hypb-release.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 5-Oct-26 at 21:58:13
;; Last-Mod: 14-Oct-26 at 13:49:08 by Bob Weiner
;; Last-Mod: 16-Oct-26 at 22:03:31 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand All @@ -18,21 +18,40 @@
;;; Code:

(require 'lisp-mnt)
(require 'cl-lib)

(defvar hypb-release-version-files
'("hversion.el"
"HY-ABOUT"
"HY-ANNOUNCE"
"HY-NEWS"
"hyperbole-pkg.el"
"Makefile"
"README.in.md"
"man/hyperbole.texi")
(defvar hypb-release-version-file-list
'(("hversion.el" "(defconst hyperb:version \"{version}\"")
("HY-ABOUT" "Version {version}")
("HY-ANNOUNCE" "Subject: GNU Hyperbole Major Release 9 (V{version})")
("hyperbole-pkg.el" "{version}" t)
("Makefile" "HYPB_VERSION = {version}")
("README.in.md" "# GNU Hyperbole {version} - The Everyday Hypertextual Information Manager")
("man/hyperbole.texi" "@set EDITION {version}")
("man/hyperbole.texi" "@set VERSION {version}"))
"Files in which the Hyperbole version number is stored.
The list does not include hyperbole.el since that needs to be updated in
the last commit for a release. That update is controlled by a make
target. See also `hypb-release-update-hyperbole-version-header'.")
Each list item contains the filename, a pattern for locating the version
number and an optional flag that if non-nil means the file is not
required to exist. Note that the list does not include hyperbole.el
since that needs to be updated in the last commit for a release. That
update is controlled by a make target. See also
`hypb-release-update-hyperbole-version-header'.")

(defun hypb-release--replace-version (pattern old-version new-version &optional check)
"Replace OLD-VERSION with NEW-VERSION using PATTERN.
PATTERN contains the placeholder {version}. When CHECK is non-nil, only
check that the pattern matches. Return non-nil if the pattern was
found."
(save-excursion
(goto-char (point-min))
(let ((search (string-replace "{version}" old-version pattern))
(replacement (string-replace "{version}" new-version pattern)))
(when (search-forward search nil t)
(unless check
(replace-match replacement t t))
t))))

;;;###autoload
(defun hypb-release-update-version (new-version)
"Replace old-version with NEW-VERSION in `hypb-release-version-files'.

Expand All @@ -47,35 +66,42 @@ Files are saved normally by Emacs, so hooks are applied as if edited manually."

(let ((old-version (lm-version "hyperbole.el")))
;; Check all files before any action.
(dolist (file hypb-release-version-files)
(unless (file-exists-p file)
(error "File does not exist: %s" file))
(with-temp-buffer
(insert-file-contents file)
(unless (search-forward old-version nil t)
(error "Version %s not found in %s"
old-version file))))
(dolist (v hypb-release-version-file-list)
(let ((file (nth 0 v))
(pattern (nth 1 v))
(optional (nth 2 v)))
(unless (or optional (file-exists-p file))
(error "File does not exist: %s" file))
(when (file-exists-p file)
(with-temp-buffer
(insert-file-contents file)
(unless (hypb-release--replace-version pattern old-version new-version 'dry-run)
(error "Version %s not found in %s"
old-version file))))))
Comment thread
rswgnu marked this conversation as resolved.

;; Substitute and save all.
(let ((replacements 0))
(dolist (file hypb-release-version-files)
(with-current-buffer (find-file-noselect file)
(save-excursion
(goto-char (point-min))
(while (search-forward old-version nil t)
(replace-match new-version t t)
(setq replacements (1+ replacements))))
(save-buffer)))
(let ((replacements 0)
(files))
(dolist (v hypb-release-version-file-list)
(let ((file (nth 0 v))
(pattern (nth 1 v)))
(when (file-exists-p file)
(with-current-buffer (find-file-noselect file)
(unless (hypb-release--replace-version pattern old-version new-version)
(error "Version %s not found in %s" old-version file))
(setq replacements (1+ replacements))
(cl-pushnew file files :test 'equal)
(save-buffer)))))

(message "Version %s -> %s: %d replacements in %d files"
old-version new-version
replacements (length hypb-release-version-files)))))
replacements (length files)))))

(defun hypb-release-update-hyperbole-version-header (new-version)
"Update the version header in hyperbole.el to NEW-VERSION.
This update needs to be in the last commit for a release and is run by a
Makefile target."
(let ((hypb-release-version-files '("hyperbole.el")))
(let ((hypb-release-version-file-list '("hyperbole.el" ";; Version: {version}")))
(hypb-release-update-version new-version)))

(provide 'hypb-release)
Expand Down
12 changes: 6 additions & 6 deletions man/hyperbole.texi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@set txicodequoteundirected
@set txicodequotebacktick

@set UPDATED October 15, 2026
@set UPDATED October 16, 2026
@set UPDATED-MONTH October 2026
@set EDITION 9.3.0
@set VERSION 9.3.0
Expand Down Expand Up @@ -170,8 +170,8 @@ WITHOUT ANY WARRANTY, without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</P>

<PRE>
Edition 9.3.0
Printed October 15, 2026.
Edition @value{EDITION}
Printed October 16, 2026.

Published by the Free Software Foundation, Inc.
Author: Bob Weiner
Expand Down Expand Up @@ -212,8 +212,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@sp 2

@example
Edition 9.3.0
October 15, 2026 @c AUTO-REPLACE-ON-SAVE
Edition @value{EDITION}
October 16, 2026 @c AUTO-REPLACE-ON-SAVE


Published by the Free Software Foundation, Inc.
Expand Down Expand Up @@ -558,7 +558,7 @@ Smart Keyboard Keys
@chapter Introduction

This edition of the GNU Hyperbole Manual is for use with any version
9.3.0 or greater of GNU Hyperbole. Hyperbole runs atop GNU Emacs
@value{VERSION} or greater of GNU Hyperbole. Hyperbole runs atop GNU Emacs
28 or higher. It will trigger an error if your Emacs is older.

This chapter summarizes the structure of the rest of the manual,
Expand Down
1 change: 1 addition & 0 deletions test/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ hy-test-dependencies.el - Hyperbole test dependencies
hy-test-helpers.el - unit test helpers
hycontrol-tests.el - hycontrol unit tests
hypb-ert-tests.el - hypb-ert tests
hypb-release-tests.el - tests for hypb-release
hypb-tests.el - tests for hypb.el utility functions
hyperbole-tests.el - tests for hyperbole.el
hyrolo-tests.el - unit tests for hyrolo.el
Expand Down
8 changes: 7 additions & 1 deletion test/hy-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; Orig-Date: 30-Jan-21 at 12:00:00
;; Last-Mod: 17-Aug-26 at 15:20:00 by Bob Weiner
;; Last-Mod: 16-Oct-26 at 18:42:29 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -176,5 +176,11 @@ and the default WORD-LENGTH is 4."
(funcall orig-featurep f subfeature)))))
,@body)))

(defun hy-test-file-contents (file)
"Return FILE contents as a string."
(with-temp-buffer
(insert-file-contents file)
(buffer-string)))

(provide 'hy-test-helpers)
;;; hy-test-helpers.el ends here
62 changes: 62 additions & 0 deletions test/hypb-release-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
;;; hypb-release-tests.el --- unit tests for hypb-release -*- lexical-binding: t; -*-
;;
;; Author: Mats Lidell
;;
;; Orig-Date: 16-Oct-26 at 18:32:18
;; Last-Mod: 16-Oct-26 at 19:33:26 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2026 Free Software Foundation, Inc.
;; See the "../HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.

;;; Commentary:
;;

;;; Code:

(require 'ert)
(require 'ert-x)
(require 'el-mock)
(require 'hy-test-helpers)
(require 'hypb-release)

(ert-deftest hypb-release-tests--replace-version ()
"Test `hypb-release--replace-version'."
(with-temp-buffer
(insert "Version: 1.0")
(should-not (hypb-release--replace-version "Version: {version}" "1.1" "1.2" 'dry-run))
(should (hypb-release--replace-version "Version: {version}" "1.0" "1.2" 'dry-run))
(should (hypb-release--replace-version "Version: {version}" "1.0" "1.2"))
(should (string= "Version: 1.2" (buffer-string)))))

(ert-deftest hypb-release-tests--update-version ()
"Test `hypb-release-update-version'."
(let* ((file1 (make-temp-file "hypb" nil nil "Version: 1.0"))
(file2 (make-temp-file "hypb" nil nil "Version: 1.0 V1.0"))
(hypb-release-version-file-list
(list (list file1 "Version: {version}")
(list file2 "Version: {version}")
(list file2 "V{version}")
(list "no-such-file" "Version: {version}" t))))
(unwind-protect
(mocklet (((lm-version "hyperbole.el") => "1.0"))
(ert-with-message-capture cap
(hypb-release-update-version "1.1")
(hy-test-helpers:should-last-message
"Version 1.0 -> 1.1: 3 replacements in 2 files" cap))
(should (string-prefix-p "Version: 1.1" (hy-test-file-contents file1)))
(should (string-prefix-p "Version: 1.1 V1.1" (hy-test-file-contents file2))))
(hy-delete-files-and-buffers (list file1 file2)))))

;; This file can't be byte-compiled without the `el-mock' package
;; which is not a dependency of Hyperbole.
;;
;; Local Variables:
;; no-byte-compile: t
;; End:

(provide 'hypb-release-tests)
;;; hypb-release-tests.el ends here
Loading