Publish Swift Package #32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Swift Package | |
| on: | |
| repository_dispatch: | |
| types: [cdk-release] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'New version (e.g., 0.1.0)' | |
| required: true | |
| type: string | |
| cdk_repo: | |
| description: 'CDK repository (owner/repo format)' | |
| required: true | |
| default: 'cashubtc/cdk' | |
| type: string | |
| cdk_ref: | |
| description: 'CDK repository ref (branch/tag)' | |
| required: true | |
| default: 'main' | |
| type: string | |
| jobs: | |
| build-publish-xcframework: | |
| runs-on: macos-14 | |
| steps: | |
| - name: Set variables | |
| id: vars | |
| run: | | |
| # Handle both repository_dispatch and workflow_dispatch | |
| if [ "${{ github.event_name }}" == "repository_dispatch" ]; then | |
| VERSION="${{ github.event.client_payload.version }}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "cdk_repo=${{ github.event.client_payload.cdk_repo || 'cashubtc/cdk' }}" >> $GITHUB_OUTPUT | |
| echo "cdk_ref=${{ github.event.client_payload.cdk_ref || github.event.client_payload.version }}" >> $GITHUB_OUTPUT | |
| else | |
| VERSION="${{ github.event.inputs.version }}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "cdk_repo=${{ github.event.inputs.cdk_repo }}" >> $GITHUB_OUTPUT | |
| echo "cdk_ref=${{ github.event.inputs.cdk_ref }}" >> $GITHUB_OUTPUT | |
| fi | |
| # Check if version contains 'rc' (case insensitive) to mark as prerelease | |
| if echo "$VERSION" | grep -qi "rc"; then | |
| echo "is_prerelease=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_prerelease=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Checkout cdk-swift | |
| uses: actions/checkout@v4 | |
| with: | |
| path: cdk-swift | |
| - name: Checkout CDK | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ steps.vars.outputs.cdk_repo }} | |
| ref: ${{ steps.vars.outputs.cdk_ref }} | |
| path: cdk | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install protoc | |
| uses: arduino/setup-protoc@v3 | |
| with: | |
| version: "25.x" | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install cargo-lipo | |
| run: cargo install cargo-lipo | |
| - name: Build XCFramework | |
| working-directory: cdk-swift | |
| run: | | |
| # The build script expects to be run from cdk-swift and will cd to ../cdk | |
| bash ./build-xcframework.sh | |
| - name: Zip XCFramework | |
| working-directory: cdk-swift | |
| run: | | |
| zip -r cdkFFI.xcframework.zip cdkFFI.xcframework | |
| echo "XCFRAMEWORK_ZIP=cdkFFI.xcframework.zip" >> $GITHUB_ENV | |
| - name: Compute checksum | |
| working-directory: cdk-swift | |
| run: | | |
| CHECKSUM=$(swift package compute-checksum cdkFFI.xcframework.zip) | |
| echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV | |
| echo "Checksum: $CHECKSUM" | |
| - name: Update Package.swift | |
| working-directory: cdk-swift | |
| run: | | |
| # Update the Package.swift with the new version and checksum | |
| VERSION=${{ steps.vars.outputs.version }} | |
| CHECKSUM=${{ env.CHECKSUM }} | |
| DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/v${VERSION}/cdkFFI.xcframework.zip" | |
| # Read the current Package.swift | |
| PACKAGE_CONTENT=$(cat Package.swift) | |
| # Update the binary target URL and checksum | |
| # This assumes the Package.swift has a binaryTarget with url and checksum | |
| sed -i '' "s|url: \".*cdkFFI.xcframework.zip\"|url: \"${DOWNLOAD_URL}\"|g" Package.swift | |
| sed -i '' "s|checksum: \".*\"|checksum: \"${CHECKSUM}\"|g" Package.swift | |
| echo "Updated Package.swift with:" | |
| echo " URL: ${DOWNLOAD_URL}" | |
| echo " Checksum: ${CHECKSUM}" | |
| - name: Update README with version | |
| working-directory: cdk-swift | |
| run: | | |
| VERSION=${{ steps.vars.outputs.version }} | |
| # Update the version in README.md Swift Package Manager example | |
| sed -i '' "s|from: \"[0-9.]*\"|from: \"${VERSION}\"|g" README.md | |
| echo "Updated README.md with version: ${VERSION}" | |
| - name: Commit changes | |
| working-directory: cdk-swift | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git add . | |
| git commit -m "Update to version ${{ steps.vars.outputs.version }}" | |
| - name: Create tag | |
| working-directory: cdk-swift | |
| run: | | |
| git tag -a "v${{ steps.vars.outputs.version }}" -m "Version ${{ steps.vars.outputs.version }}" | |
| - name: Push changes | |
| working-directory: cdk-swift | |
| run: | | |
| git push origin main | |
| git push origin "v${{ steps.vars.outputs.version }}" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.vars.outputs.version }} | |
| name: Version ${{ steps.vars.outputs.version }} | |
| body: | | |
| ## Changes | |
| - Built with CDK from ${{ steps.vars.outputs.cdk_repo }}@${{ steps.vars.outputs.cdk_ref }} | |
| ## Installation | |
| Add cdk-swift to your Swift Package Manager dependencies: | |
| ```swift | |
| .package(url: "https://github.com/${{ github.repository }}", from: "${{ steps.vars.outputs.version }}") | |
| ``` | |
| files: | | |
| cdk-swift/cdkFFI.xcframework.zip | |
| draft: false | |
| prerelease: ${{ steps.vars.outputs.is_prerelease == 'true' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |