|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published, edited] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + include: |
| 15 | + - os: macos-14 |
| 16 | + target: macos-arm64 |
| 17 | + - os: macos-15 |
| 18 | + target: macos-x86_64 |
| 19 | + - os: ubuntu-latest |
| 20 | + target: linux-x86_64 |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + - uses: astral-sh/setup-uv@v4 |
| 25 | + with: |
| 26 | + python-version: "3.12" |
| 27 | + - name: Stamp version from tag |
| 28 | + run: | |
| 29 | + VERSION="${GITHUB_REF_NAME#v}" |
| 30 | + sed -i.bak "s/^version = .*/version = \"$VERSION\"/" pyproject.toml |
| 31 | + sed -i.bak "s/^__version__ = .*/__version__ = \"$VERSION\"/" src/dualentry_cli/__init__.py |
| 32 | + rm -f pyproject.toml.bak src/dualentry_cli/__init__.py.bak |
| 33 | + - run: uv sync --dev |
| 34 | + - run: uv run python scripts/build.py |
| 35 | + - name: Rename binary |
| 36 | + run: mv dist/dualentry dist/dualentry-${{ matrix.target }} |
| 37 | + - uses: actions/upload-artifact@v4 |
| 38 | + with: |
| 39 | + name: dualentry-${{ matrix.target }} |
| 40 | + path: dist/dualentry-${{ matrix.target }} |
| 41 | + |
| 42 | + upload: |
| 43 | + needs: build |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - uses: actions/download-artifact@v4 |
| 47 | + with: |
| 48 | + path: artifacts |
| 49 | + merge-multiple: true |
| 50 | + - name: Upload binaries to release |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ github.token }} |
| 53 | + run: | |
| 54 | + for f in artifacts/*; do |
| 55 | + gh release upload "${{ github.event.release.tag_name }}" "$f" --repo "${{ github.repository }}" |
| 56 | + done |
| 57 | +
|
| 58 | + update-tap: |
| 59 | + needs: upload |
| 60 | + runs-on: ubuntu-latest |
| 61 | + steps: |
| 62 | + - name: Update Homebrew tap |
| 63 | + if: ${{ env.TAP_TOKEN != '' }} |
| 64 | + env: |
| 65 | + TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 66 | + run: | |
| 67 | + VERSION="${GITHUB_REF_NAME#v}" |
| 68 | + BASE_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}" |
| 69 | +
|
| 70 | + SHA_ARM64=$(curl -sL "$BASE_URL/dualentry-macos-arm64" | shasum -a 256 | cut -d' ' -f1) |
| 71 | + SHA_X86_64=$(curl -sL "$BASE_URL/dualentry-macos-x86_64" | shasum -a 256 | cut -d' ' -f1) |
| 72 | + SHA_LINUX=$(curl -sL "$BASE_URL/dualentry-linux-x86_64" | shasum -a 256 | cut -d' ' -f1) |
| 73 | +
|
| 74 | + cat > /tmp/dualentry.rb <<'FORMULA' |
| 75 | + class Dualentry < Formula |
| 76 | + desc "DualEntry accounting CLI" |
| 77 | + homepage "https://github.com/dualentry/dualentry-cli" |
| 78 | + version "VERSION_PLACEHOLDER" |
| 79 | +
|
| 80 | + on_macos do |
| 81 | + if Hardware::CPU.arm? |
| 82 | + url "URL_PLACEHOLDER/dualentry-macos-arm64" |
| 83 | + sha256 "SHA_ARM64_PLACEHOLDER" |
| 84 | + else |
| 85 | + url "URL_PLACEHOLDER/dualentry-macos-x86_64" |
| 86 | + sha256 "SHA_X86_64_PLACEHOLDER" |
| 87 | + end |
| 88 | + end |
| 89 | +
|
| 90 | + on_linux do |
| 91 | + url "URL_PLACEHOLDER/dualentry-linux-x86_64" |
| 92 | + sha256 "SHA_LINUX_PLACEHOLDER" |
| 93 | + end |
| 94 | +
|
| 95 | + def install |
| 96 | + binary = Dir["dualentry-*"].first || "dualentry" |
| 97 | + bin.install binary => "dualentry" |
| 98 | + end |
| 99 | +
|
| 100 | + test do |
| 101 | + assert_match "dualentry-cli", shell_output("#{bin}/dualentry --version") |
| 102 | + end |
| 103 | + end |
| 104 | + FORMULA |
| 105 | +
|
| 106 | + # Substitute placeholders and strip leading whitespace |
| 107 | + sed -i "s|VERSION_PLACEHOLDER|$VERSION|g" /tmp/dualentry.rb |
| 108 | + sed -i "s|URL_PLACEHOLDER|$BASE_URL|g" /tmp/dualentry.rb |
| 109 | + sed -i "s|SHA_ARM64_PLACEHOLDER|$SHA_ARM64|g" /tmp/dualentry.rb |
| 110 | + sed -i "s|SHA_X86_64_PLACEHOLDER|$SHA_X86_64|g" /tmp/dualentry.rb |
| 111 | + sed -i "s|SHA_LINUX_PLACEHOLDER|$SHA_LINUX|g" /tmp/dualentry.rb |
| 112 | + sed -i 's/^ //' /tmp/dualentry.rb |
| 113 | +
|
| 114 | + git clone "https://x-access-token:${TAP_TOKEN}@github.com/dualentry/homebrew-tap.git" /tmp/tap |
| 115 | + mkdir -p /tmp/tap/Formula |
| 116 | + cp /tmp/dualentry.rb /tmp/tap/Formula/dualentry.rb |
| 117 | + cd /tmp/tap |
| 118 | + git config user.name "github-actions[bot]" |
| 119 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 120 | + git add Formula/dualentry.rb |
| 121 | + git commit -m "Update dualentry to $VERSION" |
| 122 | + git push |
0 commit comments