Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
1e72dbcfc2
|
|||
|
a5b9280a46
|
|||
|
4b9c45dd5f
|
|||
|
529aa80c47
|
|||
|
66e286f267
|
|||
|
cb25dba7de
|
|||
|
9b99b35436
|
|||
|
0c6e9e1228
|
|||
|
fb246df01a
|
|||
|
0b153d7990
|
|||
|
558054464c
|
|||
|
54c07886ad
|
|||
|
f8e89ed0fa
|
|||
|
f596975bbc
|
|||
|
805100fa43
|
|||
|
f7f168b7fd
|
|||
|
99459a0a71
|
|||
|
f89efc8c5e
|
|||
|
85b285347b
|
|||
|
8c402f3f5f
|
|||
|
1429c51821
|
|||
|
1302b15ee2
|
|||
|
da810d0a45
|
|||
|
35d9422f07
|
|||
|
601869d457
|
|||
|
6d0108da0c
|
|||
|
bc0b740f95
|
|||
|
303cdef84b
|
|||
|
b5afc77428
|
|||
|
3f56dda568
|
|||
|
d1b3379815
|
|||
|
b557a60fa3
|
|||
|
5f4ef3b5b5
|
|||
|
ba1e61d99e
|
|||
|
bd56660683
|
|||
|
a480e942bc
|
|||
|
2b265a4ca5
|
|||
|
56a0bca00c
|
|||
|
7b30b78b67
|
|||
|
ce6eb3ec2f
|
|||
|
8302ede99e
|
|||
|
d9e91538fb
|
|||
|
c1a14ea855
|
|||
|
ddb5e6767a
|
|||
|
9c784d4dcb
|
|||
|
92cd6afa2b
|
|||
|
87390c4b63
|
|||
|
a8d35fed37
|
|||
|
357914ba93
|
|||
|
a39536364b
|
19
.gitea/workflows/release.yaml
Normal file
19
.gitea/workflows/release.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*.*.*"
|
||||||
|
- "v*.*.*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,3 +10,5 @@ DerivedData/
|
|||||||
.swiftpm/*
|
.swiftpm/*
|
||||||
./hpa.toml
|
./hpa.toml
|
||||||
./Version.*
|
./Version.*
|
||||||
|
/*.json
|
||||||
|
hpa
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"originHash" : "bc31b11e5e7d488e0a9c1bf91cb572d29f782bfd8e43f44157036f8f3d282893",
|
"originHash" : "f1d1e27e3b3b21d41b872325e0174196a323dc438bf3c9d9f99858856b457c96",
|
||||||
"pins" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "combine-schedulers",
|
"identity" : "combine-schedulers",
|
||||||
@@ -33,8 +33,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://git.housh.dev/michael/swift-cli-doc.git",
|
"location" : "https://git.housh.dev/michael/swift-cli-doc.git",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "e524056dc65c5ce7a6a77bdea4e5fa0bf724019b",
|
"revision" : "bbace73d974fd3e6985461431692bea773c7c5d8",
|
||||||
"version" : "0.2.0"
|
"version" : "0.2.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ let package = Package(
|
|||||||
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.3.3"),
|
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.3.3"),
|
||||||
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.5.2"),
|
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.5.2"),
|
||||||
.package(url: "https://github.com/m-housh/swift-shell-client.git", from: "0.1.0"),
|
.package(url: "https://github.com/m-housh/swift-shell-client.git", from: "0.1.0"),
|
||||||
.package(url: "https://git.housh.dev/michael/swift-cli-doc.git", from: "0.2.0"),
|
.package(url: "https://git.housh.dev/michael/swift-cli-doc.git", from: "0.2.1"),
|
||||||
.package(url: "https://github.com/m-housh/swift-cli-version.git", from: "0.1.0"),
|
.package(url: "https://github.com/m-housh/swift-cli-version.git", from: "0.1.0"),
|
||||||
.package(url: "https://github.com/LebJe/TOMLKit.git", from: "0.5.0")
|
.package(url: "https://github.com/LebJe/TOMLKit.git", from: "0.5.0")
|
||||||
],
|
],
|
||||||
@@ -70,6 +70,7 @@ let package = Package(
|
|||||||
name: "ConfigurationClient",
|
name: "ConfigurationClient",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"CodersClient",
|
"CodersClient",
|
||||||
|
"CommandClient",
|
||||||
"FileClient",
|
"FileClient",
|
||||||
.product(name: "Dependencies", package: "swift-dependencies"),
|
.product(name: "Dependencies", package: "swift-dependencies"),
|
||||||
.product(name: "DependenciesMacros", package: "swift-dependencies"),
|
.product(name: "DependenciesMacros", package: "swift-dependencies"),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import CodersClient
|
import CodersClient
|
||||||
|
import CommandClient
|
||||||
import Dependencies
|
import Dependencies
|
||||||
import DependenciesMacros
|
import DependenciesMacros
|
||||||
import FileClient
|
import FileClient
|
||||||
@@ -155,6 +156,7 @@ struct LiveConfigurationClient {
|
|||||||
private let environment: [String: String]
|
private let environment: [String: String]
|
||||||
|
|
||||||
@Dependency(\.coders) var coders
|
@Dependency(\.coders) var coders
|
||||||
|
@Dependency(\.commandClient) var commandClient
|
||||||
@Dependency(\.fileClient) var fileManager
|
@Dependency(\.fileClient) var fileManager
|
||||||
@Dependency(\.logger) var logger
|
@Dependency(\.logger) var logger
|
||||||
|
|
||||||
@@ -245,19 +247,13 @@ struct LiveConfigurationClient {
|
|||||||
try await fileManager.createDirectory(fileDirectory)
|
try await fileManager.createDirectory(fileDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: The hpa file needs to be copied somewhere on the system during install and
|
|
||||||
// not use bundle, as it only works if the tool was built on the users system.
|
|
||||||
if case .toml = file {
|
if case .toml = file {
|
||||||
// In the case of toml, we copy the internal resource that includes
|
// Copy the file using curl, because when installed as a pre-built binary we
|
||||||
// usage comments in the file.
|
// don't have access to bundled resources.
|
||||||
guard let resourceFile = Bundle.module.url(
|
try await commandClient.run(
|
||||||
forResource: HPAKey.resourceFileName,
|
quiet: true,
|
||||||
withExtension: HPAKey.resourceFileExtension
|
["curl", HPAKey.tomlConfigUrl, "--output", fileUrl.path]
|
||||||
) else {
|
)
|
||||||
throw ConfigurationError.resourceNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
try await fileManager.copy(resourceFile, fileUrl)
|
|
||||||
} else {
|
} else {
|
||||||
// Json does not allow comments, so we write the mock configuration
|
// Json does not allow comments, so we write the mock configuration
|
||||||
// to the file path.
|
// to the file path.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public enum HPAKey {
|
|||||||
public static let resourceFileExtension = "toml"
|
public static let resourceFileExtension = "toml"
|
||||||
public static let defaultFileName = "config.toml"
|
public static let defaultFileName = "config.toml"
|
||||||
public static let defaultFileNameWithoutExtension = "config"
|
public static let defaultFileNameWithoutExtension = "config"
|
||||||
|
public static let tomlConfigUrl = "https://git.housh.dev/michael/swift-hpa/raw/branch/main/Sources/ConfigurationClient/Resources/hpa.toml"
|
||||||
}
|
}
|
||||||
|
|
||||||
extension [String: String] {
|
extension [String: String] {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// Do not set this variable, it is set during the build process.
|
// Do not set this variable, it is set during the build process.
|
||||||
let VERSION: String? = nil
|
let VERSION: String? = "0.1.5"
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ struct ConfigurationClientTests: TestCase {
|
|||||||
@Test(arguments: ["config.toml", "config.json"])
|
@Test(arguments: ["config.toml", "config.json"])
|
||||||
func generateConfigFile(fileName: String) async throws {
|
func generateConfigFile(fileName: String) async throws {
|
||||||
try await withTestLogger(key: "generateConfigFile") {
|
try await withTestLogger(key: "generateConfigFile") {
|
||||||
|
$0.asyncShellClient = .liveValue
|
||||||
|
$0.commandClient = .liveValue
|
||||||
$0.coders = .liveValue
|
$0.coders = .liveValue
|
||||||
$0.fileClient = .liveValue
|
$0.fileClient = .liveValue
|
||||||
} operation: {
|
} operation: {
|
||||||
@@ -42,6 +44,8 @@ struct ConfigurationClientTests: TestCase {
|
|||||||
@Test(arguments: ["config.toml", "config.json", nil])
|
@Test(arguments: ["config.toml", "config.json", nil])
|
||||||
func loadConfigFile(fileName: String?) async throws {
|
func loadConfigFile(fileName: String?) async throws {
|
||||||
try await withTestLogger(key: "generateConfigFile") {
|
try await withTestLogger(key: "generateConfigFile") {
|
||||||
|
$0.asyncShellClient = .liveValue
|
||||||
|
$0.commandClient = .liveValue
|
||||||
$0.coders = .liveValue
|
$0.coders = .liveValue
|
||||||
$0.fileClient = .liveValue
|
$0.fileClient = .liveValue
|
||||||
} operation: {
|
} operation: {
|
||||||
@@ -65,6 +69,8 @@ struct ConfigurationClientTests: TestCase {
|
|||||||
@Test(arguments: ["config.toml", "config.json", ".hparc.json", ".hparc.toml"])
|
@Test(arguments: ["config.toml", "config.json", ".hparc.json", ".hparc.toml"])
|
||||||
func findConfiguration(fileName: String) async throws {
|
func findConfiguration(fileName: String) async throws {
|
||||||
try await withTestLogger(key: "findConfiguration") {
|
try await withTestLogger(key: "findConfiguration") {
|
||||||
|
$0.asyncShellClient = .liveValue
|
||||||
|
$0.commandClient = .liveValue
|
||||||
$0.fileClient = .liveValue
|
$0.fileClient = .liveValue
|
||||||
} operation: {
|
} operation: {
|
||||||
@Dependency(\.logger) var logger
|
@Dependency(\.logger) var logger
|
||||||
@@ -94,6 +100,8 @@ struct ConfigurationClientTests: TestCase {
|
|||||||
@Test(arguments: ["config.toml", "config.json", ".hparc.json", ".hparc.toml"])
|
@Test(arguments: ["config.toml", "config.json", ".hparc.json", ".hparc.toml"])
|
||||||
func findXdgConfiguration(fileName: String) async throws {
|
func findXdgConfiguration(fileName: String) async throws {
|
||||||
try await withTestLogger(key: "findXdgConfiguration") {
|
try await withTestLogger(key: "findXdgConfiguration") {
|
||||||
|
$0.asyncShellClient = .liveValue
|
||||||
|
$0.commandClient = .liveValue
|
||||||
$0.fileClient = .liveValue
|
$0.fileClient = .liveValue
|
||||||
} operation: {
|
} operation: {
|
||||||
@Dependency(\.logger) var logger
|
@Dependency(\.logger) var logger
|
||||||
@@ -133,6 +141,8 @@ struct ConfigurationClientTests: TestCase {
|
|||||||
@Test
|
@Test
|
||||||
func writeCreatesBackupFile() async throws {
|
func writeCreatesBackupFile() async throws {
|
||||||
try await withDependencies {
|
try await withDependencies {
|
||||||
|
$0.asyncShellClient = .liveValue
|
||||||
|
$0.commandClient = .liveValue
|
||||||
$0.fileClient = .liveValue
|
$0.fileClient = .liveValue
|
||||||
} operation: {
|
} operation: {
|
||||||
let client = ConfigurationClient.liveValue
|
let client = ConfigurationClient.liveValue
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ FROM swift:${SWIFT_IMAGE_VERSION}-slim
|
|||||||
RUN export DEBIAN_FRONTEND=nointeractive DEBCONF_NOINTERACTIVE_SEEN=true && apt-get -q update && \
|
RUN export DEBIAN_FRONTEND=nointeractive DEBCONF_NOINTERACTIVE_SEEN=true && apt-get -q update && \
|
||||||
apt-get -q install -y \
|
apt-get -q install -y \
|
||||||
ansible \
|
ansible \
|
||||||
|
curl \
|
||||||
pandoc \
|
pandoc \
|
||||||
texlive \
|
texlive \
|
||||||
&& rm -r /var/lib/apt/lists/*
|
&& rm -r /var/lib/apt/lists/*
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
ARG SWIFT_IMAGE_VERSION="6.0.3"
|
ARG SWIFT_IMAGE_VERSION="6.0.3"
|
||||||
FROM swift:${SWIFT_IMAGE_VERSION}
|
FROM swift:${SWIFT_IMAGE_VERSION}
|
||||||
|
|
||||||
|
RUN export DEBIAN_FRONTEND=nointeractive DEBCONF_NOINTERACTIVE_SEEN=true && apt-get -q update && \
|
||||||
|
apt-get -q install -y \
|
||||||
|
curl \
|
||||||
|
&& rm -r /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY ./Package.* ./
|
COPY ./Package.* ./
|
||||||
RUN swift package resolve
|
RUN swift package resolve
|
||||||
|
|||||||
36
justfile
36
justfile
@@ -2,44 +2,68 @@ docker_image_name := "swift-hpa"
|
|||||||
install_path := "~/.local/share/bin/hpa"
|
install_path := "~/.local/share/bin/hpa"
|
||||||
completion_path := "~/.local/share/zsh/completions/_hpa"
|
completion_path := "~/.local/share/zsh/completions/_hpa"
|
||||||
|
|
||||||
build mode="debug":
|
tap_url := "https://git.housh.dev/michael/homebrew-formula"
|
||||||
swift build -c {{mode}}
|
tap := "michael/formula"
|
||||||
|
formula := "hpa"
|
||||||
|
|
||||||
|
# Build and bottle homebrew formula.
|
||||||
|
bottle:
|
||||||
|
@brew uninstall {{formula}} || true
|
||||||
|
@brew tap {{tap}} {{tap_url}}
|
||||||
|
@brew install --build-bottle {{tap}}/{{formula}}
|
||||||
|
@brew bottle {{formula}}
|
||||||
|
bottle="$(ls *.gz)" && mv "${bottle}" "${bottle/--/-}"
|
||||||
|
|
||||||
|
# Build the command-line tool.
|
||||||
|
build configuration="debug" arch="arm64":
|
||||||
|
swift build \
|
||||||
|
--disable-sandbox \
|
||||||
|
--configuration {{configuration}} \
|
||||||
|
--arch {{arch}}
|
||||||
|
|
||||||
alias b := build
|
alias b := build
|
||||||
|
|
||||||
|
# Build the docker image.
|
||||||
build-docker file="Dockerfile" tag="latest":
|
build-docker file="Dockerfile" tag="latest":
|
||||||
@docker build \
|
@docker build \
|
||||||
--file docker/{{file}} \
|
--file docker/{{file}} \
|
||||||
--tag {{docker_image_name}}:{{tag}} .
|
--tag {{docker_image_name}}:{{tag}} .
|
||||||
|
|
||||||
|
# Build the docker test image used for testing.
|
||||||
build-docker-test: (build-docker "Dockerfile.test" "test")
|
build-docker-test: (build-docker "Dockerfile.test" "test")
|
||||||
|
|
||||||
|
build-universal-binary: (build "release" "arm64") (build "release" "x86_64")
|
||||||
|
@lipo -create -output {{formula}} \
|
||||||
|
".build/arm64-apple-macosx/release/hpa" \
|
||||||
|
".build/x86_64-apple-macosx/release/hpa"
|
||||||
|
|
||||||
|
# Run tests.
|
||||||
test *ARGS:
|
test *ARGS:
|
||||||
swift test {{ARGS}}
|
swift test {{ARGS}}
|
||||||
|
|
||||||
alias t := test
|
alias t := test
|
||||||
|
|
||||||
|
# Run tests in docker container.
|
||||||
test-docker *ARGS: (build-docker-test)
|
test-docker *ARGS: (build-docker-test)
|
||||||
@docker run --rm \
|
@docker run --rm \
|
||||||
--network host \
|
--network host \
|
||||||
{{docker_image_name}}:test \
|
{{docker_image_name}}:test \
|
||||||
swift test {{ARGS}}
|
swift test {{ARGS}}
|
||||||
|
|
||||||
|
# Run the application.
|
||||||
run *ARGS:
|
run *ARGS:
|
||||||
swift run hpa {{ARGS}}
|
swift run hpa {{ARGS}}
|
||||||
|
|
||||||
alias r := run
|
alias r := run
|
||||||
|
|
||||||
|
# Clean the build folder.
|
||||||
clean:
|
clean:
|
||||||
rm -rf .build
|
rm -rf .build
|
||||||
|
|
||||||
|
# Bump the version based on the git tag.
|
||||||
update-version:
|
update-version:
|
||||||
@swift package \
|
@swift package \
|
||||||
--disable-sandbox \
|
--disable-sandbox \
|
||||||
--allow-writing-to-package-directory \
|
--allow-writing-to-package-directory \
|
||||||
update-version \
|
update-version \
|
||||||
hpa
|
hpa
|
||||||
|
|
||||||
install: (build "release")
|
|
||||||
@cp .build/release/hpa {{install_path}}
|
|
||||||
@{{install_path}} --generate-completion-script zsh > {{completion_path}}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user