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

Release 2.1.0 #36

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b5ad421
updated to swift 6
thebarndog Sep 17, 2024
337801e
updated readme
thebarndog Sep 17, 2024
5f678e9
made static config vars nonisolated
thebarndog Sep 17, 2024
fbcca2d
Create ci.yml
thebarndog Sep 17, 2024
670314d
added badges
thebarndog Sep 17, 2024
8766b66
added cron schedule
thebarndog Sep 17, 2024
0237454
Merge pull request #27 from thebarndog/chore/gh-workflow
thebarndog Sep 17, 2024
bec9e0b
Merge branch 'develop' into chore/swift-6-and-documentation
thebarndog Sep 17, 2024
51333c0
fixed tool version
thebarndog Sep 17, 2024
ddfbb24
added 6.0 to ci flow
thebarndog Sep 17, 2024
51c8bb5
fully qualified
thebarndog Sep 17, 2024
ecd378e
used setup swift action
thebarndog Sep 17, 2024
f852997
fixed syntax error
thebarndog Sep 17, 2024
1880709
fixed version number
thebarndog Sep 17, 2024
90f7d21
syntax
thebarndog Sep 17, 2024
ed3dd47
changed to match tool syntax
thebarndog Sep 17, 2024
a2ec126
changed versioning to be more inclusive
thebarndog Sep 17, 2024
5ae03f3
trying to setup xcode version instead
thebarndog Sep 17, 2024
a433ad0
added 5.9 tests
thebarndog Sep 17, 2024
0d6f6bb
added linux support
thebarndog Sep 17, 2024
b43988b
added ubuntu
thebarndog Sep 17, 2024
4bae886
removed ubuntu for now
thebarndog Sep 17, 2024
9cd67e0
Merge pull request #26 from thebarndog/chore/swift-6-and-documentation
thebarndog Sep 17, 2024
f7537c8
added gitflow release workflow
thebarndog Sep 17, 2024
3a1b53a
added name
thebarndog Sep 17, 2024
492e7ab
Merge pull request #28 from thebarndog/chore/gitflow-releases
thebarndog Sep 17, 2024
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
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
28 changes: 28 additions & 0 deletions .github/workflows/gitflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Gitflow

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 }}
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.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
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:
Expand All @@ -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
Expand Down
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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading