2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> pypi-tag-release.sh"
13 # Ensure we fail the job if any steps fail.
19 echo "INFO: Setting variables"
20 # Verify if using release file or parameters
21 if $USE_RELEASE_FILE; then
22 echo "INFO: Checking number of release yaml files"
23 release_files=$(git diff-tree --no-commit-id -r "$GIT_COMMIT" --name-only -- "releases/" ".releases/")
24 if (( $(echo "$release_files" | wc -w) != 1 )); then
25 echo "ERROR: RELEASE FILES: $release_files"
26 echo "ERROR: Committing multiple release files in the same commit OR rename/amend of existing files is not supported."
29 release_file="$release_files"
30 echo "INFO: RELEASE FILE: $release_file"
33 echo "INFO: This job is built with parameters, no release file"
37 if [[ -z ${DISTRIBUTION_TYPE:-} ]]; then
38 echo "INFO: reading DISTRIBUTION_TYPE from file $release_file"
39 DISTRIBUTION_TYPE="$(niet ".distribution_type" "$release_file")"
41 if [[ -z ${VERSION:-} ]]; then
42 echo "INFO: reading VERSION from file $release_file"
43 VERSION="$(niet ".version" "$release_file")"
46 # Display Release Information
47 printf "\t%-30s\n" RELEASE_ENVIRONMENT_INFO:
48 printf "\t%-30s %s\n" RELEASE_FILE: $release_file
49 printf "\t%-30s %s\n" JENKINS_HOSTNAME: $JENKINS_HOSTNAME
50 printf "\t%-30s %s\n" SILO: $SILO
51 printf "\t%-30s %s\n" PROJECT: $PROJECT
52 printf "\t%-30s %s\n" PROJECT-DASHED: ${PROJECT//\//-}
53 printf "\t%-30s %s\n" DISTRIBUTION_TYPE: $DISTRIBUTION_TYPE
54 printf "\t%-30s %s\n" VERSION: $VERSION
57 # needs to run in the repository root
59 echo "INFO: Fetching schema"
60 pypi_schema="release-pypi-schema.yaml"
61 wget https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${pypi_schema}
62 echo "INFO: Verifying $release_file against schema $pypi_schema"
63 lftools schema verify "$release_file" "$pypi_schema"
64 echo "INFO: $release_file passed schema verification"
68 # Verify allowed patterns "v#.#.#" or "#.#.#" aka SemVer
69 echo "INFO: Verifying version string $VERSION"
70 allowed_version_regex="^((v?)([0-9]+)\.([0-9]+)\.([0-9]+))$"
71 if [[ $VERSION =~ $allowed_version_regex ]]; then
72 echo "INFO: The version $VERSION is a valid semantic version"
74 echo "ERROR: The version $VERSION is not a valid semantic version"
75 echo "ERROR: Allowed versions are \"v#.#.#\" or \"#.#.#\" aka SemVer"
76 echo "ERROR: See https://semver.org/ for more details on SemVer"
82 # Verify all file names in dist folder have the expected version string
83 dir="$WORKSPACE/$TOX_DIR/dist"
84 echo "INFO: Listing files in $dir"
86 echo "INFO: Checking files in $dir for $VERSION"
87 if unex_files=$(find $dir | grep -v $VERSION | egrep -v "^$dir$"); then
88 echo "ERROR: found unexpected files: $unex_files"
91 echo "INFO: All file names have expected string ${VERSION}"
95 # TODO: how to tag Github?
97 echo "INFO: Verifying tag $VERSION in repo"
98 # Import public signing key
99 gpg --import "$SIGNING_PUBKEY"
101 if git tag -v "$VERSION"; then
102 echo "ERROR: Repo already tagged"
105 echo "INFO: Repo has not yet been tagged"
107 echo "INFO: Tagging repo"
108 git tag -am "${PROJECT//\//-} $VERSION" "$VERSION"
109 echo "INFO: Signing tag"
110 sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$VERSION" < "$SIGUL_PASSWORD"
111 echo "INFO: Verifying tag"
112 # may fail due to missing public key
113 if ! git tag -v "$VERSION"; then
114 echo "WARN: failed to verify tag, continuing anyhow"
116 # The verify job also calls this script
117 if [[ ! $JOB_NAME =~ "merge" ]] ; then
118 echo "INFO: job is not a merge, skipping push"
120 echo "INFO: configuring Gerrit remote"
121 gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
122 git remote set-url origin "ssh://$RELEASE_USERNAME@$gerrit_ssh:29418/$PROJECT"
123 git config user.name "$RELEASE_USERNAME"
124 git config user.email "$RELEASE_EMAIL"
125 echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
126 chmod 600 ~/.ssh/config
128 echo "INFO: dry run, skipping push"
130 echo "INFO: pushing tag"
131 git push origin "$VERSION"
137 virtualenv -p python3 /tmp/pypi
138 PATH=/tmp/pypi/bin:$PATH
139 pip install lftools jsonschema niet
141 if [[ $DISTRIBUTION_TYPE != "pypi" ]]; then
142 echo "ERROR: unexpected distribution type $DISTRIBUTION_TYPE"
145 if $USE_RELEASE_FILE; then
151 echo "---> pypi-tag-release.sh ends"