From ee2249b4bd8f30a805b5098f7830dab6ad4ad412 Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Thu, 22 Sep 2022 08:34:44 +0200 Subject: [PATCH 1/5] automation/pull-mirror: Initial declaration --- automation/pull-upstream.scm | 28 ++++++++++++++++++++++++++++ automation/zz-README.org | 1 + 2 files changed, 29 insertions(+) create mode 100755 automation/pull-upstream.scm create mode 100644 automation/zz-README.org diff --git a/automation/pull-upstream.scm b/automation/pull-upstream.scm new file mode 100755 index 0000000000..f924c913fa --- /dev/null +++ b/automation/pull-upstream.scm @@ -0,0 +1,28 @@ +#!/usr/bin/env sh +exec guile -s "$0" "$@" +!# +;;; The Project Manager ("pman") -- GNU Guile-based solution for project management +;;; Copyright (C) 2022 Jacob Hrbek +;;; +;;; 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 + +;(use-modules ()) + +(define (git-checkout branch) + "Git checkout on set BRANCH" + (system* "git" "checkout" branch)) + +(git-checkout "upstream") + +(define* (git-pull remote #:optional branch) + "Git pull from REMOTE and optional BRANCH" + (system* + "git" + "pull" + remote)) + +(git-pull "upstream" "master") + diff --git a/automation/zz-README.org b/automation/zz-README.org new file mode 100644 index 0000000000..fc45631386 --- /dev/null +++ b/automation/zz-README.org @@ -0,0 +1 @@ +Directory storing scripts used by Continuous Integration and Delivery ("CI/CD") -- 2.47.0 From 31b035b6b1e4d82c1bf97253d538ed038a6d427e Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Thu, 22 Sep 2022 11:18:49 +0200 Subject: [PATCH 2/5] Add guile script to pull upstream --- automation/common.scm | 19 ++++++++++++++++++ automation/hotfixes.scm | 33 ++++++++++++++++++++++++++++++++ automation/pull-upstream.scm | 37 ++++++++++++++++++------------------ 3 files changed, 70 insertions(+), 19 deletions(-) create mode 100755 automation/common.scm create mode 100755 automation/hotfixes.scm diff --git a/automation/common.scm b/automation/common.scm new file mode 100755 index 0000000000..2be4aed5df --- /dev/null +++ b/automation/common.scm @@ -0,0 +1,19 @@ +#!/usr/bin/env sh +exec guile -s "$0" "$@" +!# +;;;C DNM: Title +;;;C Copyright (C) 2022 Jacob Hrbek +;;;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 + +;(use-modules ()) + +;;; GNU Guile script library for definitions used for automation + +;;; String containing the full path to the project's repository +(define %repodir (string-append (dirname (current-filename)) "/..")) + +;;; common.scm ends here diff --git a/automation/hotfixes.scm b/automation/hotfixes.scm new file mode 100755 index 0000000000..a378039d01 --- /dev/null +++ b/automation/hotfixes.scm @@ -0,0 +1,33 @@ +#!/usr/bin/env sh +exec guile -s "$0" "$@" +!# +;;;C DNM: Title +;;;C Copyright (C) 2022 Jacob Hrbek +;;;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 + +;(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 diff --git a/automation/pull-upstream.scm b/automation/pull-upstream.scm index f924c913fa..aec0c5a4f6 100755 --- a/automation/pull-upstream.scm +++ b/automation/pull-upstream.scm @@ -1,28 +1,27 @@ #!/usr/bin/env sh exec guile -s "$0" "$@" !# -;;; The Project Manager ("pman") -- GNU Guile-based solution for project management -;;; Copyright (C) 2022 Jacob Hrbek -;;; -;;; 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 +;;;C DNM: Title +;;;C Copyright (C) 2022 Jacob Hrbek +;;;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 -;(use-modules ()) +#;(use-modules + (git) + (git checkout)) -(define (git-checkout branch) - "Git checkout on set BRANCH" - (system* "git" "checkout" branch)) +;;; GNU Guile script to keep the 'upstream' branch up to date with upstream repository -(git-checkout "upstream") +(load (string-append (dirname (current-filename)) "/common.scm")) +(load (string-append (dirname (current-filename)) "/hotfixes.scm")) -(define* (git-pull remote #:optional branch) - "Git pull from REMOTE and optional BRANCH" - (system* - "git" - "pull" - remote)) +(git:checkout-index %repodir "upstream") -(git-pull "upstream" "master") +(git:pull %repodir) +(git:push %repodir "upstream") + +;;;X pull-upstream.scm ends here -- 2.47.0 From e5365cb96db5b0a45b86b0b5584608d70fc704de Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Thu, 22 Sep 2022 15:41:33 +0200 Subject: [PATCH 3/5] Initial DroneCI + Upstream Sync --- .drone.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100755 index 0000000000..3007746cbf --- /dev/null +++ b/.drone.yml @@ -0,0 +1,18 @@ +kind: pipeline +type: docker +name: default + +steps: +- name: Sync Upstream + image: alpine:3.16.2 + environment: + USERNAME: + from_secret: dotya_username + TOKEN: + from_secret: dotya_token + commands: + - apk add guile git # Install dependencies + - git config --global --add safe.directory /drone/src # Stupid drone issue + - git checkout upstream + - git pull + - git push "https://$USERNAME:$TOKEN@git.dotya.ml/kreyren/guix-kreyren.git" upstream -- 2.47.0 From a2d8eaad301b92dc671b800a6f893b1944df301c Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Thu, 22 Sep 2022 20:23:42 +0200 Subject: [PATCH 4/5] Staging changes --- automation/common.scm | 7 ++++- automation/pull-upstream.scm | 53 +++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/automation/common.scm b/automation/common.scm index 2be4aed5df..fea08d415f 100755 --- a/automation/common.scm +++ b/automation/common.scm @@ -14,6 +14,11 @@ exec guile -s "$0" "$@" ;;; GNU Guile script library for definitions used for automation ;;; String containing the full path to the project's repository -(define %repodir (string-append (dirname (current-filename)) "/..")) +(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 diff --git a/automation/pull-upstream.scm b/automation/pull-upstream.scm index aec0c5a4f6..95250578e8 100755 --- a/automation/pull-upstream.scm +++ b/automation/pull-upstream.scm @@ -9,19 +9,52 @@ exec guile -s "$0" "$@" ;;;C ;;;C You should have received a copy of the GNU General Public license along with this project. If not, see -#;(use-modules - (git) - (git checkout)) +(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)) -;;; GNU Guile script to keep the 'upstream' branch up to date with upstream repository +;;; Commentary: +;;; +;;; FIXME-DOCS +;;; +;;; Code: -(load (string-append (dirname (current-filename)) "/common.scm")) -(load (string-append (dirname (current-filename)) "/hotfixes.scm")) +(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")))) -(git:checkout-index %repodir "upstream") + "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. -(git:pull %repodir) +This procedure is designed to manage pull-based mirroring" -(git:push %repodir "upstream") + ;; FIXME(Krey): Sanity for inputs -;;;X pull-upstream.scm ends here + (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 -- 2.47.0 From 369652f4af7cd5a220e45b50730f128dff35545f Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Fri, 23 Sep 2022 12:09:47 +0200 Subject: [PATCH 5/5] sync --- automation/common.scm | 24 --------------- automation/hotfixes.scm | 33 -------------------- automation/pull-upstream.scm | 60 ------------------------------------ automation/sync-upstream.ss | 35 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 117 deletions(-) delete mode 100755 automation/common.scm delete mode 100755 automation/hotfixes.scm delete mode 100755 automation/pull-upstream.scm create mode 100755 automation/sync-upstream.ss diff --git a/automation/common.scm b/automation/common.scm deleted file mode 100755 index fea08d415f..0000000000 --- a/automation/common.scm +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env sh -exec guile -s "$0" "$@" -!# -;;;C DNM: Title -;;;C Copyright (C) 2022 Jacob Hrbek -;;;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 - -;(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 diff --git a/automation/hotfixes.scm b/automation/hotfixes.scm deleted file mode 100755 index a378039d01..0000000000 --- a/automation/hotfixes.scm +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env sh -exec guile -s "$0" "$@" -!# -;;;C DNM: Title -;;;C Copyright (C) 2022 Jacob Hrbek -;;;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 - -;(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 diff --git a/automation/pull-upstream.scm b/automation/pull-upstream.scm deleted file mode 100755 index 95250578e8..0000000000 --- a/automation/pull-upstream.scm +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env sh -exec guile -s "$0" "$@" -!# -;;;C DNM: Title -;;;C Copyright (C) 2022 Jacob Hrbek -;;;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 - -(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 diff --git a/automation/sync-upstream.ss b/automation/sync-upstream.ss new file mode 100755 index 0000000000..5cb60744b5 --- /dev/null +++ b/automation/sync-upstream.ss @@ -0,0 +1,35 @@ +#!/usr/bin/env sh +exec guile -s "$0" "$@" +!# +;;; DNM: Title +;;; Copyright (C) 2022 Jacob Hrbek +;;; +;;; 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 + +(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 -- 2.47.0