diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 574038e..a3d82a1 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -4,16 +4,120 @@ on: push: branches: - main - -permissions: - contents: write - pull-requests: write + workflow_dispatch: + inputs: + tag: + description: "Tag to build and publish (e.g. v0.4.1)" + required: true + type: string jobs: release-please: runs-on: ubuntu-latest + if: github.event_name == 'push' + permissions: + contents: write + pull-requests: write + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} steps: - uses: googleapis/release-please-action@v4 id: release with: token: ${{ secrets.GITHUB_TOKEN }} + + build-release: + needs: [release-please] + runs-on: macos-26 + if: >- + ${{ !cancelled() && + (needs.release-please.outputs.release_created == 'true' || + github.event_name == 'workflow_dispatch') }} + permissions: + contents: write + env: + RELEASE_TAG: ${{ inputs.tag || needs.release-please.outputs.tag_name }} + steps: + - name: Verify release exists + run: gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ env.RELEASE_TAG }} + + - name: Select Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + + - name: Build release binary + run: | + swift build -c release --product mocker + strip .build/release/mocker + + - name: Create tarball + run: | + VERSION="${RELEASE_TAG}" + tar -czf "mocker-${VERSION}-arm64-apple-macosx.tar.gz" \ + -C .build/release mocker + echo "TARBALL=mocker-${VERSION}-arm64-apple-macosx.tar.gz" >> $GITHUB_ENV + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + - name: Compute SHA256 + run: | + SHA256=$(shasum -a 256 "$TARBALL" | awk '{print $1}') + echo "SHA256=${SHA256}" >> $GITHUB_ENV + echo "SHA256: ${SHA256}" + + - name: Upload binary to release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.RELEASE_TAG }} + files: ${{ env.TARBALL }} + + - name: Update Homebrew formula + env: + GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + run: | + FORMULA_URL="https://github.com/${{ github.repository }}/releases/download/${VERSION}/${TARBALL}" + + git clone https://x-access-token:${GH_TOKEN}@github.com/us/homebrew-tap.git /tmp/homebrew-tap + cd /tmp/homebrew-tap + + cat > Formula/mocker.rb << EOF + class Mocker < Formula + desc "Docker-compatible container CLI built on Apple's Containerization framework" + homepage "https://github.com/us/mocker" + url "${FORMULA_URL}" + sha256 "${SHA256}" + license "MIT" + version "${VERSION#v}" + + def install + bin.install "mocker" + end + + def caveats + <<~EOS + Mocker requires Apple's container CLI to be installed: + https://github.com/apple/container + + macOS 26+ and Apple Silicon are required. + EOS + end + + test do + assert_match "${VERSION#v}", shell_output("#{bin}/mocker --version") + end + end + EOF + + git config user.email "rahmetsaritekin@gmail.com" + git config user.name "us" + git add Formula/mocker.rb + git commit -m "chore: update mocker to ${VERSION}" + git push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index ce7d2c3..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: Release - -on: - push: - tags: - - "v*" - workflow_dispatch: - inputs: - tag: - description: "Tag to build and publish (e.g. v0.3.2)" - required: true - type: string - -jobs: - build: - name: Build macOS binary - runs-on: macos-26 - permissions: - contents: write - env: - RELEASE_TAG: ${{ inputs.tag || github.ref_name }} - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ inputs.tag || github.ref_name }} - - - name: Select Xcode - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: latest-stable - - - name: Build release binary - run: | - swift build -c release --product mocker - strip .build/release/mocker - - - name: Create tarball - run: | - VERSION="${RELEASE_TAG}" - tar -czf "mocker-${VERSION}-arm64-apple-macosx.tar.gz" \ - -C .build/release mocker - echo "TARBALL=mocker-${VERSION}-arm64-apple-macosx.tar.gz" >> $GITHUB_ENV - echo "VERSION=${VERSION}" >> $GITHUB_ENV - - - name: Compute SHA256 - run: | - SHA256=$(shasum -a 256 "$TARBALL" | awk '{print $1}') - echo "SHA256=${SHA256}" >> $GITHUB_ENV - echo "SHA256: ${SHA256}" - - - name: Upload binary to release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ inputs.tag || github.ref_name }} - files: ${{ env.TARBALL }} - - - name: Update Homebrew formula - env: - GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} - run: | - FORMULA_URL="https://github.com/${{ github.repository }}/releases/download/${VERSION}/${TARBALL}" - - git clone https://x-access-token:${GH_TOKEN}@github.com/us/homebrew-tap.git /tmp/homebrew-tap - cd /tmp/homebrew-tap - - cat > Formula/mocker.rb << EOF - class Mocker < Formula - desc "Docker-compatible container CLI built on Apple's Containerization framework" - homepage "https://github.com/us/mocker" - url "${FORMULA_URL}" - sha256 "${SHA256}" - license "MIT" - version "${VERSION#v}" - - def install - bin.install "mocker" - end - - def caveats - <<~EOS - Mocker requires Apple's container CLI to be installed: - https://github.com/apple/container - - macOS 26+ and Apple Silicon are required. - EOS - end - - test do - assert_match "${VERSION#v}", shell_output("#{bin}/mocker --version") - end - end - EOF - - git config user.email "rahmetsaritekin@gmail.com" - git config user.name "us" - git add Formula/mocker.rb - git commit -m "chore: update mocker to ${VERSION}" - git push