diff --git a/jobs/swh-packages.yaml b/jobs/swh-packages.yaml --- a/jobs/swh-packages.yaml +++ b/jobs/swh-packages.yaml @@ -10,6 +10,8 @@ - "{name}/tests" - "{name}/tests-on-diff" - "{name}/gitlab-tests" + - "{name}/gitlab-incoming-tag" + - "{name}/gitlab-pypi-upload" - "debian/packages/{name}" - "debian/packages/{name}/update-for-release" - "debian/packages/{name}/automatic-backport" diff --git a/jobs/templates/incoming-tag.groovy.j2 b/jobs/templates/incoming-tag.groovy.j2 --- a/jobs/templates/incoming-tag.groovy.j2 +++ b/jobs/templates/incoming-tag.groovy.j2 @@ -6,6 +6,20 @@ steps { checkout([ $class: 'GitSCM', + {%- if gitlab_project %} + userRemoteConfigs: [[ + name:'origin', url: '{{gitlab_url}}/{{gitlab_project_name}}.git', + refspec: '+refs/tags/*:refs/remotes/origin/tags*' + ]], + branches: [[ + name: "${env.gitlabSourceBranch}" + ]], + browser: [ + $class: 'GitLab', + repoUrl: '{{gitlab_url}}/{{gitlab_project_name}}' + ], + extensions: [[$class: 'CloneOption', honorRefspec: true]], + {%- else %} userRemoteConfigs: [[ url: 'https://forge.softwareheritage.org/source/{{repo_name}}.git', ]], @@ -17,24 +31,40 @@ repo: '{{repo_name}}', repoUrl: 'https://forge.softwareheritage.org/', ], + {%- endif %} ]) } } stage('Build and upload PyPI package') { when { + {%- if gitlab_project %} + expression { "${env.gitlabSourceBranch}" ==~ /refs\/tags\/v\d+(.\d+)+/ } + expression { jobExists('/{{name}}/gitlab-pypi-upload') } + {%- else %} expression { params.GIT_TAG ==~ /v\d+(.\d+)+/ } expression { jobExists('/{{name}}/pypi-upload') } + {%- endif %} + } steps { build( + {%- if gitlab_project %} + job: '/{{name}}/gitlab-pypi-upload', + {%- else %} job: '/{{name}}/pypi-upload', + {%- endif %} parameters: [ + {%- if gitlab_project %} + string(name: 'GIT_TAG', value: "${env.gitlabSourceBranch}"), + {%- else %} string(name: 'GIT_TAG', value: params.GIT_TAG), + {%- endif %} string(name: 'PYPI_HOST', value: '{{incoming_tag_auto_pypi_host}}'), ], ) } } + {%- if not gitlab_project %} stage('Update Debian packaging for new release') { when { expression { params.GIT_TAG ==~ /v\d+(.\d+)+/ } @@ -67,5 +97,6 @@ ) } } + {%- endif %} } } diff --git a/jobs/templates/incoming-tag.yaml b/jobs/templates/incoming-tag.yaml --- a/jobs/templates/incoming-tag.yaml +++ b/jobs/templates/incoming-tag.yaml @@ -2,9 +2,10 @@ name: "{name}/incoming-tag" display-name: Incoming tag project-type: pipeline - auth-token: 'ph4br1cat0r' + auth-token: "ph4br1cat0r" incoming_tag_auto_pypi_host: pypi.org sandbox: true + gitlab_project: false properties: - build-discarder: num-to-keep: 20 @@ -15,11 +16,23 @@ type: PT_TAG sortMode: DESCENDING_SMART selectedValue: TOP - dsl: - !include-jinja2: incoming-tag.groovy.j2 + dsl: !include-jinja2: incoming-tag.groovy.j2 - job-template: name: "debian/deps/{name}/incoming-tag" - dsl: - !include-jinja2: dependency-incoming-tag.groovy.j2 + dsl: !include-jinja2: dependency-incoming-tag.groovy.j2 + <<: *incoming_tag + +- job-template: + name: "{name}/gitlab-incoming-tag" + display-name: Incoming tag (GitLab) + gitlab_project: true + parameters: + triggers: + - gitlab: + trigger-push: true + trigger-merge-request: false + add-ci-message: true + # secret jenkins token is generated when executing tox + secret-token: !include-raw: jenkins-token <<: *incoming_tag diff --git a/jobs/templates/swh-pypi.groovy.j2 b/jobs/templates/swh-pypi.groovy.j2 --- a/jobs/templates/swh-pypi.groovy.j2 +++ b/jobs/templates/swh-pypi.groovy.j2 @@ -31,7 +31,11 @@ agent none steps { build( + {%- if gitlab_project %} + job: '/{{name}}/gitlab-tests', + {%- else %} job: '/{{name}}/tests', + {%- endif %} parameters: [ string(name: 'REVISION', value: params.GIT_TAG), ], @@ -42,13 +46,25 @@ stage('Checkout') { steps { - checkout([$class: 'GitSCM', - branches: [[name: params.GIT_TAG]], - doGenerateSubmoduleConfigurations: false, - extensions: [], - gitTool: 'Default', - submoduleCfg: [], - userRemoteConfigs: [[url: 'https://forge.softwareheritage.org/source/{{repo_name}}.git']] + checkout([ + $class: 'GitSCM', + {%- if gitlab_project %} + userRemoteConfigs: [[ + name:'origin', url: '{{gitlab_url}}/{{gitlab_project_name}}.git', + refspec: '+refs/tags/*:refs/remotes/origin/tags*' + ]], + branches: [[ + name: "${params.GIT_TAG}" + ]], + extensions: [[$class: 'CloneOption', honorRefspec: true]], + {%- else %} + userRemoteConfigs: [[url: 'https://forge.softwareheritage.org/source/{{repo_name}}.git']], + branches: [[name: params.GIT_TAG]], + {%- endif %} + doGenerateSubmoduleConfigurations: false, + extensions: [], + gitTool: 'Default', + submoduleCfg: [], ]) sh '''rm -rf dist/''' } @@ -82,6 +98,7 @@ } } + {%- if not gitlab_project %} stage('Publish') { when { anyOf { @@ -102,6 +119,7 @@ } } } + {%- endif %} } post { cleanup { diff --git a/jobs/templates/swh-pypi.yaml b/jobs/templates/swh-pypi.yaml --- a/jobs/templates/swh-pypi.yaml +++ b/jobs/templates/swh-pypi.yaml @@ -1,15 +1,16 @@ -- job-template: +- job-template: &pypi_upload name: "{name}/pypi-upload" display-name: "Upload to PyPI" docker_image: tox include_bdist: true project-type: pipeline sandbox: true + gitlab_project: false properties: - build-discarder: artifact-num-to-keep: 10 - copyartifact: - projects: '*' + projects: "*" parameters: - git-parameter: name: GIT_TAG @@ -45,8 +46,13 @@ Proceed even if the tests are failing on the repository. - bool: name: INCLUDE_BDIST - default: '{include_bdist}' + default: "{include_bdist}" description: | Include a binary distribution in the PyPI upload. - dsl: - !include-jinja2: swh-pypi.groovy.j2 + dsl: !include-jinja2: swh-pypi.groovy.j2 + +- job-template: + name: "{name}/gitlab-pypi-upload" + display-name: "Upload to PyPI (GitLab)" + gitlab_project: true + <<: *pypi_upload diff --git a/jobs/tools/setup-gitlab-webhooks.groovy.j2 b/jobs/tools/setup-gitlab-webhooks.groovy.j2 --- a/jobs/tools/setup-gitlab-webhooks.groovy.j2 +++ b/jobs/tools/setup-gitlab-webhooks.groovy.j2 @@ -33,6 +33,8 @@ def repoName= project.get('project').get('repo_name') def gitlabProjectName = "swh/devel/${repoName}" setupGitlabWebhook(gitlabProjectName, "${jenkinsFolder}/gitlab-tests") + setupGitlabWebhook(gitlabProjectName, "${jenkinsFolder}/gitlab-incoming-tag", + false, false, true) } } }