diff --git a/jobs/templates/swh-pypi.groovy b/jobs/templates/swh-pypi.groovy index 1423d46..a45bc0b 100644 --- a/jobs/templates/swh-pypi.groovy +++ b/jobs/templates/swh-pypi.groovy @@ -1,64 +1,72 @@ +def PYPI_UPLOAD_HOST + +switch (params.PYPI_HOST) {{ + case 'pypi.org': + PYPI_UPLOAD_HOST = 'upload.pypi.org' + break + default: + PYPI_UPLOAD_HOST = params.PYPI_HOST + break +}} + pipeline {{ agent {{ label 'swh-tox' }} stages {{ stage('Run tests') {{ agent none steps {{ build( job: '/{name}/tests', parameters: [ string(name: 'REVISION', value: params.GIT_TAG), ], propagate: !params.IGNORE_TESTS, ) }} }} stage('Checkout') {{ steps {{ checkout([$class: 'GitSCM', branches: [[name: params.GIT_TAG]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[url: 'https://forge.softwareheritage.org/source/{display-name}.git']] ]) }} }} stage('Build') {{ steps {{ sh 'python3 setup.py sdist bdist_wheel' archiveArtifacts allowEmptyArchive: true, artifacts: 'dist/*', fingerprint: true }} }} stage('Publish') {{ when {{ anyOf {{ expression {{ return params.FORCE_UPLOAD }} expression {{ LASTV=sh(returnStdout: true, - script:'curl -s https://${{PYPI}}/pypi/`python setup.py --name`/json | jq -r .info.version || true').trim() + script:'curl -s https://${{PYPI_HOST}}/pypi/`python setup.py --name`/json | jq -r .info.version || true').trim() return 'v'+LASTV != params.GIT_TAG }} }} }} steps {{ withCredentials([ - usernamePassword(credentialsId: "${{params.PYPI}}", + usernamePassword(credentialsId: PYPI_UPLOAD_HOST, usernameVariable: 'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD')]) {{ - sh ''' - if [ -z "$PYPI_UPLOAD" ]; then PYPI_UPLOAD=$PYPI; fi - python3 -m twine upload --repository-url https://${{PYPI_UPLOAD}}/legacy/ dist/* - ''' + sh "python3 -m twine upload --repository-url https://${{PYPI_UPLOAD_HOST}}/legacy/ dist/*" }} }} }} }} }} diff --git a/jobs/templates/swh-pypi.yaml b/jobs/templates/swh-pypi.yaml index a718eeb..41edf17 100644 --- a/jobs/templates/swh-pypi.yaml +++ b/jobs/templates/swh-pypi.yaml @@ -1,40 +1,38 @@ - job-template: name: "{name}/pypi-upload" display-name: "Upload to PyPI" project-type: pipeline sandbox: true properties: - build-discarder: num-to-keep: 20 parameters: - git-parameter: name: GIT_TAG description: git tag to process type: PT_TAG sortMode: DESCENDING_SMART selectedValue: TOP - - string: - name: PYPI + - choice: + name: PYPI_HOST description: | PYPI registry to publish to when built revision is a tag. There must exists a usernamePassword credential object with that name. - The pypi JSON API endpoint is built as https://$PYPI/project//json + The pypi JSON API endpoint is built as https://$PYPI_HOST/project//json + choices: + - test.pypi.org + - pypi.org default: test.pypi.org - - string: - name: PYPI_UPLOAD - description: | - PYPI upload base host. If unset, defaults to $PYPI. The upload endpoint is built as - https://$PYPI_UPLOAD/legacy/ - bool: name: FORCE_UPLOAD default: false description: | Force uploading python packages on the chosen PYPI registry, even if the package already exists. - bool: name: IGNORE_TESTS default: false description: | Proceed even if the tests are failing on the repository. dsl: !include-raw: swh-pypi.groovy