diff --git a/Jenkinsfile.cd b/Jenkinsfile.cd index d766f1b..33446d6 100644 --- a/Jenkinsfile.cd +++ b/Jenkinsfile.cd @@ -36,32 +36,6 @@ pipeline { stages { - /* ========================= - TESTS - ========================= */ - - stage('Backend: test (main)') { - agent { - docker { - image 'python:3.11-slim' - args '-u root' - } - } - steps { - dir('backend') { - sh ''' - set -e - python -m venv .venv - . .venv/bin/activate - pip install --upgrade pip - pip install -r requirements-dev.txt - pytest - ''' - } - } - } - - /* ========================= DOCKER BUILD ========================= */ diff --git a/Jenkinsfile.ci b/Jenkinsfile.ci index 51612d5..3db5ae0 100644 --- a/Jenkinsfile.ci +++ b/Jenkinsfile.ci @@ -57,7 +57,7 @@ pipeline { pip install --upgrade pip pip install -r requirements-dev.txt ruff check app tests - pytest -o cache_dir="$WORKSPACE/.cache/pytest" + pytest -o cache_dir="$WORKSPACE/.cache/pytest" --junitxml=pytest.xml ''' } } @@ -84,6 +84,7 @@ pipeline { mkdir -p "$NPM_CONFIG_CACHE" npm install --no-progress --no-audit --prefer-offline npm run check + mkdir -p test-results npm test npm run build ''' @@ -93,13 +94,74 @@ pipeline { } - post { - always { - script { - node { - cleanWs() +post { + always { + script { + node { + junit testResults: 'backend/pytest.xml', allowEmptyResults: true + junit testResults: 'frontend/test-results/junit.xml', allowEmptyResults: true + + if (env.CHANGE_ID) { + def giteaBase = 'https://openbokeron.org' + def owner = 'OpenBokeron' + def repo = 'TallerCiCd' + def pr = env.CHANGE_ID + + def result = currentBuild.currentResult + def msg = "" + + if (result == "SUCCESS") { + msg = """ + ✅ Todo en orden, camarada. + + - URL: ${env.BUILD_URL} + """.stripIndent().trim() + } + else if (result == "FAILURE") { + msg = """ + ❌ Alto ahí. ¿Qué clase de crímenes de guerra has cometido en esta PR? + + - URL: ${env.BUILD_URL} + """.stripIndent().trim() + } + else { + msg = """ + ⚠️ Dudoso… + + - URL: ${env.BUILD_URL} + """.stripIndent().trim() + } + + def commentsUrl = "${giteaBase}/gitea/api/v1/repos/${owner}/${repo}/issues/${pr}/comments" + + withCredentials([usernamePassword(credentialsId: 'jenkins-bot-api', + usernameVariable: 'GITEA_USER', + passwordVariable: 'GITEA_TOKEN')]) { + + def body = msg.replace('\\', '\\\\').replace('"','\\"').replace('\n','\\n') + + // Avoid interpolation of secret variables (https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation) + withEnv(["GITEA_COMMENTS_URL=${commentsUrl}", "GITEA_BODY=${body}"]) { + sh(label: 'Comentar en PR (Gitea)', script: ''' + curl -sS -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + --data-binary @- \ + "$GITEA_COMMENTS_URL" <