Skip to content

Commit c40947b

Browse files
authored
ci(swift): add swift publish workflow (#462)
Also requires a build script at `ffi/swift/build.sh` that outputs to `package`. To be added as a follow up. Issue: DEVOPS-4302
1 parent e40aee7 commit c40947b

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Publish Swift package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry-run:
7+
description: 'Dry run'
8+
required: true
9+
type: boolean
10+
default: true
11+
12+
jobs:
13+
preflight:
14+
name: Preflight
15+
runs-on: ubuntu-latest
16+
outputs:
17+
dry-run: ${{ steps.get-dry-run.outputs.dry-run }}
18+
version: ${{ steps.get-version.outputs.version }}
19+
20+
steps:
21+
- name: Checkout ${{ github.repository }}
22+
uses: actions/checkout@v4
23+
24+
- name: Get dry run
25+
id: get-dry-run
26+
run: |
27+
$IsDryRun = '${{ github.event.inputs.dry-run }}' -Eq 'true'
28+
29+
if ($IsDryRun) {
30+
echo "dry-run=true" >> $Env:GITHUB_OUTPUT
31+
} else {
32+
echo "dry-run=false" >> $Env:GITHUB_OUTPUT
33+
}
34+
shell: pwsh
35+
36+
- name: Get version
37+
id: get-version
38+
run: |
39+
VERSION=$(grep -E "^version\s*=" Cargo.toml | head -1 | awk -F'"' '{print $2}')
40+
echo "version=$VERSION" >> $GITHUB_OUTPUT
41+
42+
build-swift:
43+
name: Build Swift package
44+
environment: build-swift
45+
needs: [preflight]
46+
runs-on: macos-latest
47+
48+
steps:
49+
- name: Checkout ${{ github.repository }}
50+
uses: actions/checkout@v4
51+
52+
- name: Setup Rust targets
53+
run: |
54+
rustup target add aarch64-apple-ios
55+
rustup target add x86_64-apple-darwin
56+
rustup target add aarch64-apple-ios-sim
57+
rustup target add aarch64-apple-darwin
58+
59+
- name: Setup code signing
60+
run: |
61+
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
62+
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
63+
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
64+
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
65+
66+
CERTIFICATE_PATH=$RUNNER_TEMP/certificate.p12
67+
echo -n "$CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
68+
security import $CERTIFICATE_PATH -P "$CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
69+
security list-keychain -d user -s $KEYCHAIN_PATH
70+
71+
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
72+
env:
73+
CERTIFICATE_BASE64: ${{ secrets.APPLE_APP_DEV_ID_APP_CERTIFICATE }}
74+
CERTIFICATE_PASSWORD: ${{ secrets.APPLE_APP_DEV_ID_APP_CERTIFICATE_PASSWORD }}
75+
KEYCHAIN_PASSWORD: ${{ secrets.APPLE_APP_DEV_ID_APP_CERTIFICATE_PASSWORD }}
76+
77+
- name: Generate package
78+
run: sh ffi/swift/build.sh
79+
80+
- name: Sign XCFramework
81+
run: |
82+
codesign --timestamp --sign "$SIGNING_IDENTITY" package/libpicky.xcframework
83+
codesign --verify --verbose package/libpicky.xcframework
84+
env:
85+
SIGNING_IDENTITY: "Developer ID Application: Devolutions inc."
86+
87+
- name: Package Swift Package
88+
run: |
89+
VERSION=${{ needs.preflight.outputs.version }}
90+
mv package Picky-$VERSION
91+
zip -r Picky-$VERSION.zip Picky-$VERSION
92+
93+
- name: Upload package
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: swift-zip
97+
path: ./Picky-${{ needs.preflight.outputs.version }}.zip
98+
99+
publish:
100+
name: Publish Swift package
101+
environment: cloudsmith-publish
102+
if: ${{ needs.preflight.outputs.dry-run == 'false' }}
103+
needs: [preflight, build-swift]
104+
runs-on: ubuntu-latest
105+
106+
steps:
107+
- name: Download Swift package artifact
108+
uses: actions/download-artifact@v4
109+
with:
110+
name: swift-zip
111+
path: .
112+
113+
- name: Install Cloudsmith CLI
114+
run: pip install --upgrade cloudsmith-cli
115+
116+
- name: Push package to Cloudsmith
117+
run: cloudsmith push swift devolutions/swift-public Picky-${{ needs.preflight.outputs.version }}.zip --name Picky --version ${{ needs.preflight.outputs.version }} --scope devolutions
118+
env:
119+
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}

0 commit comments

Comments
 (0)