Skip to content

Update value of a variable (__version__) in a python file (version.py)

License

Notifications You must be signed in to change notification settings

platomo/update-version-py-action

Repository files navigation

🛠️ GitHub Action: Update Version Variable in Python File

📄 Description

This action updates the version number of a Python package by modifying a specific variable (default: __version__) in a Python file (default: version.py). If the version is set to nightly, the current date and time will be appended to the version.

⚙️ Inputs

Parameter Description Required Default
version Version number to set. Defaults to generating a nightly version. No nightly
variable The variable to update (e.g., __version__). No __version__
file-path Path to the directory containing the version.py file. No . (current directory)
file-name Name of the file where the version variable is located. No version.py

🚀 How It Works

The action searches for a line in the specified file (default: version.py) that starts with the variable = pattern (default: __version__ =). It replaces the current version number with either a custom version or an automatically generated nightly version.

  • If version is set to nightly, a version in the format nightly-YYYYMMDD-HHMMSS will be generated.
  • If a specific version is provided, it will replace the existing version.

📦 Usage Example

name: Update Package Version

on:
  push:
    branches:
      - main

jobs:
  update-version:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Update Python package version
        uses: platomo/update-version-py-action
        with:
          version: "1.0.0"
          file-path: "my_package"

In this example, the version variable in my_package/version.py is updated to 1.0.0.

⚖️ License

GNU GENERAL PUBLIC LICENSE Version 3

About

Update value of a variable (__version__) in a python file (version.py)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published