Skip to content

Commit

Permalink
Merge pull request #43 from thebarndog/release/2.1.0
Browse files Browse the repository at this point in the history
[Release] - 2.1.0
thebarndog authored Sep 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents f6e7ca8 + f5541cf commit d130629
Showing 6 changed files with 109 additions and 6 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: [develop, production]
pull_request:
branches: [develop, production]
schedule:
- cron: 0 0 * * * # once a day

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest]
swift: ["5.9", "5.10", "6.0"]
runs-on: ${{ matrix.os }}

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v4
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
40 changes: 40 additions & 0 deletions .github/workflows/gitflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Gitflow Release

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:
- uses: actions/checkout@v4
- name: gitflow-workflow-action release workflows
id: gitflow
uses: hoangvvo/gitflow-workflow-action@0.3.7
with:
develop_branch: "develop"
main_branch: "production"
merge_back_from_main: true
version_increment: ${{ inputs.version_increment }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install GitHub CLI
run: brew install gh
- name: Update pull request title
run: |
PR_NUMBER="${{ steps.gitflow.outputs.pull_number }}"
VERSION=$(echo "${{ steps.gitflow.outputs.version }}" | sed 's/^v//')
gh pr edit $PR_NUMBER --title "[Release] - $VERSION"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Brendan Conron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# 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

`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/).

### What is a `.env` file?

`.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 +28,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
12 changes: 8 additions & 4 deletions Sources/Dotenv.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if os(Linux)
import Glibc
#else
import Darwin
#endif
import Foundation

/// Structure used to load and save environment files.
@@ -92,13 +96,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:
@@ -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

0 comments on commit d130629

Please sign in to comment.