Skip to content

Commit

Permalink
Add get_next_release_version and commit sha to update internal releas…
Browse files Browse the repository at this point in the history
…e semver
  • Loading branch information
colin-rogers-dbt committed Jun 6, 2024
1 parent 647d751 commit b8e32b1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 20 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/get_next_release_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import re

from semantic_version import Version
from typing import List


def increment_latest_version(released_versions: List[str], target_version: str) -> Version:
"""Retrieve the latest version matching the major.minor and release stage
semantic version if it exists. Ignores the patch version.
Args:
released_versions (List[str]): List of semantic versions (1.0.0.0rc, 2.3.5) to match against
target_version (str): semantic version (1.0.0.0rc, 2.3.5) to match against
Returns:
Version: The latest version.
"""
target_version = Version.coerce(target_version)
latest_version = target_version
latest_version.prerelease = ("build0",)
for version in released_versions:
version = Version.coerce(version)
if (
version.major == latest_version.major
and version.minor == latest_version.minor
and version.patch == latest_version.patch
and version.prerelease > latest_version.prerelease
):
latest_version = version

next_pre = re.sub(r"\d+", lambda x: str(int(x.group()) + 1), latest_version.prerelease[0])
latest_version.prerelease = (next_pre,)
latest_version.build = []

return latest_version


def main():
parser = argparse.ArgumentParser(description="Get the next release version")
parser.add_argument("--released_versions", nargs="+", help="List of released versions")
parser.add_argument("--target_version", help="Target version to compare against")
args = parser.parse_args()
released_versions = args.released_versions
target_version = args.target_version
latest_version = increment_latest_version(released_versions, target_version)
print(latest_version)


if __name__ == "__main__":
main()
39 changes: 19 additions & 20 deletions .github/workflows/internal-archive-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ jobs:
aws configure set aws_secret_access_key ${{ secrets.AWS_ARCHIVE_SECRET_ACCESS_KEY }} --profile ${{ env.TEMP_PROFILE_NAME }}
aws configure set region ${{ secrets.AWS_REGION }} --profile ${{ env.TEMP_PROFILE_NAME }}
aws configure set output text --profile ${{ env.TEMP_PROFILE_NAME }}
aws codeartifact login --tool twine --repository ${{ secrets.AWS_REPOSITORY }} --domain ${{ secrets.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_DOMAIN_OWNER }} --region ${{ secrets.AWS_REGION }} --profile ${{ env.TEMP_PROFILE_NAME }}
aws codeartifact login --tool twine --repository ${{ secrets.AWS_REPOSITORY }} \
--domain ${{ secrets.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_DOMAIN_OWNER }} \
--region ${{ secrets.AWS_REGION }} --profile ${{ env.TEMP_PROFILE_NAME }}
- name: "Alter version in metadata of python package"
run: |
Expand All @@ -308,32 +310,29 @@ jobs:
version_in_file=$(grep -E 'version(: str)? =' "${version_file}" | cut -d '"' -f2)
# check the latest build of adapter code in our archive
versions_on_aws="$(aws codeartifact list-package-versions --repository ${{ secrets.AWS_REPOSITORY }} --domain ${{ secrets.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_DOMAIN_OWNER }} --region ${{ secrets.AWS_REGION }} --profile ${{ env.TEMP_PROFILE_NAME }} --format pypi --package dbt-${{ inputs.dbms_name }} --output json --query 'versions[*].version' | jq -r '.[]' | grep "^${{ inputs.version_number }}" || true )" # suppress pipefail only here
versions_on_aws="$(aws codeartifact list-package-versions --repository ${{ secrets.AWS_REPOSITORY }} \
--domain ${{ secrets.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_DOMAIN_OWNER }} \
--region ${{ secrets.AWS_REGION }} --profile ${{ env.TEMP_PROFILE_NAME }} --format pypi \
--package dbt-${{ inputs.dbms_name }} --output json \
--query 'versions[*].version' | jq -r '.[]' | grep "^${{ inputs.version_number }}" || true )" # suppress pipefail only here
current_latest_version="$(echo "${versions_on_aws}" | sort -V | tail -n 1 )"
internal_release_version ="$(python .github/scripts/get_next_release_version.py \
--released_versions $versions_on_aws \
--target_version ${{ inputs.version_number }})"
echo "[Debug] version_in_file: ${version_in_file}"
echo "[Debug] current_latest_version: ${current_latest_version}"
echo "[Debug] internal_release_version: ${internal_release_version}"
commit_sha="$(git rev-parse HEAD)"
echo ">>> Altering ${version_file}"
# Ensure a build+xxx where xxx is an integer is always present in versioning
# sed may be a no-op -- this is fine!
if [[ ${current_latest_version} =~ (.*build)([0-9]+)$ ]]; then
base="${BASH_REMATCH[1]}"
number="${BASH_REMATCH[2]}"
new_number=$((number + 1))
v="${base}${new_number}"
tee <<< "version = \"${v}\"" "${version_file}"
if [ -f "${setup_file}" ]; then
sed -i "s/^package_version = .*$/package_version = \"${v}\"/" "${setup_file}"
fi
else
v="${version_in_file}+build1"
tee <<< "version = \"${v}\"" "${version_file}"
if [ -f "${setup_file}" ]; then
sed -i "s/^package_version = .*$/package_version = \"${v}\"/" "${setup_file}"
fi
v="${internal_release_version}+${commit_sha}"
tee <<< "version = \"${v}\"" "${version_file}"
if [ -f "${setup_file}" ]; then
sed -i "s/^package_version = .*$/package_version = \"${v}\"/" "${setup_file}"
fi

################
# Build package
Expand Down

0 comments on commit b8e32b1

Please sign in to comment.