-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
;;; _prepare.el --- Prepration -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(require 'cl-lib) | ||
(require 'subr-x) | ||
|
||
(require 'elenv) | ||
|
||
;; | ||
;;; Util | ||
|
||
(defmacro with-find-file (filename &rest body) | ||
"Execute BODY in FILENAME." | ||
(declare (indent 1) (debug t)) | ||
`(let ((tf ,filename)) (with-current-buffer (find-file tf) ,@body))) | ||
|
||
(defun file-size (filename) | ||
"Return FILENAME's size." | ||
(eask-2str (file-attribute-size (file-attributes filename)))) | ||
|
||
(defun file-to-string (filename) | ||
"Return FILENAME's string." | ||
(with-temp-buffer (insert-file-contents filename) (buffer-string))) | ||
|
||
(defun checksum-zip (type version) | ||
"Return checksum zip path." | ||
(cl-case type | ||
(`npm (format "cli-%s.tgz" version)) | ||
(t | ||
(cond ((string-match-p "win" type) | ||
(format "qob_%s_%s.zip" version type)) | ||
(t | ||
(format "qob_%s_%s.tar.gz" version type)))))) | ||
|
||
(defun checksum-data (type version) | ||
"Return checksum data from TYPE and qob's VERSION." | ||
(let* ((zip (checksum-zip type version)) | ||
(sha256 (format "checksum/%s/%s/sha256" version zip)) | ||
(rmd160 (format "checksum/%s/%s/rmd160" version zip)) | ||
(size (format "checksum/%s/%s/size" version zip))) | ||
`( :sha256 ,(string-trim (file-to-string sha256)) | ||
:rmd160 ,(string-trim (file-to-string rmd160)) | ||
:size ,(string-trim (file-to-string size))))) | ||
|
||
(defun get-latest-tag () | ||
"Return the latest tag (not including pre-release)." | ||
(require 'github-tags) | ||
(let* ((response (cdr (github-tags "cl-qob/cli"))) | ||
(tags (plist-get response :names)) | ||
(latest (nth 1 tags))) ; Skip the first one since it's the pre-release! | ||
latest)) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; _prepare.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
;;; brew-update.el --- Update Homebrew formula -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(let* ((latest (get-latest-tag)) | ||
(version) | ||
(beg) (end) | ||
(data (checksum-data 'npm latest))) | ||
(with-find-file "Formula/qob-cli.rb" | ||
(goto-char (point-min)) | ||
(when (search-forward "version " nil t) | ||
(when-let ((beg (1+ (point))) | ||
(end (1- (line-end-position))) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(goto-char (point-min)) | ||
(when (search-forward "sha256 \"" nil t) | ||
(delete-region (point) (1- (line-end-position))) | ||
(insert (plist-get data :sha256))) | ||
(save-buffer) | ||
(message "[INFO] Updated file %s to version %s" tf latest))))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; brew-update.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
;;; choco-update.el --- Update Choco nuspec -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(let* ((latest (get-latest-tag)) | ||
(version) | ||
(beg) (end) | ||
(data (checksum-data "win-x64" latest)) | ||
(updated)) | ||
(with-find-file "chocolatey/qob-cli.nuspec" | ||
(goto-char (point-min)) | ||
(when (search-forward "<version>" nil t) | ||
(when-let ((beg (point)) | ||
(end (- (line-end-position) 10)) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(save-buffer) | ||
(setq updated t) | ||
(message "[INFO] Updated file %s to version %s" tf latest)))) | ||
(when updated | ||
(with-find-file "chocolatey/tools/chocolateyinstall.ps1" | ||
(goto-char (point-min)) | ||
(when (search-forward "checksum = '" nil t) | ||
(delete-region (point) (1- (line-end-position))) | ||
(insert (plist-get data :sha256))) | ||
(goto-char (point-min)) | ||
(when (search-forward "checksum64 = '" nil t) | ||
(delete-region (point) (1- (line-end-position))) | ||
(insert (plist-get data :sha256))) | ||
(save-buffer)))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; choco-update.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
;;; debian-update.el --- Update Debian -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(let* ((latest (get-latest-tag)) | ||
(version) | ||
(beg) (end)) | ||
(with-find-file "debian/control/arm64" | ||
(goto-char (point-min)) | ||
(when (search-forward "Version: " nil t) | ||
(when-let ((beg (point)) | ||
(end (line-end-position)) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(save-buffer) | ||
(message "[INFO] Updated file %s to version %s" tf latest)))) | ||
(with-find-file "debian/control/x64" | ||
(goto-char (point-min)) | ||
(when (search-forward "Version: " nil t) | ||
(when-let ((beg (point)) | ||
(end (line-end-position)) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(save-buffer) | ||
(message "[INFO] Updated file %s to version %s" tf latest))))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; debian-update.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
;;; latest-tag.el --- Print latest tag -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(princ (get-latest-tag)) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; latest-tag.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
;;; port-update.el --- Update Port's Portfile -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(let* ((latest (get-latest-tag)) | ||
(version) | ||
(beg) (end) | ||
(data (checksum-data 'npm latest))) | ||
(with-find-file "macports/Portfile" | ||
(goto-char (point-min)) | ||
(when (search-forward "version " nil t) | ||
(when-let ((beg (point)) | ||
(end (line-end-position)) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(goto-char (point-min)) | ||
(when (search-forward "rmd160 " nil t) | ||
(delete-region (point) (- (line-end-position) 2)) | ||
(insert (plist-get data :rmd160))) | ||
(goto-char (point-min)) | ||
(when (search-forward "sha256 " nil t) | ||
(delete-region (point) (- (line-end-position) 2)) | ||
(insert (plist-get data :sha256))) | ||
(goto-char (point-min)) | ||
(when (search-forward "size " nil t) | ||
(delete-region (point) (line-end-position)) | ||
(insert (plist-get data :size))) | ||
(save-buffer) | ||
(message "[INFO] Updated the %s to version %s" tf latest))))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; port-update.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
;;; scoop-update.el --- Update Scoop Bucket -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(let* ((latest (get-latest-tag)) | ||
(version) | ||
(beg) (end) | ||
(data (checksum-data "win-x64" latest))) | ||
(with-find-file "bucket/qob-cli.json" | ||
(goto-char (point-min)) | ||
(when (search-forward "\"version\": " nil t) | ||
(when-let ((beg (1+ (point))) | ||
(end (- (line-end-position) 2)) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(goto-char (point-min)) | ||
(when (search-forward "\"hash\": \"" nil t) | ||
(delete-region (point) (1- (line-end-position))) | ||
(insert (plist-get data :sha256))) | ||
(save-buffer) | ||
(message "[INFO] Updated file %s to version %s" tf latest))))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; scoop-update.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
;;; snap-update.el --- Update Snap snapcraft.yaml -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(let* ((latest (get-latest-tag)) | ||
(version) | ||
(beg) (end)) | ||
(with-find-file "snap/snapcraft.yaml" | ||
(goto-char (point-min)) | ||
(when (search-forward "version: " nil t) | ||
(when-let ((beg (point)) | ||
(end (line-end-position)) | ||
(version (buffer-substring beg end)) | ||
(_ (not (string= version latest))) | ||
(new-content (string-replace version latest (buffer-string)))) | ||
(erase-buffer) | ||
(insert new-content) | ||
(save-buffer) | ||
(message "[INFO] Updated file %s to version %s" tf latest))))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; snap-update.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
;;; update-checksum.el --- Update Checksum files -*- lexical-binding: t -*- | ||
;;; Commentary: | ||
;;; Code: | ||
|
||
(load-file "./scripts/_prepare.el") | ||
|
||
(defun openssl-command (type zip) | ||
"Return openssl command by TYPE and ZIP." | ||
(cond | ||
(elenv-macos | ||
(cl-case type | ||
(:sha256 (format "openssl dgst -sha256 %s" zip)) | ||
(:rmd160 (format "openssl dgst -rmd160 %s" zip)))) | ||
(elenv-linux | ||
(cl-case type | ||
(:sha256 (format "openssl dgst -sha256 %s" zip)) | ||
(:rmd160 (format "openssl dgst -rmd160 %s" zip)))) ; XXX: This doesn't work! | ||
(elenv-windows | ||
(cl-case type | ||
(:sha256 (format "certutil -hashfile %s SHA256" zip)) | ||
(:rmd160 (format "echo Not supported" zip)))))) | ||
|
||
(defun openssl-parse-output (type output) | ||
"Extract hash from OUTPUT by TYPE." | ||
(cond | ||
(elenv-macos | ||
(cl-case type | ||
((or :sha256 :rmd160) (nth 1 (split-string output " "))))) | ||
(elenv-linux | ||
(cl-case type | ||
((or :sha256 :rmd160) (nth 1 (split-string output " "))))) | ||
(elenv-windows | ||
(cl-case type | ||
((or :sha256 :rmd160) (nth 1 (split-string output "\n"))))))) | ||
|
||
(let* ((ver (getenv "QOB_VER")) | ||
(zip (getenv "QOB_ZIP")) | ||
(dir (file-name-nondirectory zip)) | ||
(parent (format "./checksum/%s/%s/" ver dir)) | ||
(rmd160 (shell-command-to-string (openssl-command :rmd160 zip))) | ||
(rmd160 (openssl-parse-output :rmd160 rmd160)) | ||
(sha256 (shell-command-to-string (openssl-command :sha256 zip))) | ||
(sha256 (openssl-parse-output :sha256 sha256)) | ||
(size (file-size zip))) | ||
(ignore-errors (make-directory parent t)) | ||
(message "sha256: %s" (string-trim sha256)) | ||
(message "rmd160: %s" (string-trim rmd160)) | ||
(message "size: %s" (string-trim size)) | ||
(write-region rmd160 nil (concat parent "rmd160")) | ||
(write-region sha256 nil (concat parent "sha256")) | ||
(write-region size nil (concat parent "size"))) | ||
|
||
;; Local Variables: | ||
;; coding: utf-8 | ||
;; no-byte-compile: t | ||
;; End: | ||
;;; update-checksum.el ends here |