Skip to content

Commit 94c2d78

Browse files
BUILD-4657: use standard build scripts for poetry
Signed-off-by: Jayadeep Kinavoor Madam <[email protected]>
1 parent 1c907c0 commit 94c2d78

File tree

4 files changed

+114
-36
lines changed

4 files changed

+114
-36
lines changed

.cirrus.yml

+37-36
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
artifactory_build: &artifactory_build
1+
env:
2+
ARTIFACTORY_URL: VAULT[development/kv/data/repox data.url]
3+
ARTIFACTORY_DEPLOY_REPO: sonarsource-pypi-public-qa
4+
ARTIFACTORY_PRIVATE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]
25
ARTIFACTORY_DEPLOY_USERNAME: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer username]
3-
ARTIFACTORY_DEPLOY_PASSWORD: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
4-
5-
artifactory_private: &artifactory_private
6-
ARTIFACTORY_PRIVATE_USERNAME: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader username]
7-
ARTIFACTORY_PRIVATE_PASSWORD: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]
6+
ARTIFACTORY_DEPLOY_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
7+
DEPLOY_PULL_REQUEST: 'true'
88

99
container_definition: &CONTAINER_DEFINITION
1010
dockerfile: .cirrus/poetry.Dockerfile
@@ -15,42 +15,43 @@ container_definition: &CONTAINER_DEFINITION
1515
builder_role: cirrus-builder
1616
builder_image: docker-builder-v*
1717
builder_instance_type: t3.small
18-
builder_subnet_id: ${CIRRUS_AWS_SUBNET}
18+
builder_subnet_ids: ${CIRRUS_AWS_SUBNETS}
19+
use_in_memory_disk: true
20+
docker_arguments:
21+
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
22+
cpu: 3
23+
memory: 8G
1924

20-
only_sonarsource_qa: &ONLY_SONARSOURCE_QA
21-
only_if: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == "master")
22-
23-
env:
24-
CIRRUS_SHELL: bash
25-
ARTIFACTORY_URL: VAULT[development/kv/data/repox data.url]
26-
ARTIFACTORY_DEPLOY_REPO: sonarsource-pypi-public-qa
25+
only_if: $CIRRUS_USER_COLLABORATOR == "true" && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == $CIRRUS_DEFAULT_BRANCH || $CIRRUS_BRANCH =~ "feature/*" || $CIRRUS_BRANCH =~ "dogfood-on-.*")
2726

27+
poetry_cache_template: &POETRY_CACHE
28+
poetry_cache:
29+
folder: .cache/poetry/
30+
fingerprint_script: cat poetry.lock
2831

29-
build_task:
32+
.poetry_template: &POETRY_TEMPLATE
3033
eks_container:
3134
<<: *CONTAINER_DEFINITION
32-
cpu: 2
33-
memory: 2G
34-
env:
35-
<<: *artifactory_build
36-
build_script:
37-
- poetry install
38-
- poetry version $(poetry version -s).${CI_BUILD_NUMBER}
39-
- poetry build
40-
- poetry config repositories.sonarsource https://repox.jfrog.io/artifactory/api/pypi/${ARTIFACTORY_DEPLOY_REPO}
41-
- poetry publish -r sonarsource --username ${ARTIFACTORY_DEPLOY_USERNAME} --password ${ARTIFACTORY_DEPLOY_PASSWORD} --verbose
35+
<<: *POETRY_CACHE
36+
poetry_install_script:
37+
- source .cirrus/set_poetry_build_version "$CI_BUILD_NUMBER"
38+
- echo "PROJECT_VERSION=$PROJECT_VERSION" >> $CIRRUS_ENV
39+
- jfrog config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PRIVATE_ACCESS_TOKEN"
40+
- jfrog poetry-config --server-id-resolve repox --repo-resolve sonarsource-pypi
41+
- jfrog poetry install --build-name="$CIRRUS_REPO_NAME" --build-number="$CI_BUILD_NUMBER"
42+
43+
build_task:
44+
<<: *POETRY_TEMPLATE
45+
alias: build
46+
name: "Build"
47+
build_script: .cirrus/poetry_build_publish
4248

4349
promote_task:
44-
<<: *ONLY_SONARSOURCE_QA
45-
eks_container:
46-
<<: *CONTAINER_DEFINITION
47-
cpu: 2
48-
memory: 2G
50+
depends_on:
51+
- build
4952
env:
5053
ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
51-
promote_script:
52-
# Temporary hack script until https://sonarsource.atlassian.net/browse/BUILD-4592 is completed
53-
# Artifact is copied to sonarsource-pypi-public-builds repo for testing the release workflow as part of https://sonarsource.atlassian.net/browse/BUILD-4501
54-
- export VERSION=$(poetry version -s).$CI_BUILD_NUMBER
55-
- jfrog config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PROMOTE_ACCESS_TOKEN"
56-
- jfrog rt cp sonarsource-pypi-public-qa/sonar_dummy_python_oss/$VERSION/ sonarsource-pypi-public-builds/sonar_dummy_python_oss/$VERSION/
54+
GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token]
55+
ARTIFACTS: sonar-summy-python-oss
56+
<<: *POETRY_TEMPLATE
57+
promote_script: .cirrus/cirrus_promote_python

