Skip to content

Commit 5b62462

Browse files
ci: add workflow for realease
1 parent 51389b8 commit 5b62462

File tree

3 files changed

+229
-0
lines changed

3 files changed

+229
-0
lines changed

.github/workflows/release.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: "Release Libraries"
2+
3+
env:
4+
RUST_VERSION: "1.73.0"
5+
CROSS_VERSION: "0.2.4"
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: 'Create release with tag'
12+
required: true
13+
type: string
14+
15+
jobs:
16+
build-swift-package:
17+
name: Build Swift Package
18+
runs-on: macos-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Cache cargo resources
25+
uses: Swatinem/rust-cache@v2
26+
with:
27+
shared-key: deps
28+
save-if: false
29+
30+
- name: Build library for macOS
31+
if: "runner.os == 'macOS'"
32+
run: |
33+
cd uniffi
34+
echo "TAG: ${{github.event.inputs.tag}}"
35+
./build-release-apple-universal.sh
36+
cd ..
37+
checksum=$(swift package compute-checksum 'uniffi/output-frameworks/anoncreds-swift/libanoncreds.xcframework.zip')
38+
echo "CHECKSUM: $checksum"
39+
rm -f Package.swift
40+
./.scripts/updatePackage.swift ${{github.event.inputs.tag}} $checksum './.scripts/TemplatePackage.swift' 'Package.swift'
41+
42+
- name: Commit package
43+
uses: stefanzweifel/git-auto-commit-action@v5
44+
with:
45+
commit_message: "chore: prepare release ${{github.event.inputs.tag}}"
46+
tagging_message: ${{github.event.inputs.tag}}
47+
48+
- name: Upload library artifacts
49+
uses: actions/upload-artifact@v3
50+
with:
51+
name: libanoncreds.xcframework.zip
52+
path: 'uniffi/output-frameworks/anoncreds-swift/libanoncreds.xcframework.zip'
53+
54+
- name: Create library artifacts directory
55+
run: |
56+
mkdir release-artifacts
57+
cp 'uniffi/output-frameworks/anoncreds-swift/libanoncreds.xcframework.zip' release-artifacts/
58+
59+
- name: Add swift package artifacts to release
60+
uses: svenstaro/upload-release-action@v2
61+
with:
62+
tag: ${{github.event.inputs.tag}}
63+
file: uniffi/output-frameworks/anoncreds-swift/libanoncreds.xcframework.zip
64+
asset_name: "libanoncreds.xcframework.zip"
65+
66+
build-release:
67+
needs: build-swift-package
68+
name: Build Library
69+
70+
strategy:
71+
matrix:
72+
include:
73+
- architecture: linux-aarch64
74+
os: ubuntu-20.04
75+
target: aarch64-unknown-linux-gnu
76+
lib: libanoncreds_uniffi.so
77+
libPath: uniffi/target/aarch64-unknown-linux-gnu/release/libanoncreds_uniffi.so
78+
use_cross: true
79+
- architecture: linux-x86_64
80+
os: ubuntu-20.04
81+
target: x86_64-unknown-linux-gnu
82+
lib: libanoncreds_uniffi.so
83+
libPath: uniffi/target/x86_64-unknown-linux-gnu/release/libanoncreds_uniffi.so
84+
use_cross: true
85+
- architecture: darwin-x86_64
86+
os: macos-latest
87+
target: x86_64-apple-darwin
88+
lib: libanoncreds_uniffi.dylib
89+
libPath: uniffi/target/x86_64-apple-darwin/release/libanoncreds_uniffi.dylib
90+
- architecture: darwin-aarch64
91+
os: macos-latest
92+
target: aarch64-apple-darwin
93+
lib: libanoncreds_uniffi.dylib
94+
libPath: uniffi/target/aarch64-apple-darwin/release/libanoncreds_uniffi.dylib
95+
96+
runs-on: ${{ matrix.os }}
97+
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@v3
101+
102+
- name: Install Rust toolchain
103+
uses: dtolnay/rust-toolchain@stable
104+
with:
105+
toolchain: ${{ env.RUST_VERSION }}
106+
targets: ${{ matrix.target }}
107+
108+
- name: Cache cargo resources
109+
uses: Swatinem/rust-cache@v2
110+
with:
111+
shared-key: deps
112+
save-if: false
113+
114+
- name: Build library for Linux
115+
if: "runner.os == 'Linux'"
116+
run: |
117+
cd uniffi
118+
if [ -n "${{ matrix.use_cross }}" ]; then
119+
cargo install --git https://github.com/cross-rs/cross --tag v${{ env.CROSS_VERSION }} cross
120+
cross build --release --target ${{matrix.target}}
121+
else
122+
cargo build --release --target ${{matrix.target}}
123+
fi
124+
125+
- name: Build library for macOS
126+
if: "runner.os == 'macOS'"
127+
run: |
128+
cd uniffi
129+
cargo build --release --target ${{matrix.target}}
130+
131+
- name: Upload library artifacts
132+
uses: actions/upload-artifact@v3
133+
with:
134+
name: ${{ matrix.lib }}
135+
path: ${{ matrix.libPath }}
136+
137+
- name: Create library artifacts directory
138+
run: |
139+
mkdir release-artifacts
140+
cp ${{ matrix.libPath }} release-artifacts/
141+
142+
- name: Release artifacts
143+
uses: a7ul/[email protected]
144+
with:
145+
command: c
146+
cwd: release-artifacts
147+
files: .
148+
outPath: "library-${{ matrix.architecture }}.tar.gz"
149+
150+
- name: Add library artifacts to release
151+
uses: svenstaro/upload-release-action@v2
152+
with:
153+
tag: ${{github.event.inputs.tag}}
154+
file: library-${{ matrix.architecture }}.tar.gz
155+
asset_name: "library-${{ matrix.architecture }}-${{ github.sha }}.tar.gz"
156+

