Pre-release 1.8.1-pre-release #29
Workflow file for this run
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: Pre-release Build and PR | |
run-name: Pre-release ${{ github.ref_name }} | |
on: | |
push: | |
tags: | |
- '*-pre-release' | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
build-and-release: | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract version from tag | |
id: get_version | |
run: | | |
TAG_NAME=${GITHUB_REF#refs/tags/} | |
VERSION=${TAG_NAME%-pre-release} | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Build Swift FFI | |
run: | | |
chmod +x scripts/build_swift_ffi.sh | |
./scripts/build_swift_ffi.sh | |
- name: Calculate SHA256 | |
id: sha256 | |
run: | | |
CHECKSUM=$(openssl dgst -sha256 loroFFI.xcframework.zip | awk '{print $2}') | |
echo "checksum=$CHECKSUM" >> $GITHUB_OUTPUT | |
- name: Upload XCFramework artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: loroFFI.xcframework.zip | |
path: loroFFI.xcframework.zip | |
- name: Update Package.swift | |
run: | | |
VERSION=${{ steps.get_version.outputs.version }} | |
CHECKSUM=${{ steps.sha256.outputs.checksum }} | |
sed -i '' \ | |
-e "s|url: \"https://github.com/.*/loroFFI.xcframework.zip\"|url: \"https://github.com/${GITHUB_REPOSITORY}/releases/download/${VERSION}/loroFFI.xcframework.zip\"|" \ | |
-e "s|checksum: \"[a-f0-9]*\"|checksum: \"${CHECKSUM}\"|" \ | |
Package.swift | |
- name: Update README.md | |
run: | | |
VERSION=${{ steps.get_version.outputs.version }} | |
sed -i '' \ | |
-e "s|\"https://github.com/loro-dev/loro-swift.git\", from: \"[0-9.]*\"|\"https://github.com/loro-dev/loro-swift.git\", from: \"${VERSION}\"|" \ | |
README.md | |
- name: Commit and push changes to pre-release branch | |
run: | | |
VERSION=${{ steps.get_version.outputs.version }} | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
# Ensure local pre-release branch points to current commit | |
git fetch origin pre-release:pre-release || true | |
git checkout -B pre-release "$GITHUB_SHA" | |
git add Package.swift README.md Sources/* | |
git commit -m "chore: update version to ${VERSION}" || echo "No changes to commit" | |
git push origin pre-release | |
- name: Create or update Pull Request to main | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
VERSION=${{ steps.get_version.outputs.version }} | |
CHECKSUM=${{ steps.sha256.outputs.checksum }} | |
PR_NUMBER=$(gh pr list --base main --head pre-release --state open --json number --jq '.[0].number') | |
if [ -z "$PR_NUMBER" ]; then | |
gh pr create \ | |
--base main \ | |
--head pre-release \ | |
--title "Release ${VERSION}" \ | |
--body "This PR updates Package.swift and README.md to version ${VERSION}.\n\nSHA256 checksum: ${CHECKSUM}.\n\nThe XCFramework artifact has been uploaded to this workflow run." | |
else | |
echo "PR #$PR_NUMBER already exists." | |
fi |