summaryrefslogtreecommitdiff
path: root/src/crawl-actions-wrapper.scm
blob: 2f42dea7ecdc7c849acc2174d71d0347487d76aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;; kenku --- crawl and reproduce github actions
;; Copyright © 2026 bdunahu <bdunahu@operationnull.com>
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

(define-module (src crawl-actions-wrapper)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 string-fun)
  #:use-module ((src utils) #:prefix util:)
  #:use-module ((src config) #:prefix conf:)
  #:use-module (ice-9 textual-ports)
  #:use-module ((src poll-repos) #:prefix poll:)
  #:export (crawl-actions
            external-file))

(define mapdir (dirname poll:outfile))
(define mapfile (in-vicinity mapdir "repos-to-actions-map.txt"))
(define actiondir (in-vicinity conf:cache-dir "actions"))
(define external-file (in-vicinity actiondir "external.txt"))
(define docker-file (in-vicinity actiondir "docker.txt"))
(define file->regex `((,external-file .
                       "^[A-Za-z0-9][A-Za-z0-9_.-]*(/[A-Za-z0-9_.-]+)*(\\s(\\S+))?$")
                      (,docker-file . "^docker://")
                      (,(in-vicinity actiondir "internal.txt") .
                       "^\\./[A-Za-z0-9_./-]+(\\s(\\S+))?$")))

(define (get-uniq-actions str)
  (define (kill-comments str)
    (let ((pos (string-index str #\#)))
      (if pos (substring str 0 pos) str)))
 (let* ((lines (filter (lambda (s) (not (string=? s "")))
                       (string-split str #\newline)))
         (lines (map kill-comments lines))
         (actions (map (lambda (l) (cadr (string-split
                                     l char-set:whitespace)))
                       lines))
         (uniq-actions (delete-duplicates actions)))
    (map (lambda (a) (string-replace-substring a "@" " "))
         uniq-actions)))

(define (crawl-actions)
  (let* ((repos-to-actions-map-sh (in-vicinity conf:scripts-dir
                                               "repos_to_actions_map.sh")))
    (system (string-append repos-to-actions-map-sh " < "
                           poll:outfile " >> " mapfile))) ;append mode
  ;; again, we do this separately after writing everything to another file
  ;; github can cut me off at any time. I would prefer the choice of
  ;; restarting again with a manually modified input file than lose all data.
  (util:normalize-file mapfile)
  (util:filter-actions-on-regex mapfile file->regex get-uniq-actions))