WIP: automation/pull-mirror: Initial declaration #2

Draft
kreyren wants to merge 5 commits from pull-mirror-4-upstream into central
4 changed files with 35 additions and 117 deletions
Showing only changes of commit 369652f4af - Show all commits

@ -1,24 +0,0 @@
#!/usr/bin/env sh
exec guile -s "$0" "$@"
!#
;;;C DNM: Title
;;;C Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;C
;;;C This file is Free/Libre Open-Source Software; you may copy, redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
;;;C This file 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.
;;;C
;;;C You should have received a copy of the GNU General Public license along with this project. If not, see <http://www.gnu.org/licenses>
;(use-modules ())
;;; GNU Guile script library for definitions used for automation
;;; String containing the full path to the project's repository
(define %repo-dir (string-append (dirname (current-filename)) "/.."))
(define (get-variable name)
"Ensure that the environment variable NAME exists"
(or (getenv name)
(error (format #f "Environment variable not set: ~a" name))))
;;; common.scm ends here

@ -1,33 +0,0 @@
#!/usr/bin/env sh
exec guile -s "$0" "$@"
!#
;;;C DNM: Title
;;;C Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;C
;;;C This file is Free/Libre Open-Source Software; you may copy, redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
;;;C This file 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.
;;;C
;;;C You should have received a copy of the GNU General Public license along with this project. If not, see <http://www.gnu.org/licenses>
;(use-modules ())
;;; GNU Guile script library for hotfix code used for automatization
;; FIXME(Krey): I found guile-git library to do the checkout which is as of 22/09/22-EU unfinished on https://gitlab.com/guile-git/guile-git/-/blob/master/git/checkout.scm so writting custom handling which should be replaced when/if it gets finished
;; DO-NOT-CONTRIBUTE(Krey): Just a quick wrapper because the handling is not finished in guile-git library
(define (git:checkout-index repository branch)
"Quick handling to checkout the git branch of REPOSITORY on BRANCH"
(system* "git" (string-append "--work-tree=" repository) "checkout" branch))
;; DO-NOT-CONTRIBUTE(Krey): Just a quick wrapper because the handling is not finished in guile-git library
(define (git:pull repository)
"Quick handling to invoke git pull in REPOSITORY"
(system* "git" (string-append "--work-tree=" repository) "pull"))
;; DO-NOT-CONTRIBUTE(Krey): Just a quick wrapper because the handling is not finished in guile-git library
(define (git:push repository branch)
"Quick handling to invoke git push in REPOSITORY with BRANCH"
(system* "git" (string-append "--work-tree=" repository) "push" repository branch))
;;;X hotfixes.scm ends here

@ -1,60 +0,0 @@
#!/usr/bin/env sh
exec guile -s "$0" "$@"
!#
;;;C DNM: Title
;;;C Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;C
;;;C This file is Free/Libre Open-Source Software; you may copy, redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
;;;C This file 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.
;;;C
;;;C You should have received a copy of the GNU General Public license along with this project. If not, see <http://www.gnu.org/licenses>
(define-module (devops-tools sync-git-repo)
#:use-module (ice-9 optargs)
;#:use-module (git)
;#:use-module ((git checkout) #:prefix git:)
#:use-module (devops-tools hotfixes)
#:use-module (devops-tools utils)
#:export (sync-git-repo))
;;; Commentary:
;;;
;;; FIXME-DOCS
;;;
;;; Code:
(define* (sync-git-repo #:key
(source-repo (error "Key not provided: source-repo"))
(source-branch (error "Key not provided: source-branch"))
(target-repo (error "Key not provided: target-repo"))
(target-branch (error "Key not provided: target-branch"))
(push? #f)
(username (unless (false? push) (error "Key not provided: username")))
(token (unless (false? push) (error "Key not provided: token")))
(forge (unless (false? push) (error "Key not provided: forge"))))
"Sync SOURCE git repository with SOURCE-BRANCH to *local* TARGET repository's TARGET-BRANCH including pushing changes to optional FORGE, requires USERNAME and TOKEN to push changes.
This procedure is designed to manage pull-based mirroring"
;; FIXME(Krey): Sanity for inputs
(git:checkout-index target-repo target-branch)
(git:pull target-repo)
;; FIXME(Krey): Regex forge
(unless (string-null? push?) (git:push target-repo
(append-string "https://" username ":" token "@" forge "/" repo-owner "/" repo-name ".git")
target-branch)))
(sync-git-repository #:source-repo "https://git.savannah.gnu.org/git/guix.git"
#:source-branch "master"
#:target-repo (append-string (dirname (current-filename)) "/..")
#:target-branch "upstream"
#:push? #t
#:username (get-variable "USERNAME")
#:token (get-variable "TOKEN")
#:forge "https://git.dotya.ml/kreyren/guix-kreyren.git")
;;; sync-git-repo.scm ends here

35
automation/sync-upstream.ss Executable file

@ -0,0 +1,35 @@
#!/usr/bin/env sh
exec guile -s "$0" "$@"
!#
;;; DNM: Title
;;; Copyright (C) 2022 Jacob Hrbek <kreyren@rixotstudio.cz>
;;;
;;; This file is Free/Libre Open-Source Software; you may copy, redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
;;; This file 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 project. If not, see <http://www.gnu.org/licenses>
(use-modules (devops-tools sync-git-repository)
(devops-tools utils))
;;; Commentary:
;;;
;;; GNU Guile script designed to run every 10min to sync fork repository with the upstream
;;;
;;; Requires the following environment variables to be set:
;;; * USERNAME = Name of the user used for pushing
;;; * TOKEN = User Token or Password for pushing
;;;
;;; Code:
(sync-git-repository #:source-repo "https://git.savannah.gnu.org/git/guix.git"
#:source-branch "master"
;#:target-repo %repo-dir
#:target-repo "/home/kreyren/Repositories/guix"
#:target-branch "upstream"
#:push? #t
#:username (get-variable "USERNAME")
#:token (get-variable "TOKEN")
#:forge "https://git.dotya.ml/kreyren/guix-kreyren.git")
;;; sync-upstream.scm ends here