.cirrus/cirrus_promote_python

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# JFrog promotion, notify GitHub and Burgr
3+
# shellcheck source=/dev/null
4+
5+
set -euo pipefail
6+
7+
: "${CIRRUS_BRANCH?}" "${CIRRUS_DEFAULT_BRANCH?}" "${CI_BUILD_NUMBER?}" "${CIRRUS_REPO_NAME?}"
8+
9+
echo ">> Promote Python build"
10+
set +o verbose
11+
source cirrus-env PROMOTE
12+
set -o verbose
13+
jfrog config remove repox
14+
cirrus_jfrog_promote
15+
16+
if [[ -v GITHUB_TOKEN ]]; then
17+
github-notify-promotion
18+
else
19+
echo "GITHUB_TOKEN unset: skipping build number commit status on GitHub"
20+
fi

.cirrus/poetry_build_publish

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Regular way to build a SonarSource Poetry project.
3+
# - ARTIFACTORY_DEPLOY_REPO: deployment repository (sonarsource-pypi-public-qa or sonarsource-pypi-private-qa)
4+
# shellcheck source=/dev/null
5+
6+
set -euo pipefail
7+
8+
: "${ARTIFACTORY_URL?}" "${ARTIFACTORY_DEPLOY_REPO?}" "${ARTIFACTORY_DEPLOY_ACCESS_TOKEN?}"
9+
: "${CIRRUS_BRANCH?}" "${CIRRUS_DEFAULT_BRANCH?}" "${CI_BUILD_NUMBER?}" "${CIRRUS_REPO_NAME?}"
10+
11+
function jfrog_poetry_publish() {
12+
jfrog config remove repox
13+
jfrog config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_DEPLOY_ACCESS_TOKEN"
14+
project_name=$(poetry version | awk {'print $1'})
15+
pushd dist
16+
jfrog rt upload ./ "$ARTIFACTORY_DEPLOY_REPO/$project_name/$PROJECT_VERSION/" --module="$project_name:$PROJECT_VERSION" \
17+
--build-name="$CIRRUS_REPO_NAME" --build-number="$CI_BUILD_NUMBER"
18+
popd
19+
jfrog rt build-collect-env "$CIRRUS_REPO_NAME" "$CI_BUILD_NUMBER"
20+
jfrog rt build-publish "$CIRRUS_REPO_NAME" "$CI_BUILD_NUMBER" \
21+
--env-include 'PROJECT;GIT_*;*VERSION*;BUILD_*;GITHUB_*;CIRRUS_*;*BRANCH*;*ID' \
22+
--env-exclude "*login*;*pass*;*psw*;*pwd*;*secret*;*key*;*token*;*auth*"
23+
}
24+
25+
poetry build
26+
if [[ -n "${CIRRUS_PR:-}" ]]; then
27+
if [ "${DEPLOY_PULL_REQUEST:-}" == "true" ]; then
28+
jfrog_poetry_publish
29+
fi
30+
elif [[ "$CIRRUS_BRANCH" = "$CIRRUS_DEFAULT_BRANCH" || "$CIRRUS_BRANCH" =~ ^"branch-" || "$CIRRUS_BRANCH" =~ ^"dogfood-on-" ]]; then
31+
jfrog_poetry_publish
32+
fi

.cirrus/set_poetry_build_version

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
BUILD_ID=$1
5+
6+
if ! current_version=$(poetry version -s); then
7+
echo "Could not get version from Poetry project ('poetry version -s')" >&2
8+
echo "$current_version"
9+
exit 1
10+
fi
11+
release_version=${current_version%".dev"*}
12+
# In case of 2 digits, we need to add a '0' as the 3rd digit.
13+
digit_count=$(echo "${release_version//./ }" | wc --words)
14+
if [[ "$digit_count" -lt 3 ]]; then
15+
release_version="$release_version.0"
16+
fi
17+
if [[ "$digit_count" -gt 3 && $release_version =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
18+
release_version="${BASH_REMATCH[0]}"
19+
echo "WARN: version was truncated to $release_version because it had more than 3 digits"
20+
fi
21+
new_version="$release_version.${BUILD_ID}"
22+
23+
echo "Replacing version $current_version with $new_version"
24+
poetry version "$new_version"
25+
export PROJECT_VERSION=$new_version

0 commit comments

Comments
 (0)