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

ENG-4443 Part 1. Create update scripts to update an app and the manifest #4

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Go stuff
go.work
go.work.sum
31 changes: 4 additions & 27 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Options for analysis running. Details: https://golangci-lint.run/usage/configuration/#run-configuration
run:
timeout: 5m
go: "1.19"
go: "1.21"

# Configures linters. Details: https://golangci-lint.run/usage/linters
linters-settings:
Expand All @@ -12,39 +12,16 @@ linters-settings:
gomodguard:
allowed:
modules:
- github.com/nextmv-io/sdk
- github.com/nextmv-io/sdk/route
- github.com/nextmv-io/sdk/route/osrm
- github.com/nextmv-io/sdk/route/here
- github.com/nextmv-io/sdk/route/google
- github.com/nextmv-io/sdk/route/routingkit
- github.com/nextmv-io/sdk/measure/here
- github.com/nextmv-io/sdk/measure/osrm
- github.com/nextmv-io/sdk/measure/google
- github.com/nextmv-io/sdk/measure/routingkit
- googlemaps.github.io/maps
- github.com/dgraph-io/ristretto
- go.uber.org/mock
- github.com/google/go-cmp
- github.com/hashicorp/golang-lru
- github.com/nextmv-io/go-routingkit
- github.com/twpayne/go-polyline
- googlemaps.github.io/maps
- github.com/itzg/go-flagsfiller
- github.com/gorilla/schema
- github.com/google/uuid
- github.com/xeipuuv/gojsonschema
- github.com/danielgtaylor/huma
# Allow increased cyclomatic complexity for examples.
gocyclo:
min-complexity: 45
# Set correct go version.
gosimple:
go: "1.19"
go: "1.21"
staticcheck:
go: "1.19"
go: "1.21"
stylecheck:
go: "1.19"
go: "1.21"
# Check case of struct tags
tagliatelle:
case:
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.0
1 change: 1 addition & 0 deletions knapsack-gosdk/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions knapsack-java-ortools/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions knapsack-ortools/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions knapsack-pyomo/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions nextroute/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions order-fulfillment-gosdk/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyyaml==6.0.1
ruff==0.1.7
1 change: 1 addition & 0 deletions routing-ortools/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
55 changes: 55 additions & 0 deletions scripts/update_app.sh
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
104 changes: 104 additions & 0 deletions scripts/update_manifest.py
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()
1 change: 1 addition & 0 deletions shift-assignment-ortools/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions shift-assignment-pyomo/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions shift-planning-ortools/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions shift-planning-pyomo/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
1 change: 1 addition & 0 deletions shift-scheduling-gosdk/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
31 changes: 31 additions & 0 deletions workflow-configuration.yml
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
1 change: 1 addition & 0 deletions xpress/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.2.0
Loading