.scripts/TemplatePackage.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// swift-tools-version:5.7
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "AnoncredsSwift",
6+
platforms: [
7+
.iOS(.v13),
8+
.macOS(.v12)
9+
],
10+
products: [
11+
.library(
12+
name: "AnoncredsSwift",
13+
type: .dynamic,
14+
targets: ["AnoncredsSwift"]
15+
),
16+
],
17+
targets: [
18+
.target(
19+
name: "AnoncredsSwift",
20+
dependencies: ["anoncredsFFI"],
21+
path: "uniffi/output-frameworks/anoncreds-swift/AnoncredsSwift/Sources/Swift"
22+
),
23+
.target(
24+
name: "anoncredsFFI",
25+
dependencies: ["libanoncreds"],
26+
path: "uniffi/output-frameworks/anoncreds-swift/AnoncredsSwift/Sources/C"),
27+
// LOCAL
28+
// .binaryTarget(
29+
// name: "libanoncreds",
30+
// path: "./uniffi/output-frameworks/anoncreds-swift/libanoncreds.xcframework.zip"
31+
// )
32+
// RELEASE
33+
.binaryTarget(
34+
name: "libanoncreds",
35+
url: "https://github.com/input-output-hk/anoncreds-rs/releases/download/<ref>/libanoncreds.xcframework.zip",
36+
checksum: "<checksum>"
37+
)
38+
]
39+
)

.scripts/updatePackage.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env swift
2+
3+
import Foundation
4+
5+
func main() {
6+
if CommandLine.argc != 5 {
7+
let help = "Invoke the script with `swift updateFiles <ref sub> <checksum sub> <input_file_path> <output_file_path>`"
8+
print("Wrong number of arguments.\n\(help)")
9+
exit(1)
10+
}
11+
12+
let args = CommandLine.arguments
13+
let ref = args[1]
14+
let checksum = args[2]
15+
let inputPath = args[3]
16+
let outputPath = args[4]
17+
18+
do {
19+
// Read the content of the file
20+
let fileContent = try String(contentsOfFile: inputPath, encoding: .utf8)
21+
22+
// Replace <ref> and <checksum> with specified values
23+
let updatedContent = fileContent.replacingOccurrences(of: "<ref>", with: ref)
24+
.replacingOccurrences(of: "<checksum>", with: checksum)
25+
26+
// Write the updated content to the output file
27+
try updatedContent.write(toFile: outputPath, atomically: true, encoding: .utf8)
28+
print("File updated successfully.")
29+
} catch {
30+
print("An error occurred: \(error.localizedDescription)")
31+
}
32+
}
33+
34+
main()

0 commit comments

Comments
 (0)