Skip to content

Commit 79bc496

Browse files
authored
Fix portability issues with MacOS & Linux (#263)
1 parent daab988 commit 79bc496

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

.github/workflows/release-pypi-build-push-test-package.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ jobs:
3636
3737
- name: bump_test_version
3838
run: |
39-
make bump-test-version RELEASE_VERSION=${{ github.event.inputs.version }}
39+
if [ -z "${{ github.event.inputs.version }}" ]; then
40+
echo "No version input provided, running without RELEASE_VERSION."
41+
make bump-test-version
42+
else
43+
echo "Version input provided: ${{ github.event.inputs.version }}"
44+
make bump-test-version RELEASE_VERSION=${{ github.event.inputs.version }}
45+
fi
46+
shell: bash
4047

4148
- name: clean
4249
run: |

Makefile

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@ LEVERAGE_TESTING_TAG := 2.5.0
44
LEVERAGE_IMAGE_TAG := 1.2.7-0.0.5
55
PYPROJECT_FILE := pyproject.toml
66
INIT_FILE := leverage/__init__.py
7-
RELEASE_VERSION ?= $(shell curl -sL "https://test.pypi.org/pypi/leverage/json" | jq -r ".releases | keys | sort | .[-1]" | awk 'BEGIN{FS="."; OFS="."} {print $$1,$$2,$$3+1}' )rc.1
87
PLACEHOLDER := 0.0.0
98

9+
# Detect OS
10+
UNAME_S := $(shell uname -s)
11+
12+
# Default tools
13+
SED := sed
14+
SORT := sort
15+
16+
ifeq ($(UNAME_S),Darwin)
17+
# Ensuring commands are compatible and errors are handled gracefully
18+
SED := $(shell if command -v gsed >/dev/null 2>&1; then echo 'gsed'; else echo 'sed'; fi)
19+
SORT := $(shell if command -v gsort >/dev/null 2>&1; then echo 'gsort'; else echo 'sort'; fi)
20+
endif
21+
22+
RELEASE_VERSION ?= $(shell curl -sL "https://pypi.org/pypi/leverage/json" | jq -r ".releases | keys[]" | $(SORT) -V | tail -n 1 | awk 'BEGIN{FS="."; OFS="."} {print $$1,$$2,$$3+1}' )rc1
23+
1024
help:
1125
@echo 'Available Commands:'
12-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " - \033[36m%-18s\033[0m %s\n", $$1, $$2}'
26+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | $(SORT) | awk 'BEGIN {FS = ":.*?## "}; {printf " - \033[36m%-18s\033[0m %s\n", $$1, $$2}'
1327

1428
build-image: ## Build docker image for testing
1529
docker build . -t ${LEVERAGE_TESTING_IMAGE}:${LEVERAGE_TESTING_TAG}
@@ -47,27 +61,33 @@ push-ci: ## Push distributables to PyPi (to be used in CI)
4761
push-test: ## Push distributables to Pypi test
4862
poetry run twine upload --repository testpypi dist/*
4963

50-
bump-test-version: ## Bump version based on TestPyPI or provided input
51-
@echo "[INFO] Get current version from __init__.py"
64+
bump-test-version: ## Bump version based on PyPI latest release or provided input
65+
@echo "[INFO] Get current version from leverage/__init__.py"
5266
$(eval CURRENT_VERSION=$(shell awk '/__version__/ {print $$3}' $(INIT_FILE) | tr -d '"' | tr -d "'"))
5367
@echo "[INFO] Current version: $(CURRENT_VERSION)"
54-
@echo "[INFO] Get latest version from TestPypi."
55-
$(eval LATEST_VERSION=$(shell curl -sL "https://test.pypi.org/pypi/leverage/json" | jq -r ".releases | keys | sort | .[-1]"))
56-
@echo "[INFO] Latest version: $(LATEST_VERSION)"
57-
$(eval RELEASE_VERSION=$(shell echo $(LATEST_VERSION) | awk 'BEGIN{FS="."; OFS="."} {print $$1,$$2,$$3+1}')rc.1)
68+
69+
ifeq ($(strip $(RELEASE_VERSION)),)
70+
@echo "[INFO] RELEASE_VERSION not provided or empty. Fetching from TestPyPI."
71+
$(eval LATEST_VERSION=$(shell curl -sL "https://pypi.org/pypi/leverage/json" | jq -r ".releases | keys[]" | $(SORT) -V | tail -n 1 ))
72+
@echo "[INFO] Latest version fetched: $(LATEST_VERSION)"
73+
$(eval RELEASE_VERSION=$(shell echo $(LATEST_VERSION) | awk 'BEGIN{FS="."; OFS="."} {sub("rc[0-9]+", "", $$3); print $$1,$$2,$$3+1 "rc1"}'))
74+
@echo "[INFO] Auto-generated RELEASE_VERSION: $(RELEASE_VERSION)"
75+
endif
76+
5877
@echo "[INFO] Checking Release Version (template 9.9.9-rc9)..."
59-
@echo $(RELEASE_VERSION) | awk '/[0-9]+\.[0-9]+\.[0-9]+-(rc|alpha|beta)[0-9]+/ {print "[INFO] Version ok"}' || (echo "[ERROR] Version is wrong" && exit 1)
78+
@echo $(RELEASE_VERSION) | awk '/^[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$$/ {print "[INFO] Version ok"}' || (echo "[ERROR] Invalid format for RELEASE_VERSION. Expected format: ^[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$$" && exit 1)
79+
6080
@echo "[INFO] Bump version to $(RELEASE_VERSION)"
61-
@sed -i '' 's/__version__ = "$(CURRENT_VERSION)"/__version__ = "$(RELEASE_VERSION)"/' $(INIT_FILE)
62-
@sed -i '' 's/version = "$(CURRENT_VERSION)"/version = "$(RELEASE_VERSION)"/' $(PYPROJECT_FILE)
81+
@$(SED) -i 's/__version__ = "$(CURRENT_VERSION)"/__version__ = "$(RELEASE_VERSION)"/' $(INIT_FILE)
82+
@$(SED) -i 's/version = "$(CURRENT_VERSION)"/version = "$(RELEASE_VERSION)"/' $(PYPROJECT_FILE)
6383

6484
bump-version-ci: ## Fetch latest tag, update versions in __init__.py and pyproject.toml
6585
@echo "[INFO] Get latest tag"
6686
$(eval RELEASE_VERSION=$(shell git fetch --all --tags && git tag --sort=version:refname | tail -1 | sed 's/v//'))
6787
@echo $(RELEASE_VERSION)
6888

6989
@echo "[INFO] Write version to __init__.py"
70-
@sed -i '' 's/$(PLACEHOLDER)/$(RELEASE_VERSION)/' $(INIT_FILE)
90+
@$(SED) -i 's/$(PLACEHOLDER)/$(RELEASE_VERSION)/' $(INIT_FILE)
7191

7292
@echo "[INFO] Update version in pyproject.toml"
73-
@sed -i '' 's/version = ".*"/version = "$(RELEASE_VERSION)"/' $(PYPROJECT_FILE)
93+
@$(SED) -i 's/version = ".*"/version = "$(RELEASE_VERSION)"/' $(PYPROJECT_FILE)

0 commit comments

Comments
 (0)