Skip to content

Commit

Permalink
Add autotag job type.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Dec 1, 2023
1 parent f02666d commit c620451
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/env/
/.qlot
/.DS_Store
*.fasl
22 changes: 22 additions & 0 deletions src/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@
"ASDF"
"OSX")
:external-docs ("https://40ants.com/40ants-asdf-system/"))
(0.11.0 2023-12-01
"
Added
=====
New job class 40ANTS-CI/JOBS/AUTOTAG:AUTOTAG was added.
Use it like this:
```lisp
(defworkflow release
:on-push-to \"master\"
:jobs ((40ants-ci/jobs/autotag:autotag)))
```
and it will search for new semver tags in the ChangeLog.md file and push them to the git.
Changed
=======
Slots `quicklisp` and `lisp` were moved from class 40ANTS-CI/JOBS/JOB:JOB to 40ANTS-CI/JOBS/LISP-JOB:LISP-JOB.
")
(0.10.1 2023-03-08
"- Fixed installation of the Linter. Now it depends on 40ANTS-ASDF-SYSTEM system.")
(0.10.0 2022-11-10
Expand Down
8 changes: 7 additions & 1 deletion src/ci.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
(:import-from #:40ants-ci/jobs/docs
#:build-docs)
(:import-from #:40ants-ci/workflow
#:defworkflow))
#:defworkflow)
(:import-from #:40ants-ci/jobs/autotag))
(in-package 40ants-ci/ci)


(defworkflow release
:on-push-to "master"
:jobs ((40ants-ci/jobs/autotag:autotag)))


(defworkflow docs
:on-push-to "master"
:on-pull-request t
Expand Down
69 changes: 69 additions & 0 deletions src/jobs/autotag.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(uiop:define-package #:40ants-ci/jobs/autotag
(:use #:cl)
(:import-from #:40ants-ci/steps/sh
#:sh)
(:import-from #:40ants-ci/jobs/job)
(:import-from #:40ants-ci/utils
#:current-system-name)
(:import-from #:40ants-ci/steps/action
#:action)
(:export #:autotag))
(in-package 40ants-ci/jobs/autotag)

(defparameter *default-filename* "ChangeLog.md")

(defparameter *default-regex* "^## (?<version>\\d+\\.\\d+\\.\\d+.*?)( |\\n).*$")

(defparameter *default-tag-prefix* "v")

(defparameter *default-token-pattern* "${{ secrets.DEPLOY_TRIGGER_TOKEN }}")


(defclass autotag (40ants-ci/jobs/job:job)
((filename :initarg :filename
:initform *default-filename*
:type string
:documentation "File where to search for version numbers."
:reader filename)
(regex :initarg :regex
:initform *default-regex*
:type string
:documentation "Regexp used to extract version numbers."
:reader regex)
(tag-prefix :initarg :tag-prefix
:initform *default-tag-prefix*
:type string
:documentation "Tag prefix."
:reader tag-prefix)
(token-pattern :initarg :token-pattern
:initform *default-token-pattern*
:type string
:documentation "Auth token pattern."
:reader token-pattern)))


(defun autotag (&key (filename *default-filename*)
(regex *default-regex*)
(tag-prefix *default-tag-prefix*)
(token-pattern *default-token-pattern*))
"Creates a job which will run autotagger to create a new git tag for release."
(make-instance 'autotag
:filename filename
:regex regex
:tag-prefix tag-prefix
:token-pattern token-pattern))


(defmethod 40ants-ci/jobs/job:steps ((job autotag))
(append (list
(action "Checkout Code"
"actions/checkout@v3"))
(list
(action "Create release tag"
"butlerlogic/action-autotag@8bc1ad456dcdee34e8c6ffbce991cc31793578c2"
:root (filename job)
:regex_pattern (regex job)
:tag_prefix (tag-prefix job)
:env (list :github_token
(token-pattern job))))
(call-next-method)))
47 changes: 10 additions & 37 deletions src/jobs/job.lisp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
(defpackage #:40ants-ci/jobs/job
(uiop:define-package #:40ants-ci/jobs/job
(:use #:cl)
(:import-from #:40ants-ci/utils
#:ensure-list-of-plists)
(:import-from #:40ants-ci/github)
(:export
#:job
#:use-matrix-p
#:steps
#:os
#:lisp
#:quicklisp
#:name))
(:export #:job
#:use-matrix-p
#:steps
#:os
#:name
#:make-matrix
#:make-env))
(in-package 40ants-ci/jobs/job)


Expand All @@ -20,12 +19,6 @@
(os :initform "ubuntu-latest"
:initarg :os
:reader os)
(quicklisp :initform "quicklisp"
:initarg :quicklisp
:reader quicklisp)
(lisp :initform "sbcl-bin"
:initarg :lisp
:reader lisp)
(exclude :initform nil
:initarg :exclude
:reader exclude
Expand All @@ -46,14 +39,6 @@
(uiop:ensure-list
(call-next-method)))

(defmethod lisp :around ((job job))
(uiop:ensure-list
(call-next-method)))

(defmethod quicklisp :around ((job job))
(uiop:ensure-list
(call-next-method)))

(defmethod steps :around ((job job))
(uiop:ensure-list
(call-next-method)))
Expand All @@ -66,9 +51,7 @@
;; ignore-critiques: length=num
(defgeneric use-matrix-p (job)
(:method ((job job))
(or (> (length (os job)) 1)
(> (length (lisp job)) 1)
(> (length (quicklisp job)) 1))))
(or (> (length (os job)) 1))))


;; ignore-critiques: length=num
Expand All @@ -77,10 +60,6 @@
(append
(when (> (length (os job)) 1)
`(("os" . ,(os job))))
(when (> (length (quicklisp job)) 1)
`(("quicklisp" . ,(quicklisp job))))
(when (> (length (lisp job)) 1)
`(("lisp" . ,(lisp job))))
(when (exclude job)
`(("exclude" .
,(mapcar #'40ants-ci/utils:plist-to-alist
Expand All @@ -93,13 +72,7 @@
(append
(if (= (length (os job)) 1)
`(("OS" . ,(first (os job))))
`(("OS" . "${{ matrix.os }}")))
(if (= (length (quicklisp job)) 1)
`(("QUICKLISP_DIST" . ,(first (quicklisp job))))
`(("QUICKLISP_DIST" . "${{ matrix.quicklisp }}")))
(if (= (length (lisp job)) 1)
`(("LISP" . ,(first (lisp job))))
`(("LISP" . "${{ matrix.lisp }}"))))))
`(("OS" . "${{ matrix.os }}"))))))


(defgeneric make-steps (job)
Expand Down
53 changes: 48 additions & 5 deletions src/jobs/lisp-job.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defpackage #:40ants-ci/jobs/lisp-job
(uiop:define-package #:40ants-ci/jobs/lisp-job
(:use #:cl)
(:import-from #:40ants-ci/jobs/job
#:os
Expand All @@ -14,14 +14,21 @@
#:sh)
(:import-from #:40ants-ci/vars
#:*use-cache*)
(:export
#:lisp-job
#:asdf-system))
(:export #:lisp-job
#:asdf-system
#:lisp
#:quicklisp))
(in-package 40ants-ci/jobs/lisp-job)


(defclass lisp-job (40ants-ci/jobs/job:job)
((qlfile :initarg :qlfile
((quicklisp :initform "quicklisp"
:initarg :quicklisp
:reader quicklisp)
(lisp :initform "sbcl-bin"
:initarg :lisp
:reader lisp)
(qlfile :initarg :qlfile
:initform nil
:reader qlfile)
(asdf-system :initarg :asdf-system
Expand All @@ -46,6 +53,42 @@
(:documentation "This job checkouts the sources, installs Roswell and Qlot. Also, it caches results between runs."))


(defmethod lisp :around ((job lisp-job))
(uiop:ensure-list
(call-next-method)))

(defmethod quicklisp :around ((job lisp-job))
(uiop:ensure-list
(call-next-method)))


(defmethod 40ants-ci/jobs/job:use-matrix-p ((job lisp-job))
(or (call-next-method)
(> (length (lisp job)) 1)
(> (length (quicklisp job)) 1)))


(defmethod 40ants-ci/jobs/job:make-matrix ((job lisp-job))
(append
(call-next-method)

(when (> (length (quicklisp job)) 1)
`(("quicklisp" . ,(quicklisp job))))
(when (> (length (lisp job)) 1)
`(("lisp" . ,(lisp job))))))


(defmethod 40ants-ci/jobs/job:make-env ((job lisp-job))
(append
(call-next-method)
(if (= (length (quicklisp job)) 1)
`(("QUICKLISP_DIST" . ,(first (quicklisp job))))
`(("QUICKLISP_DIST" . "${{ matrix.quicklisp }}")))
(if (= (length (lisp job)) 1)
`(("LISP" . ,(first (lisp job))))
`(("LISP" . "${{ matrix.lisp }}")))))


(defmethod asdf-system :around ((job lisp-job))
(or (call-next-method)
(current-system-name)))
Expand Down
6 changes: 3 additions & 3 deletions src/steps/action.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
(when (action-args action)
`(("with" . ,(loop for (name value) on (action-args action) by #'cddr
when value
collect (cons (string-downcase
(symbol-name name))
value)))))))
collect (cons
(string-downcase name)
value)))))))
1 change: 1 addition & 0 deletions src/workflow.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(:import-from #:40ants-ci/vars)
(:import-from #:alexandria
#:with-output-to-file)
(:import-from #:40ants-ci/jobs/job)
(:export
#:defworkflow))
(in-package 40ants-ci/workflow)
Expand Down

0 comments on commit c620451

Please sign in to comment.