Skip to content

Commit

Permalink
fixing for linux (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion authored May 18, 2023
1 parent fad1b0a commit 2321aa2
Show file tree
Hide file tree
Showing 24 changed files with 719 additions and 661 deletions.
174 changes: 81 additions & 93 deletions .github/workflows/StealthyStash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ on:
push:
branches-ignore:
- '*WIP'
pull_request:
# Sequence of patterns matched against refs/heads
branches:
- main
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

env:
CODEQL_ENABLE_EXPERIMENTAL_FEATURES_SWIFT: true

jobs:
build-ubuntu:
name: Build on Ubuntu
Expand All @@ -19,43 +16,37 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
runs-on: [ubuntu-18.04, ubuntu-20.04]
swift-version: [5.5.2, 5.6.2, 5.7]
include:
- runs-on: ubuntu-22.04
swift-version: 5.7.1
runs-on: [ubuntu-20.04, ubuntu-22.04]
swift-version: [5.7.3, 5.8]
steps:
- uses: actions/checkout@v3
- name: Set Ubuntu Release DOT
run: echo "RELEASE_DOT=$(lsb_release -sr)" >> $GITHUB_ENV
- name: Set Ubuntu Release NUM
run: echo "RELEASE_NUM=${RELEASE_DOT//[-._]/}" >> $GITHUB_ENV
- name: Set Ubuntu Codename
run: echo "RELEASE_NAME=$(lsb_release -sc)" >> $GITHUB_ENV
- name: Cache swift package modules
id: cache-spm-linux
uses: actions/cache@v3
env:
cache-name: cache-spm
with:
path: .build
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Package.resolved') }}
key: ${{ runner.os }}-${{ env.RELEASE_DOT }}-${{ env.cache-name }}-${{ matrix.swift-version }}-${{ hashFiles('Package.resolved') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Set Ubuntu Release DOT
run: echo "RELEASE_DOT=$(lsb_release -sr)" >> $GITHUB_ENV
- name: Set Ubuntu Release NUM
run: echo "RELEASE_NUM=${RELEASE_DOT//[-._]/}" >> $GITHUB_ENV
- name: Set Ubuntu Codename
run: echo "RELEASE_NAME=$(lsb_release -sc)" >> $GITHUB_ENV
${{ runner.os }}-${{ env.RELEASE_DOT }}-${{ env.cache-name }}-${{ matrix.swift-version }}-
${{ runner.os }}-${{ env.RELEASE_DOT }}-${{ env.cache-name }}-
- name: Cache swift
id: cache-swift-linux
uses: actions/cache@v3
env:
cache-name: cache-swift
with:
path: swift-${{ env.SWIFT_VER }}-RELEASE-ubuntu${{ env.RELEASE_DOT }}
key: ${{ runner.os }}-${{ env.RELEASE_DOT }}-${{ env.cache-name }}-${{ env.SWIFT_VER }}
key: ${{ runner.os }}-${{ env.cache-name }}-${{ matrix.swift-version }}-${{ env.RELEASE_DOT }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ runner.os }}-${{ env.cache-name }}-${{ matrix.swift-version }}-
- name: Download Swift
if: steps.cache-swift-linux.outputs.cache-hit != 'true'
run: curl -O https://download.swift.org/swift-${SWIFT_VER}-release/ubuntu${RELEASE_NUM}/swift-${SWIFT_VER}-RELEASE/swift-${SWIFT_VER}-RELEASE-ubuntu${RELEASE_DOT}.tar.gz
Expand All @@ -66,44 +57,37 @@ jobs:
run: echo "$GITHUB_WORKSPACE/swift-${SWIFT_VER}-RELEASE-ubuntu${RELEASE_DOT}/usr/bin" >> $GITHUB_PATH
- name: Build
run: swift build
- name: Test
run: swift test --enable-code-coverage
- uses: sersoft-gmbh/swift-coverage-action@v3
with:
fail-on-empty-output: true
- name: Upload package coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
flags: spm,swift-${{ matrix.swift-version }}
token: ${{ secrets.CODECOV_TOKEN }}
build-macos:
name: Build on macOS
runs-on: ${{ matrix.runs-on }}
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
include:
# - runs-on: macos-12
# xcode: "/Applications/Xcode_14.0.1.app"
# iOSVersion: "16.0"
# watchOSVersion: "9.0"
# watchName: "Apple Watch Series 8 (41mm)"
# iPhoneName: "iPhone 12"
# - runs-on: macos-12
# xcode: "/Applications/Xcode_14.1.app"
# iOSVersion: "16.1"
# watchOSVersion: "9.1"
# watchName: "Apple Watch Ultra (49mm)"
# iPhoneName: "iPhone 13"
- runs-on: macos-12
xcode: "/Applications/Xcode_13.4.1.app"
iOSVersion: 15.5
watchOSVersion: 8.5
watchName: "Apple Watch Series 7 - 41mm"
- runs-on: macos-12
xcode: "/Applications/Xcode_14.0.1.app"
iOSVersion: "16.0"
watchOSVersion: "9.0"
watchName: "Apple Watch Series 8 (41mm)"
- runs-on: macos-12
xcode: "/Applications/Xcode_14.1.app"
iOSVersion: "16.1"
xcode: "/Applications/Xcode_14.2.app"
iOSVersion: "16.2"
watchOSVersion: "9.1"
watchName: "Apple Watch Ultra (49mm)"
- runs-on: macos-12
xcode: "/Applications/Xcode_13.3.app"
iOSVersion: 15.4
watchOSVersion: 8.5
watchName: "Apple Watch Series 7 - 41mm"
iPhoneName: "iPhone 14"
- runs-on: macos-13
xcode: "/Applications/Xcode_14.3.app"
iOSVersion: "16.4"
watchOSVersion: "9.4"
watchName: "Apple Watch Ultra (49mm)"
iPhoneName: "iPhone 14 Pro Max"
steps:
- uses: actions/checkout@v3
- name: Cache swift package modules
Expand All @@ -113,13 +97,11 @@ jobs:
cache-name: cache-spm
with:
path: .build
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Package.resolved') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.xcode }}-${{ hashFiles('Package.resolved') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.xcode }}-
- name: Cache mint
if: ${{ github.ref_name == 'main' && matrix.xcode == '/Applications/Xcode_14.1.app' }}
if: startsWith(matrix.xcode,'/Applications/Xcode_14.3')
id: cache-mint
uses: actions/cache@v3
env:
Expand All @@ -136,44 +118,50 @@ jobs:
- name: Setup Xcode
run: sudo xcode-select -s ${{ matrix.xcode }}/Contents/Developer
- name: Install mint
if: ${{ github.ref_name == 'main' && matrix.xcode == '/Applications/Xcode_14.1.app' }}
if: startsWith(matrix.xcode,'/Applications/Xcode_14.3')
run: |
brew update
brew install mint
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: swift
- name: Build
run: swift build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Lint
run: ./scripts/lint.sh
if: ${{ github.ref_name == 'main' && matrix.xcode == '/Applications/Xcode_14.1.app' }}
- name: Dump PIF
if: startsWith(matrix.xcode,'/Applications/Xcode_14')
run: |
swift package dump-pif > /dev/null
MAX_ATTEMPT=3
ATTEMPT=0
while [ -z $SUCCESS ] && [ "$ATTEMPT" -le "$MAX_ATTEMPT" ]; do
xcodebuild clean -scheme StealthyStash -destination 'generic/platform=iOS' | grep -q "CLEAN SUCCEEDED" && SUCCESS=true
ATTEMPT=$(($ATTEMPT+1))
done
- name: Run iOS target tests
run: xcodebuild test -scheme StealthyStash -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13,OS=${{ matrix.iOSVersion }}' -enableCodeCoverage YES build test
- uses: sersoft-gmbh/swift-coverage-action@v3
with:
fail-on-empty-output: true
- name: Upload iOS coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
flags: iOS,iOS-${{ matrix.iOSVersion }}
token: ${{ secrets.CODECOV_TOKEN }}
- name: Run watchOS target tests
run: xcodebuild test -scheme StealthyStash -sdk watchsimulator -destination 'platform=watchOS Simulator,name=${{ matrix.watchName }},OS=${{ matrix.watchOSVersion }}' -enableCodeCoverage YES build test
- uses: sersoft-gmbh/swift-coverage-action@v3
with:
fail-on-empty-output: true
- name: Upload watchOS coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
flags: watchOS,watchOS${{ matrix.watchOSVersion }}
token: ${{ secrets.CODECOV_TOKEN }}
if: ${{ github.ref_name == 'main' && matrix.xcode == '/Applications/Xcode_14.3.app' }}
# - name: Dump PIF
# if: startsWith(matrix.xcode,'/Applications/Xcode_14')
# run: |
# swift package dump-pif > /dev/null
# MAX_ATTEMPT=3
# ATTEMPT=0
# while [ -z $SUCCESS ] && [ "$ATTEMPT" -le "$MAX_ATTEMPT" ]; do
# xcodebuild clean -scheme StealthyStash -destination 'generic/platform=iOS' | grep -q "CLEAN SUCCEEDED" && SUCCESS=true
# ATTEMPT=$(($ATTEMPT+1))
# done
# - name: Run iOS target tests
# run: xcodebuild test -scheme StealthyStash -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13,OS=${{ matrix.iOSVersion }}' -enableCodeCoverage YES build test
# - uses: sersoft-gmbh/swift-coverage-action@v3
# with:
# fail-on-empty-output: true
# - name: Upload iOS coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# fail_ci_if_error: true
# flags: iOS,iOS-${{ matrix.iOSVersion }}
# token: ${{ secrets.CODECOV_TOKEN }}
# - name: Run watchOS target tests
# run: xcodebuild test -scheme StealthyStash -sdk watchsimulator -destination 'platform=watchOS Simulator,name=${{ matrix.watchName }},OS=${{ matrix.watchOSVersion }}' -enableCodeCoverage YES build test
# - uses: sersoft-gmbh/swift-coverage-action@v3
# with:
# fail-on-empty-output: true
# - name: Upload watchOS coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# fail_ci_if_error: true
# flags: watchOS,watchOS${{ matrix.watchOSVersion }}
# token: ${{ secrets.CODECOV_TOKEN }}
14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
"version" : "1.5.2"
}
}
],
"version" : 2
}
9 changes: 8 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0")
],
targets: [
.target(
name: "StealthyStash",
dependencies: []
dependencies: [
.product(
name: "Logging",
package: "swift-log",
condition: .when(platforms: [.linux, .android, .windows, .wasi])
)
]
),
.testTarget(
name: "StealthyStashTests",
Expand Down
66 changes: 34 additions & 32 deletions Sources/StealthyStash/CommonAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,39 @@ internal struct CommonAttributes {
}
}

extension CommonAttributes {
// swiftlint:disable:next function_body_length
internal init(dictionary: StealthyDictionary, isRaw: Bool) throws {
let account: String = try dictionary.require(kSecAttrAccount)
let data: Data = try dictionary.require(kSecValueData)
let accessGroup: String? = try dictionary.requireOptional(kSecAttrAccessGroup)
let createdAt: Date? = try dictionary.requireOptional(kSecAttrCreationDate)
let modifiedAt: Date? = try dictionary.requireOptional(kSecAttrModificationDate)
let description: String? = try dictionary.requireOptional(kSecAttrDescription)
let comment: String? = try dictionary.requireOptional(kSecAttrComment)
let type: Int? = try dictionary.requireOptionalCF(kSecAttrType)
let label: String? = try dictionary.requireOptionalCF(kSecAttrLabel)
let isSynchronizable: Synchronizable
if isRaw {
let value = dictionary[kSecAttrSynchronizable as String]
isSynchronizable = value.flatMap(Synchronizable.init(rawDictionaryValue:)) ?? .any
} else {
let syncValue: Int? = try dictionary.requireOptional(kSecAttrSynchronizable)
isSynchronizable = .init(syncValue)
#if canImport(Security)
extension CommonAttributes {
// swiftlint:disable:next function_body_length
internal init(dictionary: StealthyDictionary, isRaw: Bool) throws {
let account: String = try dictionary.require(kSecAttrAccount)
let data: Data = try dictionary.require(kSecValueData)
let accessGroup: String? = try dictionary.requireOptional(kSecAttrAccessGroup)
let createdAt: Date? = try dictionary.requireOptional(kSecAttrCreationDate)
let modifiedAt: Date? = try dictionary.requireOptional(kSecAttrModificationDate)
let description: String? = try dictionary.requireOptional(kSecAttrDescription)
let comment: String? = try dictionary.requireOptional(kSecAttrComment)
let type: Int? = try dictionary.requireOptionalCF(kSecAttrType)
let label: String? = try dictionary.requireOptionalCF(kSecAttrLabel)
let isSynchronizable: Synchronizable
if isRaw {
let value = dictionary[kSecAttrSynchronizable as String]
isSynchronizable = value.flatMap(Synchronizable.init(rawDictionaryValue:)) ?? .any
} else {
let syncValue: Int? = try dictionary.requireOptional(kSecAttrSynchronizable)
isSynchronizable = .init(syncValue)
}
self.init(
account: account,
data: data,
accessGroup: accessGroup,
createdAt: createdAt,
modifiedAt: modifiedAt,
description: description,
comment: comment,
type: type?.trimZero(),
label: label,
isSynchronizable: isSynchronizable
)
}
self.init(
account: account,
data: data,
accessGroup: accessGroup,
createdAt: createdAt,
modifiedAt: modifiedAt,
description: description,
comment: comment,
type: type?.trimZero(),
label: label,
isSynchronizable: isSynchronizable
)
}
}
#endif
2 changes: 0 additions & 2 deletions Sources/StealthyStash/DefaultProvider.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Security

/// A protocol that provides default values for creating or querying the keychain.
public protocol DefaultProvider {
/// Returns the attribute dictionary for the keychain query.
Expand Down
Loading

0 comments on commit 2321aa2

Please sign in to comment.