name: release
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
plan:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.plan.outputs.version }}
tag: ${{ steps.plan.outputs.tag }}
release: ${{ steps.plan.outputs.release }}
crate: ${{ steps.plan.outputs.crate }}
steps:
- uses: actions/checkout@v5
- id: plan
env:
GH_TOKEN: ${{ github.token }}
run: |
name=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -1)
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
tag="v$version"
if [[ "$GITHUB_REF" == refs/tags/* && "$GITHUB_REF_NAME" != "$tag" ]]; then
echo "::error::tag $GITHUB_REF_NAME does not match Cargo.toml's version $version"
exit 1
fi
if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then release=false; else release=true; fi
code=$(curl -s -o /dev/null -w '%{http_code}' -A "$GITHUB_REPOSITORY release workflow" \
"https://crates.io/api/v1/crates/$name/$version")
if [ "$code" = 200 ]; then crate=false; else crate=true; fi
echo "$name $version: GitHub release needed: $release, crates.io needed: $crate"
{
echo "version=$version"
echo "tag=$tag"
echo "release=$release"
echo "crate=$crate"
} >> "$GITHUB_OUTPUT"
macos:
needs: plan
if: needs.plan.outputs.release == 'true' || needs.plan.outputs.crate == 'true'
runs-on: macos-latest
steps:
- uses: actions/checkout@v5
- run: rustup target add aarch64-apple-darwin x86_64-apple-darwin
- run: cargo test --locked
- run: cargo build --release --locked --target aarch64-apple-darwin
- run: cargo build --release --locked --target x86_64-apple-darwin
- name: Package
run: |
mkdir -p dist/iph
lipo -create -output dist/iph/iph \
target/aarch64-apple-darwin/release/iph \
target/x86_64-apple-darwin/release/iph
# The merged file comes out unsigned, and Apple silicon will not run
# unsigned code: sign every slice ad hoc.
codesign --force --sign - dist/iph/iph
codesign --verify --verbose dist/iph/iph
lipo -info dist/iph/iph
dist/iph/iph --version
cp LICENSE LICENSE.idevice LICENSE.jktcp dist/iph/
tar -C dist -czf dist/iph-macos-universal.tar.gz iph
(cd dist && shasum -a 256 iph-macos-universal.tar.gz > iph-macos-universal.tar.gz.sha256)
- uses: actions/upload-artifact@v4
with:
name: macos
path: dist/iph-macos-universal.tar.gz*
windows:
needs: plan
if: needs.plan.outputs.release == 'true'
runs-on: windows-latest
steps:
- uses: actions/checkout@v5
- run: cargo build --release --locked
- name: Package
shell: pwsh
run: |
New-Item -ItemType Directory -Force dist/iph | Out-Null
Copy-Item target/release/iph.exe, LICENSE, LICENSE.idevice, LICENSE.jktcp dist/iph/
dist/iph/iph.exe --version
Compress-Archive -Path dist/iph/* -DestinationPath dist/iph-windows-x86_64.zip
$hash = (Get-FileHash dist/iph-windows-x86_64.zip -Algorithm SHA256).Hash.ToLower()
"$hash iph-windows-x86_64.zip" | Out-File -Encoding ascii -NoNewline dist/iph-windows-x86_64.zip.sha256
- uses: actions/upload-artifact@v4
with:
name: windows
path: dist/iph-windows-x86_64.zip*
release:
needs: [plan, macos, windows]
if: needs.plan.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.plan.outputs.tag }}
run: |
gh release create "$TAG" dist/* \
--repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --title "$TAG" --generate-notes
crate:
needs: [plan, macos]
if: needs.plan.outputs.crate == 'true'
runs-on: macos-latest
environment: crates-io
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v5
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}