From fd62837eabc7466f64c99bd0fb0ec695ea1e39e6 Mon Sep 17 00:00:00 2001 From: William Ferns Date: Thu, 4 Sep 2025 18:03:12 +0200 Subject: [PATCH 1/9] refactor(EnvironmentExtensions.swift): moved extensions to utilities package (#196) `getOrThrow` method is used and will be used in other packages in our organization. --- .dotfiles | 2 +- Backend/Package.resolved | 6 +++--- Backend/Package.swift | 2 ++ .../OpenAIChatCompletionClient.swift | 1 + .../FirecrawlClient/FirecrawlClient.swift | 1 + .../Clients/TwitterClient/TwitterClient.swift | 1 + .../PrometheusController.swift | 1 + .../Vapor/EnvironmentExtensions.swift | 18 ------------------ .../Middleware/TestControllerMiddleware.swift | 1 + .../AuthenticationServiceHelper.swift | 7 ++++--- .../MessageService/MessageService.swift | 1 + .../ProfilePictureService.swift | 1 + .../Services/TigrisService/TigrisService.swift | 1 + Backend/Sources/App/configure.swift | 9 +++++---- ...erAuthenticatedClientIntegrationTests.swift | 3 ++- .../PrometheusControllerIntegrationTests.swift | 1 + 16 files changed, 26 insertions(+), 30 deletions(-) delete mode 100644 Backend/Sources/App/Extensions/Vapor/EnvironmentExtensions.swift diff --git a/.dotfiles b/.dotfiles index dfafa80f..ec9bc762 160000 --- a/.dotfiles +++ b/.dotfiles @@ -1 +1 @@ -Subproject commit dfafa80fb3289d55c5589c25bb6e29c0f01e49e6 +Subproject commit ec9bc762fe9f4a14eee111d5ae65f02dab540b0b diff --git a/Backend/Package.resolved b/Backend/Package.resolved index 0f19797f..50cfb276 100644 --- a/Backend/Package.resolved +++ b/Backend/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "6358cd7e5e3410ca6c9d19012b8158d9f3dc14e07492356093c18fab54de132e", + "originHash" : "fd696153ea81efb825467272117f6b70b5b5fa52dfde9a8035d412d86626d6d3", "pins" : [ { "identity" : "alamofire", @@ -447,8 +447,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/vapor.git", "state" : { - "revision" : "87b0edd2633c35de543cb7573efe5fbf456181bc", - "version" : "4.114.1" + "revision" : "3636f443474769147828a5863e81a31f6f30e92c", + "version" : "4.115.1" } }, { diff --git a/Backend/Package.swift b/Backend/Package.swift index 16efb00d..513ce437 100644 --- a/Backend/Package.swift +++ b/Backend/Package.swift @@ -31,6 +31,7 @@ public let package = Package( .package(url: "https://github.com/nmdias/FeedKit.git", from: "10.0.0-rc.3"), .package(url: "https://github.com/GetAutomaApp/swift-retry.git", branch: "main"), .package(url: "https://github.com/GetAutomaApp/Fakery", branch: "master"), + .package(name: "automa-utilities", path: "../../AutomaUtilities"), ], targets: [ .executableTarget( @@ -53,6 +54,7 @@ public let package = Package( .product(name: "SotoTextract", package: "soto"), .product(name: "FeedKit", package: "FeedKit"), .product(name: "DMRetry", package: "swift-retry"), + .product(name: "automa-utilities", package: "AutomaUtilities"), ], exclude: [ "Documentation.md", diff --git a/Backend/Sources/App/Clients/ChatCompletionClient/OpenAIChatCompletionClient/OpenAIChatCompletionClient.swift b/Backend/Sources/App/Clients/ChatCompletionClient/OpenAIChatCompletionClient/OpenAIChatCompletionClient.swift index 30a18d34..c26aae9a 100644 --- a/Backend/Sources/App/Clients/ChatCompletionClient/OpenAIChatCompletionClient/OpenAIChatCompletionClient.swift +++ b/Backend/Sources/App/Clients/ChatCompletionClient/OpenAIChatCompletionClient/OpenAIChatCompletionClient.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import OpenAI import Retry import Vapor diff --git a/Backend/Sources/App/Clients/FirecrawlClient/FirecrawlClient.swift b/Backend/Sources/App/Clients/FirecrawlClient/FirecrawlClient.swift index 902dc9be..b1c42460 100644 --- a/Backend/Sources/App/Clients/FirecrawlClient/FirecrawlClient.swift +++ b/Backend/Sources/App/Clients/FirecrawlClient/FirecrawlClient.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import DataTypes import Vapor diff --git a/Backend/Sources/App/Clients/TwitterClient/TwitterClient.swift b/Backend/Sources/App/Clients/TwitterClient/TwitterClient.swift index 8a074e57..c62dfa31 100644 --- a/Backend/Sources/App/Clients/TwitterClient/TwitterClient.swift +++ b/Backend/Sources/App/Clients/TwitterClient/TwitterClient.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import DataTypes import Fluent import Foundation diff --git a/Backend/Sources/App/Controllers/PrometheusController/PrometheusController.swift b/Backend/Sources/App/Controllers/PrometheusController/PrometheusController.swift index 46ce535e..44a0ce1f 100644 --- a/Backend/Sources/App/Controllers/PrometheusController/PrometheusController.swift +++ b/Backend/Sources/App/Controllers/PrometheusController/PrometheusController.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import Fluent import Prometheus import Vapor diff --git a/Backend/Sources/App/Extensions/Vapor/EnvironmentExtensions.swift b/Backend/Sources/App/Extensions/Vapor/EnvironmentExtensions.swift deleted file mode 100644 index 5174bd2d..00000000 --- a/Backend/Sources/App/Extensions/Vapor/EnvironmentExtensions.swift +++ /dev/null @@ -1,18 +0,0 @@ -// EnvironmentExtensions.swift -// Copyright (c) 2025 GetAutomaApp -// All source code and related assets are the property of GetAutomaApp. -// All rights reserved. - -import Vapor - -/// Extension to throw error if we can't find an env value -internal extension Environment { - /// Extension to throw error if we can't find an env value - static func getOrThrow(_ key: String) throws -> String { - guard let value = Environment.get(key) else { - throw Abort(.notFound, reason: "Value for key \(key) not found") - } - - return value - } -} diff --git a/Backend/Sources/App/Middleware/TestControllerMiddleware.swift b/Backend/Sources/App/Middleware/TestControllerMiddleware.swift index c6464122..b99fb3c6 100644 --- a/Backend/Sources/App/Middleware/TestControllerMiddleware.swift +++ b/Backend/Sources/App/Middleware/TestControllerMiddleware.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import DataTypes import Vapor diff --git a/Backend/Sources/App/Services/AuthenticationService/AuthenticationServiceHelper.swift b/Backend/Sources/App/Services/AuthenticationService/AuthenticationServiceHelper.swift index 36eb6305..571a9338 100644 --- a/Backend/Sources/App/Services/AuthenticationService/AuthenticationServiceHelper.swift +++ b/Backend/Sources/App/Services/AuthenticationService/AuthenticationServiceHelper.swift @@ -3,6 +3,7 @@ /// All source code and related assets are the property of GetAutomaApp. /// All rights reserved. +import AutomaUtilities import DataTypes import Fluent import JWT @@ -128,9 +129,9 @@ internal actor AuthenticationServiceHelper { internal struct AuthenticationServiceHelperConfig: AuthenticationServiceConfig { /// Db Connection w/ Write access public let writeDb: Database - /// Db Connection w/ Read-Only access + /// Db Connection w/ Read-Only access public let readDb: Database - /// Logger + /// Logger public let logger: Logger } @@ -406,7 +407,7 @@ internal struct DeleteOldAccessTokensPayload { /// ASC on date how many tokens to skip public let totalNewestTokensToSkip: Int? - /// init + /// init public init( userId: UUID, subject: JWTTokenSubject, diff --git a/Backend/Sources/App/Services/MessageService/MessageService.swift b/Backend/Sources/App/Services/MessageService/MessageService.swift index 66c39b77..dc271ad0 100644 --- a/Backend/Sources/App/Services/MessageService/MessageService.swift +++ b/Backend/Sources/App/Services/MessageService/MessageService.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import DataTypes import Fluent import Foundation diff --git a/Backend/Sources/App/Services/ProfilePictureService/ProfilePictureService.swift b/Backend/Sources/App/Services/ProfilePictureService/ProfilePictureService.swift index 14d5c072..b3dd726a 100644 --- a/Backend/Sources/App/Services/ProfilePictureService/ProfilePictureService.swift +++ b/Backend/Sources/App/Services/ProfilePictureService/ProfilePictureService.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import DataTypes import Fluent import OpenAI diff --git a/Backend/Sources/App/Services/TigrisService/TigrisService.swift b/Backend/Sources/App/Services/TigrisService/TigrisService.swift index c3fc0ea9..4298037b 100644 --- a/Backend/Sources/App/Services/TigrisService/TigrisService.swift +++ b/Backend/Sources/App/Services/TigrisService/TigrisService.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import DataTypes import Fluent import SotoS3 diff --git a/Backend/Sources/App/configure.swift b/Backend/Sources/App/configure.swift index 49e1f8b0..4fb9ab64 100644 --- a/Backend/Sources/App/configure.swift +++ b/Backend/Sources/App/configure.swift @@ -3,6 +3,7 @@ // All source code and related assets are the property of GetAutomaApp. // All rights reserved. +import AutomaUtilities import Fluent import FluentPostgresDriver import JWT @@ -202,8 +203,8 @@ public struct DatabaseSeeder { } internal enum DatabaseURLs { - /// primary database url has read & write access - public static let primary: Result = Result { try Environment.getOrThrow("PRIMARY_POSTGRES_URL") } - /// regional url most likely doesn't have write access, but allows for extremely fast reads - public static let regional: Result = Result { try Environment.getOrThrow("REGIONAL_POSTGRES_URL") } + /// primary database url has read & write access + public static let primary: Result = Result { try Environment.getOrThrow("PRIMARY_POSTGRES_URL") } + /// regional url most likely doesn't have write access, but allows for extremely fast reads + public static let regional: Result = Result { try Environment.getOrThrow("REGIONAL_POSTGRES_URL") } } diff --git a/Backend/Tests/AppTests/Clients/TwitterClientTests/TwitterAuthenticatedClientIntegrationTests.swift b/Backend/Tests/AppTests/Clients/TwitterClientTests/TwitterAuthenticatedClientIntegrationTests.swift index 9b17babc..5a56df27 100644 --- a/Backend/Tests/AppTests/Clients/TwitterClientTests/TwitterAuthenticatedClientIntegrationTests.swift +++ b/Backend/Tests/AppTests/Clients/TwitterClientTests/TwitterAuthenticatedClientIntegrationTests.swift @@ -4,6 +4,7 @@ // All rights reserved. @testable import App +import AutomaUtilities import Fakery import Fluent import Testing @@ -13,7 +14,7 @@ import VaporTesting /// These tests verify that operations requiring user authentication work correctly extension SerialDbTestSuites { @Suite("TwitterAuthenticatedClientIntegrationTests") - internal struct TwitterAuthenticatedClientIntegrationTests: TwitterClientTestSuite { + struct TwitterAuthenticatedClientIntegrationTests: TwitterClientTestSuite { /// Tests the ability to post a tweet using an authenticated Twitter client /// This test verifies that: /// - A valid Twitter user token can be retrieved from the database diff --git a/Backend/Tests/AppTests/Controllers/PrometheusControllerTests/PrometheusControllerIntegrationTests.swift b/Backend/Tests/AppTests/Controllers/PrometheusControllerTests/PrometheusControllerIntegrationTests.swift index 4d12327c..86504856 100644 --- a/Backend/Tests/AppTests/Controllers/PrometheusControllerTests/PrometheusControllerIntegrationTests.swift +++ b/Backend/Tests/AppTests/Controllers/PrometheusControllerTests/PrometheusControllerIntegrationTests.swift @@ -4,6 +4,7 @@ // All rights reserved. @testable import App +import AutomaUtilities import Testing import VaporTesting From 1a2fdaeb229249debcce0eabb9235d51f92cfd9d Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Tue, 9 Sep 2025 14:38:56 +0200 Subject: [PATCH 2/9] chore: update submodules --- automa.config.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 automa.config.json diff --git a/automa.config.json b/automa.config.json new file mode 100644 index 00000000..a06b572f --- /dev/null +++ b/automa.config.json @@ -0,0 +1,16 @@ +{ + "fly" : { + "environments" : [ + "production", + "sandbox", + "staging" + ], + "config_files_root" : "Backend/infra/fly" + }, + "actionsSecrets" : { + "owner_repo" : "GetAutomaApp/AutomaInfraCore" + }, + "grafana" : { + "current_environment" : "automa-grafana" + } +} From 79646c8e2c79f374239a5be1d4fa49ac8b1d1251 Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 18:27:38 +0200 Subject: [PATCH 3/9] feat: try deploy with automacli external --- .github/workflows/deploy-sandbox.yml | 11 ++++------- package.json | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yml b/.github/workflows/deploy-sandbox.yml index ec110836..abf8b96d 100644 --- a/.github/workflows/deploy-sandbox.yml +++ b/.github/workflows/deploy-sandbox.yml @@ -4,6 +4,7 @@ on: push: branches: - develop + - simon/automa-cli-build-integration jobs: deploy: @@ -25,19 +26,15 @@ jobs: key: deploy-cache-${{ hashFiles('Backend/Package.resolved') }} path: Backend/.build - - name: Get CLI Cache - uses: useblacksmith/cache@v5 - id: cli-build + - name: Get AutomaCLI + uses: GetAutomaApp/private-actions/get-automacli@main with: - key: deploy-cache-${{ hashFiles('CLI/Package.resolved') }} - path: CLI/.build + github_pat: ${{ secrets.GITHUB_PAT }} - uses: superfly/flyctl-actions/setup-flyctl@master - run: | npm run deploy:backend:sandbox npm run deploy:worker:sandbox - ls -a Backend - ls -a CLI env: FLY_API_TOKEN: ${{ secrets.FLY_SANDBOX_API_KEY }} FLY_METRICS_TOKEN: ${{ secrets.FLY_METRICS_TOKEN }} diff --git a/package.json b/package.json index 98c51e86..32389140 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "cli:docker": "docker exec -ti backend-app_dev-1 ./.build/aarch64-unknown-linux-gnu/debug/App --env local", "prepare:action": "npm install", "generate": "npm run cli -- generate", - "cli": "cd CLI && swift run AutomaCLI", + "cli": "automa", "fly:config": "npm run cli -- fly-config", "format": "swiftformat .", "deploy:backend:sandbox": "npm run fly:config -- ../Backend/infra/fly/fly.toml sandbox | npm run deploy:to:fly", From adc6499ca018b1b52da8866f178aa3aaddeeefc6 Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 18:29:22 +0200 Subject: [PATCH 4/9] fix: fix repo --- .github/workflows/deploy-sandbox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yml b/.github/workflows/deploy-sandbox.yml index abf8b96d..d43ec2ff 100644 --- a/.github/workflows/deploy-sandbox.yml +++ b/.github/workflows/deploy-sandbox.yml @@ -27,7 +27,7 @@ jobs: path: Backend/.build - name: Get AutomaCLI - uses: GetAutomaApp/private-actions/get-automacli@main + uses: GetAutomaApp/private-actions/get-automacli@main with: github_pat: ${{ secrets.GITHUB_PAT }} From 996fa35f52c090841ead6bd31a489dc1804ed29a Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 18:31:18 +0200 Subject: [PATCH 5/9] fix: invalid permissions --- .github/workflows/deploy-sandbox.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/deploy-sandbox.yml b/.github/workflows/deploy-sandbox.yml index d43ec2ff..8cf8d565 100644 --- a/.github/workflows/deploy-sandbox.yml +++ b/.github/workflows/deploy-sandbox.yml @@ -12,6 +12,13 @@ jobs: runs-on: blacksmith-4vcpu-ubuntu-2404 concurrency: deploy-group-sandbox steps: + - name: Checkout private-actions + uses: actions/checkout@v4 + with: + repository: GetAutomaApp/private-actions + ref: main + token: ${{ secrets.GITHUB_PAT }} + - name: Checkout Code uses: actions/checkout@v4 From 36c8a4ef6b7eb3e23114d686d323862f9c45fe72 Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 18:33:30 +0200 Subject: [PATCH 6/9] fix: turn on proper access --- .github/workflows/deploy-sandbox.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/deploy-sandbox.yml b/.github/workflows/deploy-sandbox.yml index 8cf8d565..d43ec2ff 100644 --- a/.github/workflows/deploy-sandbox.yml +++ b/.github/workflows/deploy-sandbox.yml @@ -12,13 +12,6 @@ jobs: runs-on: blacksmith-4vcpu-ubuntu-2404 concurrency: deploy-group-sandbox steps: - - name: Checkout private-actions - uses: actions/checkout@v4 - with: - repository: GetAutomaApp/private-actions - ref: main - token: ${{ secrets.GITHUB_PAT }} - - name: Checkout Code uses: actions/checkout@v4 From 96c284511cd2094894750bdc7a85ea02e5e9a283 Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 18:43:06 +0200 Subject: [PATCH 7/9] fix: use pat for getting automacli --- .github/workflows/deploy-sandbox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sandbox.yml b/.github/workflows/deploy-sandbox.yml index d43ec2ff..5343b380 100644 --- a/.github/workflows/deploy-sandbox.yml +++ b/.github/workflows/deploy-sandbox.yml @@ -29,7 +29,7 @@ jobs: - name: Get AutomaCLI uses: GetAutomaApp/private-actions/get-automacli@main with: - github_pat: ${{ secrets.GITHUB_PAT }} + github_pat: ${{ secrets.GET_AUTOMACLI_GH_PAT }} - uses: superfly/flyctl-actions/setup-flyctl@master - run: | From aaf28b00ac4928d82f799de77884d2ff74d283c9 Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 19:29:22 +0200 Subject: [PATCH 8/9] fix --- .env.cli | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .env.cli diff --git a/.env.cli b/.env.cli deleted file mode 100644 index f7e878c2..00000000 --- a/.env.cli +++ /dev/null @@ -1 +0,0 @@ -FLY_METRICS_TOKEN=FF5BB834-6D7E-4F10-9F9A-CD0B240BBF86 \ No newline at end of file From 56b30367d5c1dabed255f47210b557597ae1925a Mon Sep 17 00:00:00 2001 From: AdonisCodes Date: Sun, 14 Sep 2025 19:35:42 +0200 Subject: [PATCH 9/9] feat: ignore envs in root dir --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index fa237e46..6bc898b4 100644 --- a/.gitignore +++ b/.gitignore @@ -202,3 +202,5 @@ wireguard-prod.conf .swiftlint.yml .swiftformat + +*.env.*