From f8d682b69d56d72abcadfb98981508f2f83c5480 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Thu, 6 Jul 2023 10:31:52 +0200 Subject: [PATCH] Init --- .github/workflows/publish-swift-package.yaml | 67 ++++++++++ .gitignore | 121 +++++++++++++++++++ LICENSE | 21 ++++ README.md | 40 ++++++ 4 files changed, 249 insertions(+) create mode 100644 .github/workflows/publish-swift-package.yaml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md diff --git a/.github/workflows/publish-swift-package.yaml b/.github/workflows/publish-swift-package.yaml new file mode 100644 index 0000000..f1cabe5 --- /dev/null +++ b/.github/workflows/publish-swift-package.yaml @@ -0,0 +1,67 @@ +name: Publish Swift Bindings +on: + workflow_dispatch: + inputs: + version: + description: 'nostr repo release (MAJOR.MINOR.PATCH)' + required: true + type: string + +jobs: + build-tag-release: + name: Build, tag, and release the Nostr SDK Swift bindings + runs-on: macOS-latest + permissions: + contents: write + steps: + - name: Checkout nostr repo + uses: actions/checkout@v3 + with: + repository: ${{ github.repository_owner }}/nostr + path: build + ref: nostr-ffi-v${{ inputs.version }} + + - name: Checkout nostr-swift repo + uses: actions/checkout@v3 + with: + path: dist + ssh-key: ${{ secrets.SWIFT_DEPLOY_SSH_KEY }} + + - name: Build Swift bindings + working-directory: build/bindings/nostr-ffi + run: | + make init + make bindings-swift + + - name: Compress XCFramework + working-directory: build/bindings/nostr-ffi/bindings-swift + run: | + zip -9 -r nostrFFI.xcframework.zip nostrFFI.xcframework + echo "XCF_CHECKSUM=`swift package compute-checksum nostrFFI.xcframework.zip`" >> $GITHUB_ENV + + - name: Update Swift Package definition + working-directory: build/bindings/nostr-ffi/bindings-swift + run: | + sed 's#.binaryTarget(name: "nostrFFI", path: "./nostrFFI.xcframework"),#.binaryTarget(name: "nostrFFI", url: "https://github.com/rust-nostr/nostr-swift/releases/download/${{ inputs.version }}/nostrFFI.xcframework.zip", checksum: "${{ env.XCF_CHECKSUM }}"),#;/.testTarget(name: "NostrTests", dependencies: \["Nostr"\]),/d' Package.swift > ../../../../dist/Package.swift + cp -r Sources ../../../../dist + + - name: Tag the Swift bindings + working-directory: dist + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add Package.swift + git add Sources + git commit -m "Update Nostr Swift bindings to version ${{ inputs.version }}" + git push + git tag ${{ inputs.version }} -m "${{ inputs.version }}" + git push --tags + + - name: Release and attach XCFramework binary artifact + uses: ncipollo/release-action@v1 + with: + artifacts: "build/bindings/nostr-ffi/bindings-swift/nostrFFI.xcframework.zip" + tag: ${{ inputs.version }} + token: ${{ secrets.GITHUB_TOKEN }} + name: ${{ inputs.version }} + prerelease: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edca928 --- /dev/null +++ b/.gitignore @@ -0,0 +1,121 @@ +# Created by https://www.toptal.com/developers/gitignore/api/macos,swift +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,swift + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# Pods/ +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +# End of https://www.toptal.com/developers/gitignore/api/macos,swift diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ff5644 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-2023 Yuki Kishimoto + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..42e9af5 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Nostr – Swift Package + +## Installation + +This package is intended to be used with the [Swift Package Manager](https://www.swift.org/package-manager/). + +### Xcode + +Via `File > Add Packages...`, add + +``` +https://github.com/rust-nostr/nostr-swift.git +``` + +as a package dependency in Xcode. + +### Swift Package + +Add the following to the dependencies array in your `Package.swift`: + +``` swift +.package(url: "https://github.com/rust-nostr/nostr-swift.git", from: "0.0.1"), +``` + +## 📄 Usage + +``` swift +import Nostr + +// TODO + +``` + +## Information for Maintainers and Contributors + +This repository is used to publish a Swift package providing Swift bindings to the Nostr's [underlying Rust implementation](https://github.com/rust-nostr/nostr). The Swift bindings are generated using [UniFFi](https://github.com/mozilla/uniffi-rs). + +Any changes to the Nostr SDK, the Swift bindings, and the configuration of this Swift package must be made via the [nostr](https://github.com/rust-nostr/nostr) repo. + +To release a new version of this package, go to the Actions tab of this GitHub repository. Then select the *Publish Swift Package* workflow and run it on the `master` branch. It will ask for a version as input. This allows you to specify the version (e.g., *0.0.1*) of the [nostr](https://github.com/rust-nostr/nostr) repository that should be released as a Swift package.