Release #33
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: Release | |
| on: | |
| workflow_run: | |
| workflows: ["Release Please"] | |
| types: [completed] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Release tag (e.g., v0.1.0)' | |
| required: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| detect-release: | |
| name: Detect release | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' | |
| outputs: | |
| tag: ${{ steps.detect.outputs.tag }} | |
| should_build: ${{ steps.detect.outputs.should_build }} | |
| steps: | |
| - name: Detect recent release | |
| id: detect | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT" | |
| echo "should_build=true" >> "$GITHUB_OUTPUT" | |
| echo "Using manual input tag: ${{ inputs.tag }}" | |
| exit 0 | |
| fi | |
| RELEASE="" | |
| for i in $(seq 1 6); do | |
| TEN_MIN_AGO=$(date -u -d '10 minutes ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -u -v-10M '+%Y-%m-%dT%H:%M:%SZ') | |
| RELEASE=$(gh api repos/${{ github.repository }}/releases \ | |
| --jq ".[] | select(.tag_name | startswith(\"v\")) | select(.created_at >= \"${TEN_MIN_AGO}\") | .tag_name" \ | |
| | head -1) | |
| if [ -n "$RELEASE" ]; then | |
| echo "Found release: ${RELEASE} (attempt ${i})" | |
| break | |
| fi | |
| echo "No release found (attempt ${i}/6), retrying in 10s..." | |
| sleep 10 | |
| done | |
| if [ -n "$RELEASE" ]; then | |
| echo "tag=${RELEASE}" >> "$GITHUB_OUTPUT" | |
| echo "should_build=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "should_build=false" >> "$GITHUB_OUTPUT" | |
| echo "No recent release found after 6 attempts" | |
| fi | |
| build: | |
| name: Build ${{ matrix.target }} | |
| needs: detect-release | |
| if: needs.detect-release.outputs.should_build == 'true' | |
| runs-on: macos-latest | |
| strategy: | |
| matrix: | |
| target: | |
| - aarch64-apple-darwin | |
| - x86_64-apple-darwin | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.detect-release.outputs.tag }} | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Build | |
| run: ./scripts/build.sh --target ${{ matrix.target }} release | |
| - name: Package | |
| id: package | |
| run: | | |
| TAG="${{ needs.detect-release.outputs.tag }}" | |
| VERSION="${TAG#v}" | |
| case "${{ matrix.target }}" in | |
| aarch64-apple-darwin) ARCH="arm64" ;; | |
| x86_64-apple-darwin) ARCH="x86_64" ;; | |
| esac | |
| ARCHIVE="ranma-${ARCH}-${VERSION}.tar.gz" | |
| tar czf "${ARCHIVE}" \ | |
| -C target/${{ matrix.target }}/release ranma ranma-server | |
| echo "archive=${ARCHIVE}" >> "$GITHUB_OUTPUT" | |
| - name: Upload release asset | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.detect-release.outputs.tag }} | |
| files: ${{ steps.package.outputs.archive }} | |
| update-homebrew: | |
| name: Update Homebrew formula | |
| needs: [detect-release, build] | |
| runs-on: ubuntu-latest | |
| if: needs.detect-release.outputs.should_build == 'true' | |
| steps: | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| TAG="${{ needs.detect-release.outputs.tag }}" | |
| VERSION="${TAG#v}" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| - name: Download release assets and calculate SHA256 | |
| id: sha256 | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| TAG="${{ needs.detect-release.outputs.tag }}" | |
| curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/ranma-arm64-${VERSION}.tar.gz" -o arm64.tar.gz | |
| ARM64_SHA=$(shasum -a 256 arm64.tar.gz | cut -d ' ' -f 1) | |
| echo "arm64_sha256=${ARM64_SHA}" >> "$GITHUB_OUTPUT" | |
| curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/ranma-x86_64-${VERSION}.tar.gz" -o x86_64.tar.gz | |
| X86_64_SHA=$(shasum -a 256 x86_64.tar.gz | cut -d ' ' -f 1) | |
| echo "x86_64_sha256=${X86_64_SHA}" >> "$GITHUB_OUTPUT" | |
| - name: Dispatch update to homebrew-ranma | |
| env: | |
| GH_TOKEN: ${{ secrets.HOMEBREW_DISPATCH_TOKEN }} | |
| run: | | |
| gh api repos/typester/homebrew-ranma/dispatches \ | |
| -f event_type="update-formula" \ | |
| -f "client_payload[version]=${{ steps.version.outputs.version }}" \ | |
| -f "client_payload[arm64_sha256]=${{ steps.sha256.outputs.arm64_sha256 }}" \ | |
| -f "client_payload[x86_64_sha256]=${{ steps.sha256.outputs.x86_64_sha256 }}" |