Loading .gitlab-ci.yml +27 −57 Original line number Diff line number Diff line Loading @@ -3,9 +3,10 @@ image: python:3.12 variables: PROJECT: "noctua" PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" FORMAT_TARGETS: "noctua" # For sed, autopep8, isort PYLINT_TARGETS: "noctua" # For pylint FORMAT_TARGETS: "${PROJECT}" # For sed, autopep8, isort PYLINT_TARGETS: "${PROJECT}" # For pylint GIT_USER_EMAIL: "davide.ricci@inaf.it" GIT_USER_NAME: "Davide GitLab CI" FORMATTED_BRANCH_NAME: "validated" Loading @@ -18,11 +19,11 @@ cache: stages: - setup_and_format - lint # A stage for checks that don't modify code (like pylint) - lint # Does not modify code - auto_commit # Job 1: Install Noctua and its dependencies install_noctua: # Job 1: Install ${PROJECT} and its dependencies install_project: stage: setup_and_format tags: - git-run-ia2 Loading @@ -31,9 +32,9 @@ install_noctua: - ls -la - echo "Python version $(python -v)" - pip install --upgrade pip - echo "Installing project 'noctua' and its dependencies..." - echo "Installing project '${PROJECT}' and its dependencies..." - pip install -e . - echo "Noctua installation complete." - echo "${PROJECT} installation complete." artifacts: paths: # Pass the entire workspace. This includes the checked-out code Loading @@ -46,7 +47,7 @@ fix_trailing_whitespaces: tags: - git-run-ia2 needs: - job: install_noctua - job: install_project artifacts: true script: - echo "Current directory $(pwd)" Loading Loading @@ -129,12 +130,13 @@ commit_formatted_code: - job: run_pylint # Must pass pylint - job: apply_autopep8 # Needs the final code state from formatting artifacts: true script: - echo "Pushing on validated branch..." after_script: before_script: - git fetch origin ${FORMATTED_BRANCH_NAME} - git checkout ${FORMATTED_BRANCH_NAME} - git config --global user.email "davide.ricci@inaf.it" - git config --global user.name "CI Bot" - git checkout -b validated script: - echo "Pushing on ${FORMATTED_BRANCH_NAME} branch..." - git add . - MAIN_COMMIT_MSG=$(git log -1 --pretty=%B $CI_COMMIT_SHA) - | Loading @@ -144,38 +146,6 @@ commit_formatted_code: - Job ID: $CI_JOB_ID - Pipeline ID: $CI_PIPELINE_ID" - git pull - git push https://davide.ricci:$GITLAB_TOKEN@www.ict.inaf.it/gitlab/davide.ricci/software-di-controllo.git $(FORMATTED_BRANCH_NAME) - git push https://davide.ricci:$GITLAB_TOKEN@www.ict.inaf.it/gitlab/davide.ricci/software-di-controllo.git ${FORMATTED_BRANCH_NAME} # before_script: # # Git and SSH setup (ensure SSH_DEPLOY_KEY CI/CD variable is set as File type) # - apt-get update -y && apt-get install -y openssh-client git # - eval $(ssh-agent -s) # - mkdir -p ~/.ssh && chmod 700 ~/.ssh # - echo "$SSH_DEPLOY_KEY" | tr -d '\r' > ~/.ssh/id_ci_deploy && chmod 600 ~/.ssh/id_ci_deploy # - ssh-add ~/.ssh/id_ci_deploy # - ssh-keyscan -p ${CI_SERVER_PORT:-22} $CI_SERVER_HOST >> ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts # - git config --global user.email "${GIT_USER_EMAIL}" # - git config --global user.name "${GIT_USER_NAME}" # # Ensure we are on the correct branch and have the latest files from artifacts # - git checkout "$CI_COMMIT_BRANCH" # script: # - echo "Checking for formatting changes to commit..." # - | # # Add only the formatted targets to avoid committing other unintended changes # git add "${FORMAT_TARGETS}" # # if ! git diff --cached --quiet HEAD; then # Check staged changes against HEAD # echo "Code formatting changes applied. Committing to branch '${CI_COMMIT_BRANCH}'." # # Option 1: Commit to a NEW branch (Safer) # git checkout -B "${FORMATTED_BRANCH_NAME}" # git commit -m "ci: Apply automated code formatting [skip ci]" # git push -u origin "${FORMATTED_BRANCH_NAME}" -o ci.skip # echo "Changes pushed to new branch '${FORMATTED_BRANCH_NAME}'. Please review and merge." # else # echo "No formatting changes to commit." # fi # rules: # # Example: Only run manually on the default branch after all checks pass # - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE != "schedule" # Avoid on schedules # when: manual # Make this a conscious decision # allow_failure: false # If it runs, it must succeed Loading
.gitlab-ci.yml +27 −57 Original line number Diff line number Diff line Loading @@ -3,9 +3,10 @@ image: python:3.12 variables: PROJECT: "noctua" PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" FORMAT_TARGETS: "noctua" # For sed, autopep8, isort PYLINT_TARGETS: "noctua" # For pylint FORMAT_TARGETS: "${PROJECT}" # For sed, autopep8, isort PYLINT_TARGETS: "${PROJECT}" # For pylint GIT_USER_EMAIL: "davide.ricci@inaf.it" GIT_USER_NAME: "Davide GitLab CI" FORMATTED_BRANCH_NAME: "validated" Loading @@ -18,11 +19,11 @@ cache: stages: - setup_and_format - lint # A stage for checks that don't modify code (like pylint) - lint # Does not modify code - auto_commit # Job 1: Install Noctua and its dependencies install_noctua: # Job 1: Install ${PROJECT} and its dependencies install_project: stage: setup_and_format tags: - git-run-ia2 Loading @@ -31,9 +32,9 @@ install_noctua: - ls -la - echo "Python version $(python -v)" - pip install --upgrade pip - echo "Installing project 'noctua' and its dependencies..." - echo "Installing project '${PROJECT}' and its dependencies..." - pip install -e . - echo "Noctua installation complete." - echo "${PROJECT} installation complete." artifacts: paths: # Pass the entire workspace. This includes the checked-out code Loading @@ -46,7 +47,7 @@ fix_trailing_whitespaces: tags: - git-run-ia2 needs: - job: install_noctua - job: install_project artifacts: true script: - echo "Current directory $(pwd)" Loading Loading @@ -129,12 +130,13 @@ commit_formatted_code: - job: run_pylint # Must pass pylint - job: apply_autopep8 # Needs the final code state from formatting artifacts: true script: - echo "Pushing on validated branch..." after_script: before_script: - git fetch origin ${FORMATTED_BRANCH_NAME} - git checkout ${FORMATTED_BRANCH_NAME} - git config --global user.email "davide.ricci@inaf.it" - git config --global user.name "CI Bot" - git checkout -b validated script: - echo "Pushing on ${FORMATTED_BRANCH_NAME} branch..." - git add . - MAIN_COMMIT_MSG=$(git log -1 --pretty=%B $CI_COMMIT_SHA) - | Loading @@ -144,38 +146,6 @@ commit_formatted_code: - Job ID: $CI_JOB_ID - Pipeline ID: $CI_PIPELINE_ID" - git pull - git push https://davide.ricci:$GITLAB_TOKEN@www.ict.inaf.it/gitlab/davide.ricci/software-di-controllo.git $(FORMATTED_BRANCH_NAME) - git push https://davide.ricci:$GITLAB_TOKEN@www.ict.inaf.it/gitlab/davide.ricci/software-di-controllo.git ${FORMATTED_BRANCH_NAME} # before_script: # # Git and SSH setup (ensure SSH_DEPLOY_KEY CI/CD variable is set as File type) # - apt-get update -y && apt-get install -y openssh-client git # - eval $(ssh-agent -s) # - mkdir -p ~/.ssh && chmod 700 ~/.ssh # - echo "$SSH_DEPLOY_KEY" | tr -d '\r' > ~/.ssh/id_ci_deploy && chmod 600 ~/.ssh/id_ci_deploy # - ssh-add ~/.ssh/id_ci_deploy # - ssh-keyscan -p ${CI_SERVER_PORT:-22} $CI_SERVER_HOST >> ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts # - git config --global user.email "${GIT_USER_EMAIL}" # - git config --global user.name "${GIT_USER_NAME}" # # Ensure we are on the correct branch and have the latest files from artifacts # - git checkout "$CI_COMMIT_BRANCH" # script: # - echo "Checking for formatting changes to commit..." # - | # # Add only the formatted targets to avoid committing other unintended changes # git add "${FORMAT_TARGETS}" # # if ! git diff --cached --quiet HEAD; then # Check staged changes against HEAD # echo "Code formatting changes applied. Committing to branch '${CI_COMMIT_BRANCH}'." # # Option 1: Commit to a NEW branch (Safer) # git checkout -B "${FORMATTED_BRANCH_NAME}" # git commit -m "ci: Apply automated code formatting [skip ci]" # git push -u origin "${FORMATTED_BRANCH_NAME}" -o ci.skip # echo "Changes pushed to new branch '${FORMATTED_BRANCH_NAME}'. Please review and merge." # else # echo "No formatting changes to commit." # fi # rules: # # Example: Only run manually on the default branch after all checks pass # - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE != "schedule" # Avoid on schedules # when: manual # Make this a conscious decision # allow_failure: false # If it runs, it must succeed