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

Version Project #724

Merged
merged 15 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
!src
!package*.json
!tsconfig.json
!.env
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_VERSION=$npm_package_version
2 changes: 2 additions & 0 deletions Backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ RUN dotnet publish -c Release -o build
# Build runtime image.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

LABEL com.github.sillsdev.thecombine.version="0.1.0-alpha.0"

ENV ASPNETCORE_URLS=http://+:5000
ENV COMBINE_IS_IN_CONTAINER=1
ENV ASPNETCORE_ENVIRONMENT=Production
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ RUN npm run build
# Production environment.
FROM staticfloat/nginx-certbot

LABEL com.github.sillsdev.thecombine.version="0.1.0-alpha.0"

WORKDIR /app

ENV NGINX_HOST_DIR /usr/share/nginx/html
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ To generate a full report of the licenses used in production:
> npm run license-report
```

### Edit Project Version

To update the version string project-wide:

```bash
# On Windows use `py` instead of python3.
$ python3 set_version.py 1.0.1-alpha.0
```

## Docker

### Requirements
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thecombine",
"version": "0.1.0",
"version": "0.1.0-alpha.0",
"license": "MIT",
"private": true,
"scripts": {
Expand Down
70 changes: 70 additions & 0 deletions set_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3

import argparse
import os
from pathlib import Path
from typing import List

project_dir = Path(__file__).resolve().parent


def parse_args() -> argparse.Namespace:
"""Parse user command line arguments."""
parser = argparse.ArgumentParser(
description="Set the version for the project in the current repository.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"version",
type=str,
help="Version to set project-wide."
)
return parser.parse_args()


def update_file_line(file_path: Path, match_str: str, new_line: str) -> None:
"""Update lines in a file that contain a given string.

Args:
file_path: File to be modified in place.
match_str: String that must exist in the line of the file to be edited.
new_line: A line to replace matched lines with.
"""
print(f'Updating {file_path}...')
with open(file_path) as f:
lines = f.readlines()

new_lines: List[str] = []
for line in lines:
if match_str in line:
new_lines.append(f'{new_line}\n')
else:
new_lines.append(line)

with open(file_path, 'w') as f:
f.writelines(new_lines)


def main() -> None:
args = parse_args()
npm_version_tag = '"version":'
update_file_line(
project_dir / 'package.json',
npm_version_tag,
f' {npm_version_tag}"{args.version}",')

for docker_file in (project_dir / 'Dockerfile', project_dir / 'Backend' / 'Dockerfile'):
label = "LABEL com.github.sillsdev.thecombine.version"
update_file_line(
docker_file,
label,
f'{label}="{args.version}"',
)

npm_install_command = f"npm install {project_dir}"
print(f'To update package-lock.json, executing: {npm_install_command}')
os.system(npm_install_command)


if __name__ == '__main__':
main()
4 changes: 4 additions & 0 deletions src/components/AppBar/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface UserMenuListProps {
* UserMenu options: site settings (for admins), user settings, log out
*/
export function UserMenuList(props: UserMenuListProps) {
const { REACT_APP_VERSION } = process.env;
return (
<React.Fragment>
{/* Only show Site Settings link to Admin users. */}
Expand Down Expand Up @@ -115,6 +116,9 @@ export function UserMenuList(props: UserMenuListProps) {
<ExitToApp style={{ marginRight: theme.spacing(1) }} />
<Translate id="userMenu.logout" />
</MenuItem>
<MenuItem disabled style={{ justifyContent: "center" }}>
v{REACT_APP_VERSION}
</MenuItem>
</React.Fragment>
);
}