From b5ad42147cb29b54ee9930d733b5767bb5df44a2 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 07:31:35 -0400 Subject: [PATCH 01/22] updated to swift 6 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 6ca43cd..e1079b6 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.9 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription From 337801e3ab1d22b092752e49b75ca371a4b92a6e Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 07:33:30 -0400 Subject: [PATCH 02/22] updated readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9c8530..796fe2f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A one-stop shop for working with environment values in a Swift program. ## Overview -`SwiftDotenv` is a small and compact Swift package that allows you to load and save `.env` files at runtime and query for those values as well as system provided environemntal values via `ProcessInfo`. It's a single abstraction for dealing with environment variables at runtime in a local configuration file that doesn't get committed to version control, rather than hardcoding strings into your app or framework. +`SwiftDotenv` is a small and compact Swift scripting library that allows you to load and save `.env` files at runtime and query for those values as well as system provided environemntal values via `ProcessInfo`. It's a single abstraction for dealing with environment variables at runtime in a local configuration file that doesn't get committed to version control, rather than hardcoding strings into your app or framework. **IMPORTANT**: Please note that storing secrets or other sensitive information in the `.env` file does not necessarily make your app secure. For more information, see [this great article from NSHipster](https://nshipster.com/secrets/). @@ -12,6 +12,10 @@ A one-stop shop for working with environment values in a Swift program. `.env` files are used, most often in server-side applications, to inject environment variables into an application during active development. They can contain api keys, secrets, and other sensitive information and therefore **should not be committed to version control**. An environment file should only exist locally on a development machine; on a continuous integration system like TravisCI or CircleCI, environment variables are added via the respective UI in lieu of a `.env` file. +### When should I use this library? + +`SwiftDotenv` is primarily meant for _scripting use-cases only_, not within applications. This is because in order to access the `.env` file from your application, it would have to be included and bundled with your application which defeats the purpose of keeping them separate to start with. You can however still use `Dotenv` as a Swiftier way of interacting with the system environment variables which will just proxy to `processInfo.environment`. + ## Installation `SwiftDotenv` supports Swift Package Manager and can be added by adding this entry to your `Package.swift` manifest file: @@ -20,6 +24,8 @@ A one-stop shop for working with environment values in a Swift program. .package(url: "https://github.com/thebarndog/swift-dotenv.git", .upToNextMajor("2.0.0")) ``` +You can also use solutions such as [`swift-sh`](https://github.com/mxcl/swift-sh) for a less cumbersome scripting setup. + ## Usage ```swift From 5f678e9334ad7f5e7ef332cedab6baaa1adc877a Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 07:33:52 -0400 Subject: [PATCH 03/22] made static config vars nonisolated --- Sources/Dotenv.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Dotenv.swift b/Sources/Dotenv.swift index 1fc02a1..b69a702 100644 --- a/Sources/Dotenv.swift +++ b/Sources/Dotenv.swift @@ -92,13 +92,13 @@ public enum Dotenv { // MARK: - Configuration /// `FileManager` instance used to load and save configuration files. Can be replaced with a custom instance. - public static var fileManager = FileManager.default + nonisolated(unsafe) public static var fileManager = FileManager.default /// Delimeter for key value pairs, defaults to `=`. - public static var delimeter: Character = "=" + nonisolated(unsafe) public static var delimeter: Character = "=" /// Process info instance. - public static var processInfo: ProcessInfo = ProcessInfo.processInfo + nonisolated(unsafe) public static var processInfo: ProcessInfo = ProcessInfo.processInfo /// Configure the environment with environment values loaded from the environment file. /// - Parameters: From fbcca2dcf56b642a6f626af802520f63e76daf59 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 07:42:49 -0400 Subject: [PATCH 04/22] Create ci.yml --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8647b2f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +# This workflow will build a Swift project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift + +name: Swift + +on: + push: + branches: [ "develop", "production" ] + pull_request: + branches: [ "develop", "production" ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v From 670314d1812bb7361b3cbff187c9b086621ad700 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 07:47:09 -0400 Subject: [PATCH 05/22] added badges --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 796fe2f..9ba6ce0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # SwiftDotenv +[![CI](https://github.com/thebarndog/swift-dotenv/workflows/CI/badge.svg)](https://github.com/pointfreeco/swift-composable-architecture/actions?query=workflow%3ACI) +[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fthebarndog%2Fswift-dotenv%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/thebarndog/swift-dotenv) +[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fthebarndog%2Fswift-dotenv%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/thebarndog/swift-dotenv) + A one-stop shop for working with environment values in a Swift program. ## Overview From 8766b668fb7e460eaf61debcac215abe260fc38d Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 07:49:18 -0400 Subject: [PATCH 06/22] added cron schedule --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8647b2f..9742d28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,8 @@ on: branches: [ "develop", "production" ] pull_request: branches: [ "develop", "production" ] + schedule: + - cron: 0 0 * * * #trigger once a day, according to the cron syntax jobs: build: From 51333c0c570252dd562d90810ff7e702e229ca60 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:00:25 -0400 Subject: [PATCH 07/22] fixed tool version --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index e1079b6..bd33041 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:6.0 +// swift-tools-version:6.0.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription From ddfbb244ca7134535508bcaab3366cf3f1c8851c Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:02:11 -0400 Subject: [PATCH 08/22] added 6.0 to ci flow --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9742d28..87123f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + swift-version: '6.0' - name: Build run: swift build -v - name: Run tests From 51c8bb594c1de8685b6439933a67a47bbecd2dad Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:05:23 -0400 Subject: [PATCH 09/22] fully qualified --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87123f7..9b34817 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - swift-version: '6.0' + swift-version: '6.0.0' - name: Build run: swift build -v - name: Run tests From ecd378efec046e15ce0c1b2362329b05cce9d22e Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:10:37 -0400 Subject: [PATCH 10/22] used setup swift action --- .github/workflows/ci.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b34817..16d3521 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ # This workflow will build a Swift project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift -name: Swift +name: CI on: push: @@ -9,17 +9,22 @@ on: pull_request: branches: [ "develop", "production" ] schedule: - - cron: 0 0 * * * #trigger once a day, according to the cron syntax + - cron: 0 0 * * * # once a day jobs: build: - - runs-on: macos-latest + name: Swift ${{ matrix.swift }} on ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest] + swift: ["5.10.0", "6.0.0"] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: swift-actions/setup-swift@2.10.1 with: - swift-version: '6.0.0' + swift-version: ${{ matrix.swift } + - uses: actions/checkout@v4 - name: Build run: swift build -v - name: Run tests From f8529977a02280f43f62666de8228c0464465cd4 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:11:27 -0400 Subject: [PATCH 11/22] fixed syntax error --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16d3521..af8cfde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: steps: - uses: swift-actions/setup-swift@2.10.1 with: - swift-version: ${{ matrix.swift } + swift-version: ${{ matrix.swift }} - uses: actions/checkout@v4 - name: Build run: swift build -v From 188070970126152b3ba3492fd89df7f5c8f93e06 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:12:21 -0400 Subject: [PATCH 12/22] fixed version number --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af8cfde..79473d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: swift-actions/setup-swift@2.10.1 + - uses: swift-actions/setup-swift@2.1.0 with: swift-version: ${{ matrix.swift }} - uses: actions/checkout@v4 From 90f7d21ca5043eda0402ebc3022bdd6837088b85 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:13:37 -0400 Subject: [PATCH 13/22] syntax --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79473d2..2c72600 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: swift-actions/setup-swift@2.1.0 + - uses: swift-actions/setup-swift@v2.1.0 with: swift-version: ${{ matrix.swift }} - uses: actions/checkout@v4 From ed3dd47bca90d231dad45cfa58b5bfed4d3ca73e Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:14:30 -0400 Subject: [PATCH 14/22] changed to match tool syntax --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c72600..8a791d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [macos-latest] - swift: ["5.10.0", "6.0.0"] + swift: ["5.10", "6.0"] runs-on: ${{ matrix.os }} steps: From a2ec1260ce2d9b6a09d64f61607bf9f4345fe31e Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:14:47 -0400 Subject: [PATCH 15/22] changed versioning to be more inclusive --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a791d6..94a097d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: swift-actions/setup-swift@v2.1.0 + - uses: swift-actions/setup-swift@v2 with: swift-version: ${{ matrix.swift }} - uses: actions/checkout@v4 From 5ae03f3e27b38c123d860beea34e0e0b71495283 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:17:11 -0400 Subject: [PATCH 16/22] trying to setup xcode version instead --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94a097d..814d726 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,9 +21,9 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: swift-actions/setup-swift@v2 + - uses: maxim-lobanov/setup-xcode@v1 with: - swift-version: ${{ matrix.swift }} + xcode-version: latest-stable - uses: actions/checkout@v4 - name: Build run: swift build -v From a433ad01d811a4186d0d2094802573ccf1c811e6 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:18:33 -0400 Subject: [PATCH 17/22] added 5.9 tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 814d726..63bcc75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [macos-latest] - swift: ["5.10", "6.0"] + swift: ["5.9", "5.10", "6.0"] runs-on: ${{ matrix.os }} steps: From 0d6f6bb4a53e88a219181b71115758a2ee94567e Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:20:30 -0400 Subject: [PATCH 18/22] added linux support --- Sources/Dotenv.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Dotenv.swift b/Sources/Dotenv.swift index b69a702..b8671b9 100644 --- a/Sources/Dotenv.swift +++ b/Sources/Dotenv.swift @@ -1,4 +1,8 @@ +#if os(Linux) +import Glibc +#else import Darwin +#endif import Foundation /// Structure used to load and save environment files. @@ -164,7 +168,7 @@ public enum Dotenv { /// - key: Key to set the value with. /// - overwrite: Flag that indicates if any existing value should be overwritten, defaults to `true`. public static func set(value: String?, forKey key: String, overwrite: Bool = true) { - setenv(key, value, overwrite ? 1 : 0) + setenv(key, value ?? "", overwrite ? 1 : 0) } // MARK: - Subscripting From b43988bed46f83c0089366fd3dd6e0434c1862a7 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:21:58 -0400 Subject: [PATCH 19/22] added ubuntu --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63bcc75..60bf78e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,10 @@ -# This workflow will build a Swift project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift - name: CI on: push: - branches: [ "develop", "production" ] + branches: [develop, production] pull_request: - branches: [ "develop", "production" ] + branches: [develop, production] schedule: - cron: 0 0 * * * # once a day @@ -16,7 +13,7 @@ jobs: name: Swift ${{ matrix.swift }} on ${{ matrix.os }} strategy: matrix: - os: [macos-latest] + os: [ubuntu-latest, macos-latest] swift: ["5.9", "5.10", "6.0"] runs-on: ${{ matrix.os }} From 4bae8862b95d37f58d7345af9993698fafc0b131 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:24:53 -0400 Subject: [PATCH 20/22] removed ubuntu for now --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60bf78e..d2fc5a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: name: Swift ${{ matrix.swift }} on ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [macos-latest] swift: ["5.9", "5.10", "6.0"] runs-on: ${{ matrix.os }} From f7537c86ef33e1ff0e92fcf74a2105a1d7342bc3 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:37:23 -0400 Subject: [PATCH 21/22] added gitflow release workflow --- .github/workflows/gitflow.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/gitflow.yml diff --git a/.github/workflows/gitflow.yml b/.github/workflows/gitflow.yml new file mode 100644 index 0000000..b4cb0f3 --- /dev/null +++ b/.github/workflows/gitflow.yml @@ -0,0 +1,26 @@ +on: + workflow_dispatch: + inputs: + version_increment: + type: choice + required: true + description: "Version increment" + default: "patch" + options: + - "major" + - "minor" + - "patch" + +jobs: + gitflow-release: + name: Gitflow Release + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Gitflow Genius Action + uses: ./ + with: + version_increment: ${{ inputs.version_increment }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 3a1b53a49fbf3a701aba3bbc5e626ec591da1327 Mon Sep 17 00:00:00 2001 From: Brendan Conron Date: Tue, 17 Sep 2024 08:39:44 -0400 Subject: [PATCH 22/22] added name --- .github/workflows/gitflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/gitflow.yml b/.github/workflows/gitflow.yml index b4cb0f3..1f5dfbc 100644 --- a/.github/workflows/gitflow.yml +++ b/.github/workflows/gitflow.yml @@ -1,3 +1,5 @@ +name: Gitflow + on: workflow_dispatch: inputs: