-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENG-4443 Part 1. Create update scripts to update an app and the manifest
- Loading branch information
1 parent
40d6758
commit bc4407d
Showing
20 changed files
with
215 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pyyaml==6.0.1 | ||
ruff==0.1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# ================= README ================= | ||
# Updates an app to the desired version. | ||
|
||
# Required exports. | ||
# APP: the name of the app to update. | ||
# VERSION: the version to update to. | ||
|
||
# ================= Checks ================= | ||
# Checks that APP is set. | ||
echo "🐰 Checking the value of APP" | ||
if [[ -z "${APP}" ]]; then | ||
echo "❌ APP must be set" | ||
exit -1 | ||
fi | ||
|
||
# Checks that VERSION is set. | ||
echo "🐰 Checking the value of VERSION" | ||
if [[ -z "${VERSION}" ]]; then | ||
echo "❌ VERSION must be set" | ||
exit -1 | ||
fi | ||
|
||
# ================= App info ================= | ||
# Get the info of the app from the configuration file. | ||
WORFKLOW_CONFIGURATION="workflow-configuration.yml" | ||
INFO=$(yq '.apps[] | select(.name == strenv(APP))' workflow-configuration.yml) | ||
echo "🐰 App info:" | ||
echo "$INFO" | yq . | ||
|
||
# ================= Directory ================= | ||
# Change to the APP directory. | ||
cd "$(dirname "$0")/.." | ||
echo "🐰 Current dir is: $(pwd)" | ||
echo "🐰 Changing to dir $APP" | ||
cd $APP | ||
|
||
# ================= Update ================= | ||
# Update the VERSION file to the VERSION. | ||
OLD=$(cat VERSION) | ||
echo "🐰 Updating the VERSION file from $OLD to $VERSION" | ||
echo $VERSION > VERSION | ||
|
||
# If the app is a Go app, update the go.mod file. | ||
TYPE=$(echo "$INFO" | yq .type) | ||
echo "🐰 App type is $TYPE" | ||
if [[ $TYPE == "go" ]]; then | ||
SDK_VERSION=$(echo "$INFO" | yq .sdk_version) | ||
echo "🐰 SDK version is $SDK_VERSION" | ||
echo "🐰 Updating the go.mod file" | ||
go get github.com/nextmv-io/sdk@$SDK_VERSION | ||
go mod tidy | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
""" | ||
This script updates the manifest file with the latest version of the release | ||
and the apps. It assumes that there is a `manifest.yml` file which corresponds | ||
to the old manifest. It writes the new manifest to `new_manifest.yml`. Versions | ||
are taken from the `VERSION` file in each app directory, and the root. | ||
Execute from the root: | ||
```bash | ||
python scripts/update_manifest.py | ||
``` | ||
""" | ||
import copy | ||
import os | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
|
||
def main(): | ||
""" | ||
Entry point for the script. | ||
""" | ||
|
||
apps = [ | ||
{ | ||
"name": app["name"], | ||
"type": app["type"], | ||
"version": version(dir=app["name"]), | ||
} | ||
for app in open_yaml_file(filepath="workflow-configuration.yml")["apps"] | ||
] | ||
apps.sort(key=lambda x: x["name"]) | ||
old = open_yaml_file(filepath="manifest.yml") | ||
new = update_manifest(old=old, apps=apps) | ||
with open("new_manifest.yml", "w") as f: | ||
yaml.dump(new, f) | ||
|
||
|
||
def update_manifest( | ||
old: dict[str, Any], | ||
apps: list[dict[str, str]], | ||
) -> dict[str, Any]: | ||
""" | ||
Updates the manifest with the new apps. | ||
Args: | ||
old: The old manifest. | ||
apps: The list of apps. | ||
Returns: | ||
The new manifest. | ||
""" | ||
|
||
new = copy.deepcopy(old) | ||
new_version = version(dir=".") | ||
new["latest"] = new_version | ||
release = { | ||
"version": new_version, | ||
"apps": apps, | ||
} | ||
new["releases"].append(release) | ||
|
||
return new | ||
|
||
|
||
def open_yaml_file(filepath: str) -> dict[str, Any]: | ||
""" | ||
Returns the YAML file in the path. | ||
Args: | ||
filepath: The path of the file. | ||
Returns: | ||
The content of the YAML file. | ||
Raises: | ||
FileNotFoundError: If the file is not found. | ||
""" | ||
|
||
with open(filepath) as f: | ||
return yaml.safe_load(f) | ||
|
||
|
||
def version(dir: str) -> str: | ||
""" | ||
Returns the version in the given directory. | ||
Args: | ||
dir: The directory. | ||
Returns: | ||
The version. | ||
Raises: | ||
FileNotFoundError: If the VERSION file is not found. | ||
""" | ||
|
||
with open(os.path.join(dir, "VERSION")) as f: | ||
return f.read().strip() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apps: | ||
- name: knapsack-gosdk | ||
type: go | ||
sdk_version: latest | ||
- name: knapsack-java-ortools | ||
type: java | ||
- name: knapsack-ortools | ||
type: python | ||
- name: knapsack-pyomo | ||
type: python | ||
- name: nextroute | ||
type: go | ||
sdk_version: latest | ||
- name: order-fulfillment-gosdk | ||
type: go | ||
sdk_version: latest | ||
- name: routing-ortools | ||
type: python | ||
- name: shift-assignment-ortools | ||
type: python | ||
- name: shift-assignment-pyomo | ||
type: python | ||
- name: shift-planning-ortools | ||
type: python | ||
- name: shift-planning-pyomo | ||
type: python | ||
- name: shift-scheduling-gosdk | ||
type: go | ||
sdk_version: latest | ||
- name: xpress | ||
type: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.2.0 |