Skip to content

Commit

Permalink
Make a release workflow for the Swift FFI that:
Browse files Browse the repository at this point in the history
    - builds the existing rust code
    - packages into Xcframework
    - updates the Swift package directory
    - zips and calculates SHA-256 of xcframework
    - updates the Package.swift with the artifact url and checksum
    - commits the changes, pushes them and tags the repo
    - creates a Github Release with notes that have the Diff and checksum

closes #2
closes Electric-Coin-Company#99
  • Loading branch information
pacu committed May 31, 2024
1 parent 0bc99a3 commit 72dcfc1
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 4,468 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Rust

on:
push:
branches: ["main"]
pull_request:
branches-ignore: ["release-*.*.*"]

env:
CARGO_TERM_COLOR: always

jobs:
build:
if: ${{ ! startsWith(github.event.pull_request.head.ref, 'release-') }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cd rust && cargo build --verbose
23 changes: 23 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
paths:
- rust
pull_request:
paths:
- rust
branches-ignore:
- "release-*.*.*"
name: Clippy check

# Make sure CI fails on all warnings, including Clippy lints
env:
RUSTFLAGS: "-Dwarnings"

jobs:
clippy_check:
if: ${{ ! startsWith(github.event.pull_request.head.ref, 'release-') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Clippy
run: cd rust && cargo clippy --all-features
106 changes: 106 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Release

on:
pull_request:
types: [opened, reopened]
branches:
- "main"

jobs:
release:
if: ${{ startsWith(github.event.pull_request.head.ref, 'release-') }}
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}

- uses: actions-rust-lang/setup-rust-toolchain@v1

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: x86_64-apple-darwin aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim

- name: Extract SEMVER from branch name
id: extract_semver
run: echo "SEMVER=$(echo ${{ github.head_ref }} | sed 's/^release-//')" >> $GITHUB_ENV

- name: Make Install
run: make install

- name: Make Xcframework
run: make xcframework

- name: Compute SHA-256 checksum
id: checksum
run: echo "SHA256=$(shasum -a 256 products/libzcashlc.xcframework.zip | cut -d ' ' -f 1)" >> $GITHUB_ENV

- name: Update Swift Package
run: |
RELEASE_URL="https://github.com/${{ github.repository }}/releases/download/${{ env.SEMVER }}/libzcashlc.xcframework.zip"
CHECKSUM="${{ env.SHA256 }}"
sed -i '' -e "s|url: .*|url: \"${RELEASE_URL}\",|g" \
-e "s|checksum: .*|checksum: \"${CHECKSUM}\"|g" Package.swift
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Commit and Push Changes
env:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
git add Package.swift
git commit -m "Update Swift package for release ${{ env.SEMVER }}"
git push
- name: Tag the Release
env:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
TAG_NAME="${{ env.SEMVER }}"
git tag $TAG_NAME
git push https://x-access-token:${PAT_TOKEN}@github.com/${{ github.repository }} $TAG_NAME
- name: Fetch all tags
run: git fetch --tags

- name: Generate Release Notes
id: release_notes
run: |
TAG_NAME="${{ env.SEMVER }}"
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+' | sed -n '2p')
RELEASE_NOTES=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"%h - %s (%an, %ad)" --date=short)
echo "RELEASE_NOTES=${RELEASE_NOTES}" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
tag_name: ${{ env.SEMVER }}
release_name: Release ${{ env.SEMVER }}
body: |
### Changes since last release
${{ env.RELEASE_NOTES }}
### Checksum
```plaintext
${{ env.SHA256 }}
```
draft: false
prerelease: false

- name: Upload XCFramework to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: products/libzcashlc.xcframework.zip
asset_name: libzcashlc.xcframework.zip
asset_content_type: application/zip
25 changes: 25 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Swift Build & Test

on:
push:
branches: ["main"]
paths:
- Package.swift

pull_request:
branches-ignore: ["release-*.*.*"]
paths:
- Package.swift

env:
CARGO_TERM_COLOR: always

jobs:
build_and_test_swift:
if: ${{ ! startsWith(github.event.pull_request.head.ref, 'release-') }}
name: Build Swift Package
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- run: swift build --verbose
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ IOS_DEVICE_ARCHS = aarch64-apple-ios
IOS_SIM_ARCHS_STABLE = x86_64-apple-ios aarch64-apple-ios-sim
MACOS_ARCHS = x86_64-apple-darwin aarch64-apple-darwin
IOS_SIM_ARCHS = $(IOS_SIM_ARCHS_STABLE)

FRAMEWORK_NAME = libzcashlc
RUST_SRCS = $(shell find rust -name "*.rs") Cargo.toml
STATIC_LIBS = $(shell find target -name "libzcashlc.a")

Expand All @@ -29,8 +29,7 @@ clean:
.PHONY: clean

xcframework: products/libzcashlc.xcframework
mkdir -p releases/XCFramework/
rsync -avr --exclude='*.DS_Store' products/libzcashlc.xcframework releases/XCFramework/
zip -r products/$(FRAMEWORK_NAME).xcframework.zip products/$(FRAMEWORK_NAME).xcframework
.PHONY: xcframework

products/libzcashlc.xcframework: $(PLATFORMS)
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "libzcashlc",
path: "releases/XCFramework/libzcashlc.xcframework"
url: "https://github.com/pacu/zcash-light-client-ffi/releases/download/0.0.0/libzcashlc.xcframework.zip",
checksum: "5bc1fac907698f45d5cfce3bbca421f1c3e35ae64401a16fc5b561b7502e6876"
)
]
)
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ Depending on what state the intermediate build products might be in, you may fir

### Swift Package Manager

1. Build the framework as described above.
2. Commit the result.
3. Tag this commit with the new release version, (following semantic versioning).
4. Push the commit and tag to the remote repository.
#### Using CI

**pre-requisites**: you need to be a repo maintainer


1. as a *maintainer* pull the the latest changes from main.
2. branch to a new release. Example: to create release 0.0.1
create a new branch called `release-0.0.1` using `git checkout -b release-0.0.1`
3. update the rust/Cargo.toml file with the new SemVer number matching the
release format. if it's already updated and you will need to generate another
file changte, that's why you can update the VERSION.txt file.
4. push your changes to the remote branch and open a pull request.
5. The `release.yml` workflow should be executed. this will build
the project and create a github release with the version number provided
in the branch name, containing the artifacts and generated release notes
by making a diff of the commits from the latest tag to this one.

#### manually
**pre-requisite:** update the version numbers on rust/Cargo.toml and VERSION.txt with the SemVer version that you will use.
1. tag the commit to the remote repository
2. run `make xcframework`
3. get the xcframework.zip located inside products and get the sha256 using `shasum -a 256 products/libzcashlc.xcframework.zip | cut -d ' ' -f 1`
4. don't commit the binaries to github!!!
5. create a new Github release using the website or the Github CLI
6. make sure to include the `libzcashlc.xcframework.zip` file and the checksum in the release notes

## License

Expand Down
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.8.0
53 changes: 0 additions & 53 deletions releases/XCFramework/libzcashlc.xcframework/Info.plist

This file was deleted.

Loading

0 comments on commit 72dcfc1

Please sign in to comment.