From 24b8e879e8bed0e9efab2b820f7fff5b0194b63d Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Thu, 25 Sep 2025 11:15:45 +0200 Subject: [PATCH 1/9] feat: test pull functionality --- templates/pull_push.yml | 12 ++++++++++++ test/git/dummy.txt | 1 + 2 files changed, 13 insertions(+) create mode 100644 templates/pull_push.yml create mode 100644 test/git/dummy.txt diff --git a/templates/pull_push.yml b/templates/pull_push.yml new file mode 100644 index 0000000..2dc5613 --- /dev/null +++ b/templates/pull_push.yml @@ -0,0 +1,12 @@ +--- + +pull: + stage: test + script: | + git pull $CI_PROJECT_URL $CI_DEFAULT_BRANCH + if [[ "$(< test/git/dummy.txt)" != $MGCI_TEST_VALUE ]]; then + exit 1 + fi + cat test/git/dummy.txt + + diff --git a/test/git/dummy.txt b/test/git/dummy.txt new file mode 100644 index 0000000..9af03fe --- /dev/null +++ b/test/git/dummy.txt @@ -0,0 +1 @@ +7b3c88db4ed22d8782db409d3e2cc2f \ No newline at end of file -- GitLab From d1e3a53b508949b670326282d231ddc2fddf7d76 Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Mon, 29 Sep 2025 15:58:41 +0200 Subject: [PATCH 2/9] feat: test push with ssh --- templates/pull_push.yml | 43 +++++++++++++++++++++++++++++++++++++++-- test/git/dummy.txt | 1 - test/git/pull_dummy.txt | 1 + 3 files changed, 42 insertions(+), 3 deletions(-) delete mode 100644 test/git/dummy.txt create mode 100644 test/git/pull_dummy.txt diff --git a/templates/pull_push.yml b/templates/pull_push.yml index 2dc5613..d4c6adf 100644 --- a/templates/pull_push.yml +++ b/templates/pull_push.yml @@ -4,9 +4,48 @@ pull: stage: test script: | git pull $CI_PROJECT_URL $CI_DEFAULT_BRANCH - if [[ "$(< test/git/dummy.txt)" != $MGCI_TEST_VALUE ]]; then + if [[ "$(< test/git/pull_dummy.txt)" != $MGCI_TEST_VALUE ]]; then exit 1 fi - cat test/git/dummy.txt + echo "Pull ok" + +push: + stage: test + before_script: | + apt-get update && apt-get install -y openssh-client git curl >/dev/null + mkdir -p ~/.ssh && chmod 700 ~/.ssh + echo -n "$SSH_PRIVATE_KEY_BASE64" | base64 -d > ~/.ssh/ssh_private_key + cat << EOF >> ~/.ssh/config + Host gitlab.com + User git + IdentityFile ~/.ssh/ssh_private_key + IdentitiesOnly yes + StrictHostKeyChecking no + EOF + + chmod -R 400 ~/.ssh/ssh_private_key ~/.ssh/config + + git config --global user.email ${GITLAB_USER_EMAIL} + git config --global user.name ${GITLAB_USER_NAME} + eval "$(ssh-agent -s)" + ssh-add ~/.ssh/ssh_private_key + git remote set-url origin git@gitlab.com:${CI_PROJECT_PATH}.git + + script: | + git branch tmp + git checkout tmp + echo "$MGCI_TEST_VALUE" > test/git/push_dummy.txt + git add test/git/push_dummy.txt + git commit -m "test" --allow-empty + git push origin -o ci.skip HEAD:tmp + sleep 10 + value="$(curl https://gitlab.com/froggit/tools/mgci/-/raw/tmp/test/git/push_dummy.txt?ref_type=heads)" + if [[ "$value" != "$MGCI_TEST_VALUE" ]]; then + echo "Push failed" + exit 1 + fi + echo "Push ok" + git push origin -d tmp + diff --git a/test/git/dummy.txt b/test/git/dummy.txt deleted file mode 100644 index 9af03fe..0000000 --- a/test/git/dummy.txt +++ /dev/null @@ -1 +0,0 @@ -7b3c88db4ed22d8782db409d3e2cc2f \ No newline at end of file diff --git a/test/git/pull_dummy.txt b/test/git/pull_dummy.txt new file mode 100644 index 0000000..a3b0635 --- /dev/null +++ b/test/git/pull_dummy.txt @@ -0,0 +1 @@ +7b3c88db4ed22d8782db409d3e2cc2f3 \ No newline at end of file -- GitLab From 3935ebe3b7e460632a1e3748d6967694fa8dfc1a Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Thu, 9 Oct 2025 12:01:53 +0200 Subject: [PATCH 3/9] feat: trigger with variable --- includes-if/tags/git.yml | 3 +++ templates/{pull_push.yml => git.yml} | 28 ++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 includes-if/tags/git.yml rename templates/{pull_push.yml => git.yml} (61%) diff --git a/includes-if/tags/git.yml b/includes-if/tags/git.yml new file mode 100644 index 0000000..ff9c3c9 --- /dev/null +++ b/includes-if/tags/git.yml @@ -0,0 +1,3 @@ +--- +.git: + tags: [$MGCI_TEST_GIT_JOB_TAGS] diff --git a/templates/pull_push.yml b/templates/git.yml similarity index 61% rename from templates/pull_push.yml rename to templates/git.yml index d4c6adf..bfe050e 100644 --- a/templates/pull_push.yml +++ b/templates/git.yml @@ -1,7 +1,14 @@ --- -pull: +.git: stage: test + variables: + MGCI_TEST_GIT_TMP_BRANCH: MGCI_TEST_GIT_TMP_BRANCH_${CI_COMMIT_SHORT_SHA} + rules: + - if: $MGCI_TEST_GIT == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') + +git:pull: + extends: .git script: | git pull $CI_PROJECT_URL $CI_DEFAULT_BRANCH if [[ "$(< test/git/pull_dummy.txt)" != $MGCI_TEST_VALUE ]]; then @@ -9,8 +16,8 @@ pull: fi echo "Pull ok" -push: - stage: test +git:push: + extends: .git before_script: | apt-get update && apt-get install -y openssh-client git curl >/dev/null mkdir -p ~/.ssh && chmod 700 ~/.ssh @@ -32,20 +39,25 @@ push: git remote set-url origin git@gitlab.com:${CI_PROJECT_PATH}.git script: | - git branch tmp - git checkout tmp + git branch $MGCI_TEST_GIT_TMP_BRANCH + git checkout $MGCI_TEST_GIT_TMP_BRANCH echo "$MGCI_TEST_VALUE" > test/git/push_dummy.txt git add test/git/push_dummy.txt git commit -m "test" --allow-empty - git push origin -o ci.skip HEAD:tmp + git push origin -o ci.skip HEAD:$MGCI_TEST_GIT_TMP_BRANCH sleep 10 - value="$(curl https://gitlab.com/froggit/tools/mgci/-/raw/tmp/test/git/push_dummy.txt?ref_type=heads)" + value="$(curl https://gitlab.com/froggit/tools/mgci/-/raw/$MGCI_TEST_GIT_TMP_BRANCH/test/git/push_dummy.txt?ref_type=heads)" if [[ "$value" != "$MGCI_TEST_VALUE" ]]; then echo "Push failed" exit 1 fi echo "Push ok" - git push origin -d tmp + git push origin -d $MGCI_TEST_GIT_TMP_BRANCH + +include: + - local: 'includes-if/tags/git.yml' + rules: + - if: $MGCI_TEST_GIT_JOB_TAGS -- GitLab From 036064ae4a930f32a47339294b12c46978827c60 Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Thu, 9 Oct 2025 12:27:11 +0200 Subject: [PATCH 4/9] doc: documentation for git test --- README-fr.md | 10 ++++++++++ README.md | 10 ++++++++++ templates/git.yml | 1 + 3 files changed, 21 insertions(+) diff --git a/README-fr.md b/README-fr.md index 00a6488..616bd97 100644 --- a/README-fr.md +++ b/README-fr.md @@ -68,10 +68,13 @@ Chaque fonctionnalité testée peut être activée avec une variable `MGCI_TEST_ | `MGCI_TEST_REGISTRY_GENERIC` | Lancement du test du registre de paquets génériques | `false` | | `MGCI_TEST_REGISTRY_CONTAINER` | Lancement du test du registre des conteneurs | `false` | | `MGCI_TEST_RUNNERS_TAGS` | Lancement du test des tags de runner | `false` | +| `MGCI_TEST_GIT` | Lancement du test de Git | `false` | | `MGCI_RUNNERS_TAGS` | Liste des Tags de runners à tester, format | `` | | `MGCI_API_TOKEN` | Token d'accès `Owner` au dépôt pour tester l'API | `` | | `MATTERMOST_URL` | URL de l'instance Mattermost à tester | `` | | `DOCKER_AUTH_CONFIG` | Chaîne d'autentification au Docker Hub | `` | +| `SSH_PRIVATE_KEY_BASE64` | Clé SSH privée encodée en Base64 pour tester le push git | `` | + ##### MGCI_API_TOKEN @@ -225,6 +228,7 @@ MGCI_TEST_CACHE_JOB_TAGS=cache - [x] Health check (uniquement disponible pour une instance auto-hébergée) - [X] Mattermost : Health check - [X] Environnement : création et destruction +- [X] Git: pull et push ### 🏗️ À venir @@ -311,6 +315,12 @@ Si vous activez ce test, il faut également créer la variable `MATTERMOST_URL`, - **Nom des jobs** : `runners:register` - **Description** : le job `runners:register` teste la fonctionnalité d'enregistrement et de suppression d'un runner. Il va enregistrer un runner pour le projet avec le tag `test-runner` puis le supprimer tout de suite après. +## Test de git + +- **Nom du fichier** : `templates/git.yml` +- **Nom des jobs** : `git:pull` et `git:push` +- **Description** : les tests `git:pull` et `git:push` consistent respectivement à vérifier l'intégrité d'une valeur test après un pull et un push. + ## Contribuer Ce projet étant sous la licence [GPL3](https://www.gnu.org/licenses/gpl.html), il est possible d'y contribuer pour y apporter des améliorations, des nouvelles fonctionnalités. diff --git a/README.md b/README.md index 762386d..36332eb 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,12 @@ Each tested feature can be activated with a `MGCI_TEST_` variable that | `MGCI_TEST_REGISTRY_GENERIC` | Run the generic packages registry test | `false` | | `MGCI_TEST_REGISTRY_CONTAINER` | Run the container registry test | `false` | | `MGCI_TEST_RUNNERS_TAGS` | Run the runner tags test | `false` | +| `MGCI_TEST_GIT` | Run the git tests | `false` | | `MGCI_RUNNERS_TAGS` | List of runner tags to test, format | `` | | `MGCI_API_TOKEN` | `Owner` access token to the repository for API testing | `` | | `MATTERMOST_URL` | URL of the Mattermost instance to test | `` | | `DOCKER_AUTH_CONFIG` | Docker Hub authentication chain | `` | +| `SSH_PRIVATE_KEY_BASE64` | BASE64 encode private SSH key for git pushing | `` | ##### MGCI_API_TOKEN @@ -224,6 +226,7 @@ MGCI_TEST_CACHE_JOB_TAGS=cache - [x] Health check (only available for self-hosted Gitlab) - [x] Mattermost: Health check - [x] Environment: creation and deletion +- [X] Git: pull and push ### 🏗️ Upcoming @@ -312,6 +315,13 @@ If you enable this test, you also need to create the `MATTERMOST_URL` variable, - **Job names**: `runners:register` - **Description**: the `runners:register` job tests the functionality of registering and deleting a runner. It will register a runner for the project with the `test-runner` tag and then delete it immediately after. +## Test de git + +- **Nom du fichier** : `templates/git.yml` +- **Nom des jobs** : `git:pull` and `git:push` +- **Description** : the `git:pull` and `git:push` jobs test a value after a pull and a push. + + ## Contributing This project is licensed under [GPL3](https://www.gnu.org/licenses/gpl.html), and contributions are welcome to bring improvements, new features, etc. diff --git a/templates/git.yml b/templates/git.yml index bfe050e..2aa3330 100644 --- a/templates/git.yml +++ b/templates/git.yml @@ -12,6 +12,7 @@ git:pull: script: | git pull $CI_PROJECT_URL $CI_DEFAULT_BRANCH if [[ "$(< test/git/pull_dummy.txt)" != $MGCI_TEST_VALUE ]]; then + echo "Pull failed" exit 1 fi echo "Pull ok" -- GitLab From c32432e9da1880ad592130ef0af0ab64a6bb7dc4 Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Thu, 9 Oct 2025 16:34:57 +0200 Subject: [PATCH 5/9] feat: corrections --- README-fr.md | 2 +- README.md | 2 +- templates/bases/variables.yml | 2 ++ templates/git.yml | 36 ++++++++++++++++++----------------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/README-fr.md b/README-fr.md index 616bd97..7c9bbe3 100644 --- a/README-fr.md +++ b/README-fr.md @@ -73,7 +73,7 @@ Chaque fonctionnalité testée peut être activée avec une variable `MGCI_TEST_ | `MGCI_API_TOKEN` | Token d'accès `Owner` au dépôt pour tester l'API | `` | | `MATTERMOST_URL` | URL de l'instance Mattermost à tester | `` | | `DOCKER_AUTH_CONFIG` | Chaîne d'autentification au Docker Hub | `` | -| `SSH_PRIVATE_KEY_BASE64` | Clé SSH privée encodée en Base64 pour tester le push git | `` | +| `SSH_PRIVATE_KEY_BASE64` | [Clé SSH privée](https://docs.gitlab.com/user/ssh/) encodée en Base64 pour tester le push git | `` | ##### MGCI_API_TOKEN diff --git a/README.md b/README.md index 36332eb..9d78981 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Each tested feature can be activated with a `MGCI_TEST_` variable that | `MGCI_API_TOKEN` | `Owner` access token to the repository for API testing | `` | | `MATTERMOST_URL` | URL of the Mattermost instance to test | `` | | `DOCKER_AUTH_CONFIG` | Docker Hub authentication chain | `` | -| `SSH_PRIVATE_KEY_BASE64` | BASE64 encode private SSH key for git pushing | `` | +| `SSH_PRIVATE_KEY_BASE64` | BASE64 encode [private SSH key](https://docs.gitlab.com/user/ssh/) for git pushing | `` | ##### MGCI_API_TOKEN diff --git a/templates/bases/variables.yml b/templates/bases/variables.yml index 9326897..73cb2fd 100644 --- a/templates/bases/variables.yml +++ b/templates/bases/variables.yml @@ -18,6 +18,7 @@ variables: MGCI_RUNNERS_TAGS: "" MGCI_API_TOKEN: "" DOCKER_AUTH_CONFIG: "" + MGCI_TEST_GIT_VALUE: "7b3c88db4ed22d8782db409d3e2cc2f3" # Test vars flags are set to false by default MGCI_TEST_API: "false" @@ -34,3 +35,4 @@ variables: MGCI_TEST_REGISTRY_NPM: "false" MGCI_TEST_REGISTRY_GENERIC: "false" MGCI_TEST_REGISTRY_CONTAINER: "false" + MGCI_TEST_GIT: "false" \ No newline at end of file diff --git a/templates/git.yml b/templates/git.yml index 2aa3330..bc7e647 100644 --- a/templates/git.yml +++ b/templates/git.yml @@ -7,11 +7,12 @@ rules: - if: $MGCI_TEST_GIT == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') + git:pull: extends: .git script: | - git pull $CI_PROJECT_URL $CI_DEFAULT_BRANCH - if [[ "$(< test/git/pull_dummy.txt)" != $MGCI_TEST_VALUE ]]; then + git pull ${CI_PROJECT_URL} ${CI_DEFAULT_BRANCH} + if [[ "$(< test/git/pull_dummy.txt)" != ${MGCI_TEST_GIT_VALUE} ]]; then echo "Pull failed" exit 1 fi @@ -19,10 +20,14 @@ git:pull: git:push: extends: .git + variables: + MGCI_TEST_VALUE: "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==" + COMMIT_EMAIL: "gitlab@runner.ci" + COMMIT_NAME: "Gitlab CI" before_script: | apt-get update && apt-get install -y openssh-client git curl >/dev/null mkdir -p ~/.ssh && chmod 700 ~/.ssh - echo -n "$SSH_PRIVATE_KEY_BASE64" | base64 -d > ~/.ssh/ssh_private_key + echo -n "${SSH_PRIVATE_KEY_BASE64}" | base64 -d > ~/.ssh/ssh_private_key cat << EOF >> ~/.ssh/config Host gitlab.com User git @@ -33,32 +38,29 @@ git:push: chmod -R 400 ~/.ssh/ssh_private_key ~/.ssh/config - git config --global user.email ${GITLAB_USER_EMAIL} - git config --global user.name ${GITLAB_USER_NAME} + git config --global user.email ${COMMIT_EMAIL} + git config --global user.name ${COMMIT_NAME} eval "$(ssh-agent -s)" ssh-add ~/.ssh/ssh_private_key - git remote set-url origin git@gitlab.com:${CI_PROJECT_PATH}.git + git remote set-url origin git@${CI_SERVER_SHELL_SSH_HOST}:${CI_PROJECT_PATH}.git script: | - git branch $MGCI_TEST_GIT_TMP_BRANCH - git checkout $MGCI_TEST_GIT_TMP_BRANCH - echo "$MGCI_TEST_VALUE" > test/git/push_dummy.txt + git branch ${MGCI_TEST_GIT_TMP_BRANCH} + git checkout ${MGCI_TEST_GIT_TMP_BRANCH} + echo "${MGCI_TEST_VALUE}" > test/git/push_dummy.txt git add test/git/push_dummy.txt - git commit -m "test" --allow-empty - git push origin -o ci.skip HEAD:$MGCI_TEST_GIT_TMP_BRANCH + git commit -m "${MGCI_TEST_GIT_TMP_BRANCH}" --allow-empty + git push origin -o ci.skip HEAD:${MGCI_TEST_GIT_TMP_BRANCH} sleep 10 - value="$(curl https://gitlab.com/froggit/tools/mgci/-/raw/$MGCI_TEST_GIT_TMP_BRANCH/test/git/push_dummy.txt?ref_type=heads)" - if [[ "$value" != "$MGCI_TEST_VALUE" ]]; then + value="$(curl ${CI_PROJECT_URL}/-/raw/${MGCI_TEST_GIT_TMP_BRANCH}/test/git/push_dummy.txt?ref_type=heads)" + if [[ "$value" != "${MGCI_TEST_VALUE}" ]]; then echo "Push failed" exit 1 fi echo "Push ok" - git push origin -d $MGCI_TEST_GIT_TMP_BRANCH + git push origin -d ${MGCI_TEST_GIT_TMP_BRANCH} include: - local: 'includes-if/tags/git.yml' rules: - if: $MGCI_TEST_GIT_JOB_TAGS - - - -- GitLab From 8d450f7bc5a28231649de573344a9f5bb4c5f263 Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Thu, 27 Nov 2025 12:16:22 +0100 Subject: [PATCH 6/9] doc: fix laguage mistake in doc --- README.md | 4 ++-- templates/git.yml | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9d78981..e72383c 100644 --- a/README.md +++ b/README.md @@ -317,8 +317,8 @@ If you enable this test, you also need to create the `MATTERMOST_URL` variable, ## Test de git -- **Nom du fichier** : `templates/git.yml` -- **Nom des jobs** : `git:pull` and `git:push` +- **File name** : `templates/git.yml` +- **Job name** : `git:pull` and `git:push` - **Description** : the `git:pull` and `git:push` jobs test a value after a pull and a push. diff --git a/templates/git.yml b/templates/git.yml index bc7e647..237047c 100644 --- a/templates/git.yml +++ b/templates/git.yml @@ -1,11 +1,14 @@ --- .git: + image: ubuntu:latest stage: test + before_script: + apt-get update && apt-get install git -y variables: MGCI_TEST_GIT_TMP_BRANCH: MGCI_TEST_GIT_TMP_BRANCH_${CI_COMMIT_SHORT_SHA} - rules: - - if: $MGCI_TEST_GIT == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') + # rules: + # - if: $MGCI_TEST_GIT == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') git:pull: -- GitLab From 9ef87c135885123eafa2f3d5305065af5fe48234 Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Mon, 1 Dec 2025 12:20:31 +0100 Subject: [PATCH 7/9] doc: updated documentation for projet deploy key --- README-fr.md | 12 ++++++++++-- README.md | 14 +++++++++++--- templates/git.yml | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README-fr.md b/README-fr.md index 7c9bbe3..6b03f07 100644 --- a/README-fr.md +++ b/README-fr.md @@ -73,7 +73,7 @@ Chaque fonctionnalité testée peut être activée avec une variable `MGCI_TEST_ | `MGCI_API_TOKEN` | Token d'accès `Owner` au dépôt pour tester l'API | `` | | `MATTERMOST_URL` | URL de l'instance Mattermost à tester | `` | | `DOCKER_AUTH_CONFIG` | Chaîne d'autentification au Docker Hub | `` | -| `SSH_PRIVATE_KEY_BASE64` | [Clé SSH privée](https://docs.gitlab.com/user/ssh/) encodée en Base64 pour tester le push git | `` | +| `SSH_PRIVATE_KEY_BASE64` | Clé SSH privée encodée en Base64. Voir [SSH_PRIVATE_KEY_BASE64](#####SSH_PRIVATE_KEY_BASE64) | `` | ##### MGCI_API_TOKEN @@ -81,6 +81,14 @@ Chaque fonctionnalité testée peut être activée avec une variable `MGCI_TEST_ Pour que l'ensemble des jobs fonctionne, un token doit avoir été généré sur votre instance Gitlab. Il peut s'agir d'un _project access token_, _personal access token_ ou _group access token_. Il doit avoir un accès `Owner` et doit avoir les scopes `api`, `create_runner` et `manage_runner`. Vous devrez ensuite le renseigner dans la variable `MGCI_API_TOKEN` dans les variables de la CI. +##### SSH_PRIVATE_KEY_BASE64 + +La connection en SSH doit se faire avec une [deploy key](https://docs.gitlab.com/user/project/deploy_keys/). + +- Générez une [paire de clés SSH](https://docs.gitlab.com/user/ssh/) +- Encodez la clé privée en base64 et renseignez la dans la variable CI/CD `SSH_PRIVATE_KEY_BASE64`. +- Renseignez la clé privé comme project deploy key avec accès en écriture. + ## Mises à jour du projet ### Suivi des versions @@ -319,7 +327,7 @@ Si vous activez ce test, il faut également créer la variable `MATTERMOST_URL`, - **Nom du fichier** : `templates/git.yml` - **Nom des jobs** : `git:pull` et `git:push` -- **Description** : les tests `git:pull` et `git:push` consistent respectivement à vérifier l'intégrité d'une valeur test après un pull et un push. +- **Description** : les tests `git:pull` et `git:push` consistent respectivement à vérifier l'intégrité d'une valeur test après un pull et un push. Nécéssite [SSH_PRIVATE_KEY_BASE64](#### Liste des variables disponibles). ## Contribuer diff --git a/README.md b/README.md index e72383c..a214b1d 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,21 @@ Each tested feature can be activated with a `MGCI_TEST_` variable that | `MGCI_API_TOKEN` | `Owner` access token to the repository for API testing | `` | | `MATTERMOST_URL` | URL of the Mattermost instance to test | `` | | `DOCKER_AUTH_CONFIG` | Docker Hub authentication chain | `` | -| `SSH_PRIVATE_KEY_BASE64` | BASE64 encode [private SSH key](https://docs.gitlab.com/user/ssh/) for git pushing | `` | +| `SSH_PRIVATE_KEY_BASE64` | Base64 encoded private SSH key. See [SSH_PRIVATE_KEY_BASE64](##### SSH_PRIVATE_KEY_BASE64) | `` | ##### MGCI_API_TOKEN For all jobs to work, a token must have been generated on your Gitlab instance. It can be a _project access token_, _personal access token_ or _group access token_. It must have Owner access and must have the `api`, `create_runner` and `manage_runner` scopes. You will then need to enter it in the `MGCI_API_TOKEN` variable in the CI variables. +##### SSH_PRIVATE_KEY_BASE64 + +The SSH connection should be done using a [project deploy key](https://docs.gitlab.com/user/project/deploy_keys/). + +- Generate an [SSH key pair](https://docs.gitlab.com/user/ssh/) +- Encode the private key in base64 and put it as the `SSH_PRIVATE_KEY_BASE64` CI/CD variable. +- Set the public key as the project deploy key with write access. + ## Updating the Project ### Keeping Up with Releases @@ -315,11 +323,11 @@ If you enable this test, you also need to create the `MATTERMOST_URL` variable, - **Job names**: `runners:register` - **Description**: the `runners:register` job tests the functionality of registering and deleting a runner. It will register a runner for the project with the `test-runner` tag and then delete it immediately after. -## Test de git +## Git test - **File name** : `templates/git.yml` - **Job name** : `git:pull` and `git:push` -- **Description** : the `git:pull` and `git:push` jobs test a value after a pull and a push. +- **Description** : the `git:pull` and `git:push` jobs test a value after a pull and a push. Requires [SSH_PRIVATE_KEY_BASE64](#### List of Available Variables) ## Contributing diff --git a/templates/git.yml b/templates/git.yml index 237047c..d4f50b5 100644 --- a/templates/git.yml +++ b/templates/git.yml @@ -7,8 +7,8 @@ apt-get update && apt-get install git -y variables: MGCI_TEST_GIT_TMP_BRANCH: MGCI_TEST_GIT_TMP_BRANCH_${CI_COMMIT_SHORT_SHA} - # rules: - # - if: $MGCI_TEST_GIT == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') + rules: + - if: $MGCI_TEST_GIT == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') git:pull: -- GitLab From e21e3e8350e26a111b0c41908b98117e219e12d3 Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Mon, 1 Dec 2025 16:17:10 +0100 Subject: [PATCH 8/9] fix: monitored branch --- templates/git.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/git.yml b/templates/git.yml index d4f50b5..dc38389 100644 --- a/templates/git.yml +++ b/templates/git.yml @@ -14,7 +14,9 @@ git:pull: extends: .git script: | - git pull ${CI_PROJECT_URL} ${CI_DEFAULT_BRANCH} + git checkout ${MGCI_VERSION} + rm -rf test/git/pull_dummy.txt + git pull ${CI_PROJECT_URL} ${MGCI_VERSION} if [[ "$(< test/git/pull_dummy.txt)" != ${MGCI_TEST_GIT_VALUE} ]]; then echo "Pull failed" exit 1 -- GitLab From a60631c0c075d3a383a7bac58b9f04239741edfc Mon Sep 17 00:00:00 2001 From: Celeste Robert Date: Mon, 1 Dec 2025 16:42:54 +0100 Subject: [PATCH 9/9] test --- templates/git.yml | 1 + test/git/pull_dummy.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/git.yml b/templates/git.yml index dc38389..1ec6030 100644 --- a/templates/git.yml +++ b/templates/git.yml @@ -16,6 +16,7 @@ git:pull: script: | git checkout ${MGCI_VERSION} rm -rf test/git/pull_dummy.txt + git reset --hard HEAD git pull ${CI_PROJECT_URL} ${MGCI_VERSION} if [[ "$(< test/git/pull_dummy.txt)" != ${MGCI_TEST_GIT_VALUE} ]]; then echo "Pull failed" diff --git a/test/git/pull_dummy.txt b/test/git/pull_dummy.txt index a3b0635..d8730f9 100644 --- a/test/git/pull_dummy.txt +++ b/test/git/pull_dummy.txt @@ -1 +1 @@ -7b3c88db4ed22d8782db409d3e2cc2f3 \ No newline at end of file +7b3c88db4ed22d8782db409d3e2cc2f3 -- GitLab