diff --git a/README-fr.md b/README-fr.md index 00a6488aead86d5875a73844cc6d7bc09a7e6e96..7c9bbe334bc4ab84999992ec162d1fa0be829ac6 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](https://docs.gitlab.com/user/ssh/) 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 762386d164ebf5331fee70c02725f9853fa0cea6..9d789818b4870fbb7aa866d38f064b0ab6e96358 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](https://docs.gitlab.com/user/ssh/) 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/includes-if/tags/git.yml b/includes-if/tags/git.yml new file mode 100644 index 0000000000000000000000000000000000000000..ff9c3c9dc46e877e7fcf8c7359f98aaae28a5ad6 --- /dev/null +++ b/includes-if/tags/git.yml @@ -0,0 +1,3 @@ +--- +.git: + tags: [$MGCI_TEST_GIT_JOB_TAGS] diff --git a/templates/bases/variables.yml b/templates/bases/variables.yml index 52e56cfb552353562e419eea702e9b1b304590b8..d77e776b9adaaee02e7e211f3f6d542c91e775d5 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 new file mode 100644 index 0000000000000000000000000000000000000000..bc7e64759d66376cba7400225032c8685587002f --- /dev/null +++ b/templates/git.yml @@ -0,0 +1,66 @@ +--- + +.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_GIT_VALUE} ]]; then + echo "Pull failed" + exit 1 + fi + echo "Pull ok" + +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 + 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 ${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@${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 add test/git/push_dummy.txt + 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 ${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} + +include: + - local: 'includes-if/tags/git.yml' + rules: + - if: $MGCI_TEST_GIT_JOB_TAGS diff --git a/test/git/pull_dummy.txt b/test/git/pull_dummy.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3b0635c10f5a0cdf5898842276433b2d67f0b7d --- /dev/null +++ b/test/git/pull_dummy.txt @@ -0,0 +1 @@ +7b3c88db4ed22d8782db409d3e2cc2f3 \ No newline at end of file