diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1a1c536..597ecaf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,50 @@ +variables: + # https://hub.docker.com/r/alpine/git/tags + GIT_VERSION: v2.30.1 + +.git:push: + after_script: + # Go to the new directory + - cd "${CI_COMMIT_SHA}" + + - pwd + + - ls + + # Add all generated files to Git + - git add README.md + + - git status + + - |- + # Check if we have modifications to commit + CHANGES=$(git status --porcelain | wc -l) + + if [ "$CHANGES" -gt "0" ]; then + # Show the status of files that are about to be created, updated or deleted + git status + + # Commit all changes + git commit -m "${COMMIT_MESSAGE}" + + # Update the repository and make sure to skip the pipeline create for this commit + git push origin "${CI_DEFAULT_BRANCH}" -o ci.skip + fi + before_script: + # Clone the repository via HTTPS inside a new directory + - git clone "https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "${CI_COMMIT_SHA}" + + # Set the displayed user with the commits that are about to be made + - git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}" + - git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}" + image: + entrypoint: [""] + name: alpine/git:${GIT_VERSION} + stage: deploy + stages: - render - - commit + - deploy check_readme_changes: stage: render @@ -27,24 +71,10 @@ check_readme_changes: - README.qmd when: always -commit_and_push: - stage: commit - image: alpine:latest - before_script: - - apk add --no-cache git +deploy: + extends: .git:push script: - - | - if git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep -q 'README.qmd'; then - git config --global user.email "ci@example.com" - git config --global user.name "CI Bot" - git remote remove origin - git remote add origin https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git - git add README.md - git commit -m "[ci skip]: maj auto du README.md après rendu Quarto" - git push origin HEAD:$CI_COMMIT_REF_NAME - else - echo "Aucun commit/push nécessaire." - fi + - mv README.md "${CI_COMMIT_SHA}/" dependencies: - check_readme_changes rules: