Skip to content

Commit

Permalink
Fix rewrite_version script
Browse files Browse the repository at this point in the history
  • Loading branch information
suecharo committed Jun 8, 2023
1 parent 3be7e43 commit 211aa94
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FROM python:3.8.15-slim-buster
LABEL org.opencontainers.image.authors="National Institute of Informatics, Japan"
LABEL org.opencontainers.image.url="https://github.com/NII-DG/nii-dg"
LABEL org.opencontainers.image.source="https://raw.githubusercontent.com/NII-DG/nii-dg/main/Dockerfile"
LABEL org.opencontainers.image.version="[0-9]*.[0-9]*.[0-9]*"1.0.0"
LABEL org.opencontainers.image.version="1.0.0"
LABEL org.opencontainers.image.licenses="Apache2.0"

RUN apt update && \
Expand Down
2 changes: 1 addition & 1 deletion compose.api.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.5"
services:
app:
image: ghcr.io/nii-dg/nii-dg:[0-9]*.[0-9]*.[0-9]*1.0.0"
image: ghcr.io/nii-dg/nii-dg:0.1.2
container_name: nii-dg
volumes:
- ${PWD}:/app
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.5"
services:
app:
image: ghcr.io/nii-dg/nii-dg:[0-9]*.[0-9]*.[0-9]*1.0.0"
image: ghcr.io/nii-dg/nii-dg:0.1.2
container_name: nii-dg
volumes:
- ${PWD}:/app
Expand Down
2 changes: 1 addition & 1 deletion nii_dg/module_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
GH_REPO: str = "NII-DG/nii-dg"
"""str: The GitHub repository name for the nii_dg package."""

GH_REF: str = "[0-9]*.[0-9]*.[0-9]*"1.0.0"
GH_REF: str = "1.0.0"
"""str: The GitHub reference (tag or branch) for the nii_dg package."""


Expand Down
35 changes: 21 additions & 14 deletions rewrite_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ if [[ $# -lt 1 ]]; then
exit 1
fi

PREV_VERSION=$(python3 ./nii_dg/module_info.py)
NEW_VERSION=$1

# Define the locations and current version patterns to replace
declare -A LOCATIONS=(
["./nii_dg/module_info.py"]="GH_REF: str = \"[0-9]*\.[0-9]*\.[0-9]*\""
["./Dockerfile"]="LABEL org.opencontainers.image.version=\"[0-9]*\.[0-9]*\.[0-9]*\""
["./compose.yml"]="image: ghcr.io\/nii-dg\/nii-dg:[0-9]*\.[0-9]*\.[0-9]*"
["./compose.api.yml"]="image: ghcr.io\/nii-dg\/nii-dg:[0-9]*\.[0-9]*\.[0-9]*"
)

# Iterate over the locations and update the version
for FILE in "${!LOCATIONS[@]}"; do
PATTERN=${LOCATIONS[$FILE]}
echo "Updating version in $FILE ..."
sed -i -r "s/${PATTERN}/${PATTERN%%[0-9]*\.[0-9]*\.[0-9]*\"}${NEW_VERSION}\"/g" $FILE
done
read -p "Rewrite version from ${PREV_VERSION} to ${NEW_VERSION}? (y/n) :" YN

if [[ "${YN}" != "y" ]]; then
echo "Abort."
exit 1
fi

echo "Rewriting version from ${PREV_VERSION} to ${NEW_VERSION} ..."

echo "Rewriting nii_dg/module_info.py ..."
sed -i "s/GH_REF: str = \"${PREV_VERSION}\"/GH_REF: str = \"${NEW_VERSION}\"/g" ./nii_dg/module_info.py

echo "Rewriting Dockerfile ..."
sed -i "s/LABEL org.opencontainers.image.version=\"${PREV_VERSION}\"/LABEL org.opencontainers.image.version=\"${NEW_VERSION}\"/g" ./Dockerfile

echo "Rewriting compose.yml ..."
sed -i "s/image: ghcr.io\/NII-DG\/nii-dg:${PREV_VERSION}/image: ghcr.io\/NII-DG\/nii-dg:${NEW_VERSION}/g" ./compose.yml

echo "Rewriting compose.api.yml ..."
sed -i "s/image: ghcr.io\/NII-DG\/nii-dg:${PREV_VERSION}/image: ghcr.io\/NII-DG\/nii-dg:${NEW_VERSION}/g" ./compose.api.yml

echo "Version update complete."

0 comments on commit 211aa94

Please sign in to comment.