diff --git a/.github/scripts/release.py b/.github/scripts/release.py deleted file mode 100644 index b421abe..0000000 --- a/.github/scripts/release.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 -import json -import subprocess - - -def get_last_version() -> str: - """Return the version number of the last release.""" - json_string = ( - subprocess.run( - ["gh", "release", "view", "--json", "tagName"], - check=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - .stdout.decode("utf8") - .strip() - ) - - return json.loads(json_string)["tagName"] - - -def bump_patch_number(version_number: str) -> str: - """Return a copy of `version_number` with the patch number incremented.""" - major, minor, patch = version_number.split(".") - return f"{major}.{minor}.{int(patch) + 1}" - - -def create_new_patch_release(): - """Create a new patch release on GitHub.""" - try: - last_version_number = get_last_version() - except subprocess.CalledProcessError as err: - if err.stderr.decode("utf8").startswith("HTTP 404:"): - # The project doesn't have any releases yet. - new_version_number = "0.0.1" - else: - raise - else: - new_version_number = bump_patch_number(last_version_number) - - subprocess.run( - ["gh", "release", "create", "--generate-notes", new_version_number], - check=True, - ) - - -if __name__ == "__main__": - create_new_patch_release() diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a5340a..a0eada8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,8 +3,14 @@ name: Build and Test on: pull_request: branches: [ main ] + paths-ignore: + - '**/_version.py' push: branches: [ main ] + tags-ignore: + - 'v*' + paths-ignore: + - '**/_version.py' jobs: test: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0691aa4..6311e3b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,16 +16,78 @@ on: default: true jobs: + bump: + name: Bump version + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + outputs: + VERSION: ${{ steps.get-version-and-commit-sha.outputs.VERSION }} + SHORT_VERSION: ${{ steps.get-version-and-commit-sha.outputs.SHORT_VERSION }} + MAJOR_VERSION: ${{ steps.get-version-and-commit-sha.outputs.MAJOR_VERSION }} + MINOR_VERSION: ${{ steps.get-version-and-commit-sha.outputs.MINOR_VERSION }} + COMMIT_SHA: ${{ steps.get-version-and-commit-sha.outputs.COMMIT_SHA }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: 3.11 + cache: 'pip' + - name: Set up AllenInstitute Repo Authorization + uses: ./.github/actions/setup-ai-github-urls + with: + token: ${{ secrets.AI_PACKAGES_TOKEN }} + - name: Get tags + run: git fetch --tags origin + - name: Configure git for github-actions[bot] + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + - name: Run Install + run: | + make install-release + shell: bash + - name: Bump version with bumpversion + run: | + source .venv/bin/activate + bump-my-version bump ${{ github.event.inputs.part }} + - name: Commit and push with tags + if: ${{ github.event.inputs.dry-run == 'false' }} + run: | + git push --follow-tags + - name: Get version and commit SHA + id: get-version-and-commit-sha + run: | + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + # remove the leading v from tag + version="${latest_tag:1}" + echo "VERSION=$version" >> $GITHUB_OUTPUT + major_version="$(cut -d '.' -f 1 <<< $version)" + echo "MAJOR_VERSION=$major_version" >> $GITHUB_OUTPUT + minor_version="$(cut -d '.' -f 2 <<< $version)" + echo "MINOR_VERSION=$minor_version" >> $GITHUB_OUTPUT + short_version="$major_version.$minor_version" + echo "SHORT_VERSION=$short_version" >> $GITHUB_OUTPUT + commit_sha=$(git rev-parse $latest_tag) + echo "COMMIT_SHA=$commit_sha" >> $GITHUB_OUTPUT + - name: Show short version + run: echo ${{ steps.get-version-and-commit-sha.outputs.SHORT_VERSION }} build: name: Build distribution runs-on: ubuntu-latest + needs: bump strategy: fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 + with: + ref: ${{ needs.bump.outputs.COMMIT_SHA }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: diff --git a/Makefile b/Makefile index a4d9752..e95def5 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,11 @@ $(INSTALL_STAMP): $(PYTHON) $(DEP_FILES) $(PIP) install -e .[dev]; @touch $(INSTALL_STAMP) +install-release: clean-install-stamp $(PYTHON) $(DEP_FILES) ## Installs package for release + @. $(VENV_BIN)/activate;\ + $(PIP) install .[release] + + install-force: clean-install-stamp install ## Force install package dependencies link-packages: ## Link local packages to virtualenv @@ -166,9 +171,8 @@ coverage-server: $(INSTALL_STAMP) ## Run coverage server ##@ Release Commands ##################### -dist: $(PYTHON) $(DEP_FILES) ## Build source and wheel package +dist: install-release ## Build source and wheel package @. $(VENV_BIN)/activate;\ - $(PIP) install .[release];\ $(PYTHON) -m build; reinstall: obliterate install ## Recreate environment and install diff --git a/pyproject.toml b/pyproject.toml index 151fd53..ece5995 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dependencies = [ release = [ "build", + "bump-my-version", "twine", "wheel", ] @@ -195,3 +196,29 @@ line_length = 99 profile = "black" src_paths = ["src", "test"] +# ----------------------------------------------------------------------------- +## bumpversion Configurations +# https://callowayproject.github.io/bump-my-version/ +# ----------------------------------------------------------------------------- + +[tool.bumpversion] +allow_dirty = false +commit = true +commit_args = "" +current_version = "0.0.1" +ignore_missing_version = false +message = "Bump version: {current_version} → {new_version}" +parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" +regex = false +replace = "{new_version}" +search = "{current_version}" +serialize = ["{major}.{minor}.{patch}"] +sign_tags = false +tag = true +tag_message = "Bump version: {current_version} → {new_version}" +tag_name = "v{new_version}" + +[[tool.bumpversion.files]] +filename = "src/aibs_informatics_test_resources/__version__.py" +search = "__version__ = \"{current_version}\"" +replace = "__version__ = \"{new_version}\"" \ No newline at end of file