Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version during release #46

Closed
mehmetcanay opened this issue Jun 14, 2024 · 4 comments · Fixed by #52
Closed

Update version during release #46

mehmetcanay opened this issue Jun 14, 2024 · 4 comments · Fixed by #52
Assignees
Labels
enhancement New feature or request

Comments

@mehmetcanay
Copy link
Member

mehmetcanay commented Jun 14, 2024

Update the versions of API (in routes.py) and PDataViewer (in package-lock.json) automatically during release.

@mehmetcanay mehmetcanay added the enhancement New feature or request label Jun 14, 2024
@mehmetcanay mehmetcanay added this to the Release v0.0.3 milestone Jun 14, 2024
@mehmetcanay mehmetcanay self-assigned this Jun 14, 2024
@mehmetcanay
Copy link
Member Author

mehmetcanay commented Jun 17, 2024

For Angular versioning I found this: https://medium.com/@tolvaly.zs/how-to-version-number-angular-6-applications-4436c03a3bd3

For API versioning I found a code snippet like this:

- name: Increment API Version
      id: increment_version
      run: |
        import re

        file_path = "backend/routes.py"

        # Read the routes.py file
        with open(file_path, "r") as file:
            content = file.read()

        # Find the current version using regex
        version_pattern = re.compile(r'version="(\d+\.\d+\.\d+)"')
        current_version = version_pattern.search(content).group(1)

        # Increment the patch version
        major, minor, patch = map(int, current_version.split('.'))
        new_version = f"{major}.{minor}.{patch + 1}"

        # Replace the old version with the new version
        new_content = version_pattern.sub(f'version="{new_version}"', content)

        # Write the new content back to routes.py
        with open(file_path, "w") as file:
            file.write(new_content)

        print(f"Updated version from {current_version} to {new_version}")
      shell: python

@tiadams what is your opinion on these, I can implement both of these easily if you also think they are OK.

@mehmetcanay mehmetcanay changed the title Update api version in routes.py during release Update version during release Jun 17, 2024
@tiadams
Copy link
Member

tiadams commented Jun 17, 2024

For Angular versioning I found this: https://medium.com/@tolvaly.zs/how-to-version-number-angular-6-applications-4436c03a3bd3

For API versioning I found a code snippet like this:

- name: Increment API Version
      id: increment_version
      run: |
        import re

        file_path = "backend/routes.py"

        # Read the routes.py file
        with open(file_path, "r") as file:
            content = file.read()

        # Find the current version using regex
        version_pattern = re.compile(r'version="(\d+\.\d+\.\d+)"')
        current_version = version_pattern.search(content).group(1)

        # Increment the patch version
        major, minor, patch = map(int, current_version.split('.'))
        new_version = f"{major}.{minor}.{patch + 1}"

        # Replace the old version with the new version
        new_content = version_pattern.sub(f'version="{new_version}"', content)

        # Write the new content back to routes.py
        with open(file_path, "w") as file:
            file.write(new_content)

        print(f"Updated version from {current_version} to {new_version}")
      shell: python

@tiadams what is your opinion on these, I can implement both of these easily if you also think they are OK.

This seems a bit overkill imo, we also already got the version from the current tag, should be solvable in one line by just editing the file, e.g. via sed. I did it here the other way around (getting the version from the API):
echo "BACKEND_VERSION=$(echo "$(<backend/api/routes.py)" | grep -oP "(?<=version=\")[^\"]+")" >> "$GITHUB_OUTPUT"

@mehmetcanay
Copy link
Member Author

CURRENT_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
VERSION=$(echo $CURRENT_TAG | grep -oP "(?<=v\.)[\d\.]+")
ROUTES_FILE="backend/api/routes.py"
PACKAGE_FILE="frontend/package-lock.json"
sed -i "s/version=\"[^\"]*\"/version=\"$VERSION\"/" $ROUTES_FILE
sed -i "s/version=\"[^\"]*\"/version=\"$VERSION\"/" $PACKAGE_FILE

Something like this?

@mehmetcanay
Copy link
Member Author

CURRENT_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
VERSION=$(echo $CURRENT_TAG | grep -oP "(?<=v\.)[\d\.]+")
ROUTES_FILE="backend/api/routes.py"
PACKAGE_FILE="frontend/package-lock.json"
sed -i "s/version=\"[^\"]*\"/version=\"$VERSION\"/" $ROUTES_FILE
sed -i "s/version=\"[^\"]*\"/version=\"$VERSION\"/" $PACKAGE_FILE

Something like this?

nvm this will not work for package-lock.json, I am looking for a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants