-
Notifications
You must be signed in to change notification settings - Fork 4
143 lines (127 loc) · 5.18 KB
/
Copy pathrelease.yml
File metadata and controls
143 lines (127 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Release
on:
release:
types: [published]
permissions:
contents: write
jobs:
build:
strategy:
matrix:
include:
- os: macos-14
target: macos-arm64
- os: macos-15
target: macos-x86_64
- os: ubuntu-latest
target: linux-x86_64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v4
with:
python-version: "3.12"
- name: Stamp version from tag
run: |
VERSION="${GITHUB_REF_NAME#v}"
sed -i.bak "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
sed -i.bak "s/^__version__ = .*/__version__ = \"$VERSION\"/" src/dualentry_cli/__init__.py
rm -f pyproject.toml.bak src/dualentry_cli/__init__.py.bak
- run: uv sync --dev
- run: uv run python scripts/build.py
- name: Package as tarball
run: tar czf dist/dualentry-${{ matrix.target }}.tar.gz -C dist dualentry/
- uses: actions/upload-artifact@v4
with:
name: dualentry-${{ matrix.target }}
path: dist/dualentry-${{ matrix.target }}.tar.gz
upload:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Upload binaries to release
env:
GH_TOKEN: ${{ github.token }}
run: |
for f in artifacts/*; do
gh release upload "${{ github.event.release.tag_name }}" "$f" --repo "${{ github.repository }}"
done
update-tap:
needs: upload
runs-on: ubuntu-latest
steps:
- name: Update Homebrew tap
if: ${{ env.TAP_TOKEN != '' }}
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
VERSION="${GITHUB_REF_NAME#v}"
BASE_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}"
SHA_ARM64=$(curl -sL "$BASE_URL/dualentry-macos-arm64.tar.gz" | shasum -a 256 | cut -d' ' -f1)
SHA_X86_64=$(curl -sL "$BASE_URL/dualentry-macos-x86_64.tar.gz" | shasum -a 256 | cut -d' ' -f1)
SHA_LINUX=$(curl -sL "$BASE_URL/dualentry-linux-x86_64.tar.gz" | shasum -a 256 | cut -d' ' -f1)
cat > /tmp/dualentry.rb <<'FORMULA'
class Dualentry < Formula
desc "DualEntry accounting CLI"
homepage "https://github.com/dualentry/dualentry-cli"
version "VERSION_PLACEHOLDER"
on_macos do
if Hardware::CPU.arm?
url "URL_PLACEHOLDER/dualentry-macos-arm64.tar.gz"
sha256 "SHA_ARM64_PLACEHOLDER"
else
url "URL_PLACEHOLDER/dualentry-macos-x86_64.tar.gz"
sha256 "SHA_X86_64_PLACEHOLDER"
end
end
on_linux do
url "URL_PLACEHOLDER/dualentry-linux-x86_64.tar.gz"
sha256 "SHA_LINUX_PLACEHOLDER"
end
def install
libexec.install "dualentry"
libexec.install "_internal"
bin.install_symlink libexec/"dualentry"
end
test do
assert_match "dualentry-cli", shell_output("#{bin}/dualentry --version")
end
end
FORMULA
# Substitute placeholders and strip leading whitespace
sed -i "s|VERSION_PLACEHOLDER|$VERSION|g" /tmp/dualentry.rb
sed -i "s|URL_PLACEHOLDER|$BASE_URL|g" /tmp/dualentry.rb
sed -i "s|SHA_ARM64_PLACEHOLDER|$SHA_ARM64|g" /tmp/dualentry.rb
sed -i "s|SHA_X86_64_PLACEHOLDER|$SHA_X86_64|g" /tmp/dualentry.rb
sed -i "s|SHA_LINUX_PLACEHOLDER|$SHA_LINUX|g" /tmp/dualentry.rb
sed -i 's/^ //' /tmp/dualentry.rb
git clone "https://x-access-token:${TAP_TOKEN}@github.com/dualentry/homebrew-tap.git" /tmp/tap
mkdir -p /tmp/tap/Formula
cp /tmp/dualentry.rb /tmp/tap/Formula/dualentry.rb
cd /tmp/tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
BRANCH="update-dualentry-$VERSION"
git checkout -b "$BRANCH"
git add Formula/dualentry.rb
git commit -m "Update dualentry to $VERSION"
git push origin "$BRANCH"
# main is a protected branch on the tap repo (PR required), so push a
# branch and PR it instead of pushing straight to main.
export GH_TOKEN="$TAP_TOKEN"
PR_URL=$(gh pr create --repo dualentry/homebrew-tap \
--title "Update dualentry to $VERSION" \
--body "Automated formula update for dualentry $VERSION." \
--head "$BRANCH" --base main)
echo "Opened $PR_URL"
if gh pr merge --repo dualentry/homebrew-tap "$BRANCH" --squash --delete-branch; then
echo "Merged $PR_URL"
elif gh pr merge --repo dualentry/homebrew-tap "$BRANCH" --auto --squash --delete-branch; then
echo "Enabled auto-merge for $PR_URL"
else
echo "::warning::Could not merge or enable auto-merge for $PR_URL — merge it manually."
fi