From e6fe03c190ad963aee91578d2acd901cbbd76a04 Mon Sep 17 00:00:00 2001
From: Hiddify <114227601+hiddify-com@users.noreply.github.com>
Date: Tue, 16 Jan 2024 16:52:42 +0000
Subject: [PATCH] new: add sha256 to github action for ios
---
.github/workflows/release.yml | 6 +++-
Makefile | 8 +++--
Package.swift | 63 +++++++++++++++++++++++------------
3 files changed, 52 insertions(+), 25 deletions(-)
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f76fdd4..98166e2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -83,7 +83,11 @@ jobs:
else
gzip -r -S ".gz" ./bin/hiddify-libcore*
fi
-
+ - name: Calculate SHA256 Checksum
+ if: startsWith(matrix.job.target,'ios')
+ run: |
+ sha256sum hiddify-libcore-ios.xcframework.zip > hiddify-libcore-ios.xcframework.zip.sha256
+ working-directory: bin
- uses: actions/upload-artifact@v3
if: ${{ success() }}
with:
diff --git a/Makefile b/Makefile
index 96b8264..1b00e8e 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ ios-full: lib_install
ios: lib_install
gomobile bind -v -target ios -libname=box -tags=$(TAGS),with_dhcp,with_low_memory,with_conntrack -trimpath -ldflags="-w -s" -o $(BINDIR)/$(PRODUCT_NAME).xcframework github.com/sagernet/sing-box/experimental/libbox ./mobile &&\
mv $(BINDIR)/$(PRODUCT_NAME).xcframework $(BINDIR)/$(NAME).xcframework &&\
- cp Libcore.podspec $(BINDIR)/$(NAME).xcframework/
+ # cp Libcore.podspec $(BINDIR)/$(NAME).xcframework/
cp Info.plist $(BINDIR)/$(NAME).xcframework/
@@ -61,12 +61,14 @@ release: # Create a new tag for release.
VERSION_STR="$${VERSION_ARRAY[0]}.$${VERSION_ARRAY[1]}.$${VERSION_ARRAY[2]}" && \
BUILD_NUMBER=$$(( $${VERSION_ARRAY[0]} * 10000 + $${VERSION_ARRAY[1]} * 100 + $${VERSION_ARRAY[2]} )) && \
echo "version: $${VERSION_STR}+$${BUILD_NUMBER}" && \
- sed -i "s/^s.version: .*/s.version = '$${VERSION_STR}'/g" Libcore.podspec && \
+ # sed -i "s/^s.version: .*/s.version = '$${VERSION_STR}'/g" Libcore.podspec && \
+ sed -i "s/^let version: .*/let version = \"v$${VERSION_STR}\"/g" Package.swift && \
+
sed -i -e "s|CFBundleVersion\s*[^<]*|CFBundleVersion$${VERSION_STR}|" Info.plist &&\
sed -i -e "s|CFBundleShortVersionString\s*[^<]*|CFBundleShortVersionString$${VERSION_STR}|" Info.plist &&\
git tag $${TAG} > /dev/null && \
git tag -d $${TAG} > /dev/null && \
- git add Libcore.podspec Info.plist && \
+ git add Package.swift Info.plist && \
git commit -m "release: version $${TAG}" && \
echo "creating git tag : v$${TAG}" && \
git tag v$${TAG} && \
diff --git a/Package.swift b/Package.swift
index f636380..cbd1e72 100644
--- a/Package.swift
+++ b/Package.swift
@@ -3,24 +3,45 @@
import PackageDescription
-let package = Package(
- name: "Libcore",
- platforms: [
- .iOS(.v13) // Minimum platform version
- ],
- products: [
- .library(
- name: "Libcore",
- targets: ["Libcore"]),
- ],
- dependencies: [
- // No dependencies
- ],
- targets: [
- .binaryTarget(
- name: "Libcore",
- url: "https://github.com/hiddify/hiddify-next-core/releases/download/draft/hiddify-libcore-ios.xcframework.zip",
- checksum: "70f84a51508898a706e72ab9eda4af8ab72c321bf79284b38313764b8f2091b2"
- )
- ]
-)
+func fetchChecksum(from url: String) throws -> String {
+ guard let checksumURL = URL(string: url) else {
+ throw NSError(domain: "Invalid URL", code: 0, userInfo: nil)
+ }
+
+ let checksumString = try String(contentsOf: checksumURL)
+ return checksumString.trimmingCharacters(in: .whitespacesAndNewlines)
+}
+
+let version = "draft"
+let baseURL = "https://github.com/hiddify/hiddify-next-core/releases/download/"
+let packageURL = "\(baseURL)\(version)/hiddify-libcore-ios.xcframework.zip"
+let checksumURL = "\(packageURL).sha256"
+
+do {
+ let package = Package(
+ name: "Libcore",
+ platforms: [
+ .iOS(.v13) // Minimum platform version
+ ],
+ products: [
+ .library(
+ name: "Libcore",
+ targets: ["Libcore"]),
+ ],
+ dependencies: [
+ // No dependencies
+ ],
+ targets: [
+ .binaryTarget(
+ name: "Libcore",
+ url: packageURL,
+ checksum: try fetchChecksum(from: checksumURL)
+ )
+ ]
+ )
+} catch {
+ // Handle URL or checksum fetch errors
+ print("Error: \(error)")
+ // You might want to exit or handle the error in a way suitable for your application
+ // exit(1)
+}