Skip to content

Commit

Permalink
Add scripts for managing releases
Browse files Browse the repository at this point in the history
  • Loading branch information
raffomania committed Jan 31, 2024
1 parent c14e767 commit b311f02
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-openapi-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
working-directory: frontend
run: |
node updateAPI.js -p 5500
npm run generate-dev
npm run generate-api
- name: Check that frontend builds without error
working-directory: frontend
run: npm run build
Expand Down
5 changes: 5 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ wipe_all_data:
ENV_NAME=dwts source _activate_current_env.sh
cd src
python wipe_database.py

.PHONY: release
update_version:
ENV_NAME=dwts source _activate_current_env.sh
python release.py --version $(VERSION)
20 changes: 20 additions & 0 deletions backend/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import argparse

from omegaconf import OmegaConf

version_conf = OmegaConf.load("./src/configs/version.yaml")

parser = argparse.ArgumentParser(description="DATS release script")
parser.add_argument(
"--version",
type=str,
help="New version to release",
required=True,
dest="version",
)
args = parser.parse_args()

print(args.version)
version_conf.api.version = args.version

OmegaConf.save(version_conf, "./src/configs/version.yaml")
2 changes: 2 additions & 0 deletions backend/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"DWISE_BACKEND_CONFIG", "./configs/default_localhost_dev.yaml"
)
conf = OmegaConf.load(__conf_file__)
version_conf = OmegaConf.load("./configs/version.yaml")
conf = OmegaConf.merge(conf, version_conf)

# setup loguru logging
logger.remove()
Expand Down
2 changes: 2 additions & 0 deletions backend/src/configs/version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api:
version: v0.0.5
10 changes: 2 additions & 8 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ async def lifespan(app: FastAPI):

# create the FastAPI app
app = FastAPI(
# title="D-WISE Tool Suite Backend API",
# description="The REST API for the D-WISE Tool Suite Backend",
# version="alpha_mwp_1",
generate_unique_id_function=custom_generate_unique_id,
lifespan=lifespan,
)
Expand All @@ -111,12 +108,9 @@ async def lifespan(app: FastAPI):
# customize openapi schema
# we need to add some DTOs manually, because they are not used in any endpoint, but needed in the frontend nonetheless
def custom_openapi():
# if app.openapi_schema:
# return app.openapi_schema
openapi_schema = get_openapi(
title="D-WISE Tool Suite Backend API",
version="beta_mwp_1",
description="The REST API for the D-WISE Tool Suite Backend.",
title="Discourse Analysis Tool Suite API",
version=conf.api.version,
routes=app.routes,
)
openapi_schema["components"]["schemas"][
Expand Down
27 changes: 27 additions & 0 deletions bin/relase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -euxo pipefail

if [ "${1:-}" = "" ]; then
echo "Please provide a version parameter, e.g. release.sh v.0.0.3"
exit 1
fi

if [ "$(git diff-index --cached HEAD --)" ]; then
echo "There are staged changes. Please run this script in a clean working directory."
exit 1
fi

cd backend
make update_version VERSION="$1"

read -p "Please restart the backend to make sure its OpenAPI spec is up to date. Afterwards, press any key to continue. " -n 1 -r

cd ../frontend
npm run update-version

cd ..
git tag v"$1"
git add backend/src/configs/version.yaml frontend/package.json frontend/src/openapi.json
# git commit "Release v$1"
# git push --tags
4 changes: 2 additions & 2 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This is the repository for the D-WISE Tool Suite (DWTS) Frontend - an outcome of
the [D-WISE Project](https://www.dwise.uni-hamburg.de/)

## Run the frontend _(for development)_
1) Install the dependencies: `npm install`
1) Install the dependencies: `npm install -f`
2) Download openapi.json from backend: `npm run update-api`
- This requires the backend to be running and the OpenAPI Specification to be available at [http://localhost:5500/openapi.json](http://localhost:5500/openapi.json)
3) Generate the API Service: `npm run generate-dev`
3) Generate the API Service: `npm run generate-api`
4) Run the development server: `npm run start`
5) Open the browser and visit [http://localhost:3000/](http://localhost:3000/)
File renamed without changes.
19 changes: 7 additions & 12 deletions frontend/updateAPI.js → frontend/bin/updateAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ const fs = require("fs");
const http = require("http");
const exec = require("child_process").exec;

// settings
let port = 18120;
const argv = require("minimist")(process.argv.slice(2));
if (Object.keys(argv).includes("p")) {
port = argv["p"];
} else if (Object.keys(argv).includes("port")) {
port = argv["port"];
} else {
console.error("Please specify port of the DWTS Backend API using -p <PORT> or --port <PORT>");
process.exit();
}
require("dotenv").config({ path: ".env.development" });

// 1. remove existing openapi file
const openapiFilePath = "src/openapi.json";
Expand All @@ -22,8 +12,13 @@ if (fs.existsSync(openapiFilePath)) {
}

// 2. download new openapi json file
const backendUrl = process.env.REACT_APP_SERVER;
if (backendUrl === "" || backendUrl === undefined) {
console.error("REACT_APP_SERVER .env variable is not set, don't know how to reach the backend!");
process.exit(1);
}
http
.get(`http://0.0.0.0:${port}/openapi.json`, (res) => {
.get(`${backendUrl}/openapi.json`, (res) => {
const { statusCode } = res;
const contentType = res.headers["content-type"];

Expand Down
11 changes: 11 additions & 0 deletions frontend/bin/updateVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");
const { execSync } = require("child_process");

const contents = JSON.parse(fs.readFileSync("src/openapi.json"));
const version = contents.info.version;

const packageJson = JSON.parse(fs.readFileSync("package.json"));
packageJson.version = version;
fs.writeFileSync("package.json", JSON.stringify(packageJson));

execSync(`npx prettier --write package.json`);
52 changes: 0 additions & 52 deletions frontend/ltdwise_tunnels.sh

This file was deleted.

34 changes: 30 additions & 4 deletions frontend/package-lock.json

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

9 changes: 5 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "0.1.0",
"version": "0.0.3",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
Expand Down Expand Up @@ -50,9 +50,9 @@
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"update-api": "node updateAPI.js -p 19220",
"generate": "openapi --input src/openapi.json --useOptions --output src/api/openapi",
"generate-dev": "node generateAPI.js"
"update-api": "node bin/updateAPI.js",
"generate-api": "node bin/generateAPI.js",
"update-version": "npm run update-api && node bin/updateVersion.js"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -74,6 +74,7 @@
"@types/lodash": "^4.14.182",
"@types/react": "^18.0.12",
"@types/react-dom": "^18.0.5",
"dotenv": "^16.4.1",
"eslint": "8.54.0",
"eslint-config-react-app": "7.0.1",
"minimist": "^1.2.7",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/openapi/core/OpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type OpenAPIConfig = {

export const OpenAPI: OpenAPIConfig = {
BASE: "",
VERSION: "beta_mwp_1",
VERSION: "0.0.3",
WITH_CREDENTIALS: false,
CREDENTIALS: "include",
TOKEN: undefined,
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/openapi.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"openapi": "3.1.0",
"info": {
"title": "D-WISE Tool Suite Backend API",
"description": "The REST API for the D-WISE Tool Suite Backend.",
"version": "beta_mwp_1"
},
"info": { "title": "Discourse Analysis Tool Suite API", "version": "0.0.3" },
"paths": {
"/heartbeat": {
"get": {
Expand Down

0 comments on commit b311f02

Please sign in to comment.