|
8 | 8 | env: |
9 | 9 | CARGO_TERM_COLOR: always |
10 | 10 | BINARY_NAME: shipit |
| 11 | + REPO: trollefson/shipit |
| 12 | + TAP_REPO: trollefson/homebrew-shipit |
11 | 13 |
|
12 | 14 | jobs: |
13 | 15 | build: |
@@ -102,3 +104,152 @@ jobs: |
102 | 104 | generate_release_notes: true |
103 | 105 | env: |
104 | 106 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + |
| 108 | + extras: |
| 109 | + name: Installer & Homebrew formula |
| 110 | + needs: build |
| 111 | + runs-on: ubuntu-latest |
| 112 | + permissions: |
| 113 | + contents: write |
| 114 | + |
| 115 | + steps: |
| 116 | + - name: Download release binaries and compute SHA256s |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + run: | |
| 120 | + TAG="${{ github.ref_name }}" |
| 121 | + VERSION="${TAG#v}" |
| 122 | + mkdir -p /tmp/artifacts |
| 123 | +
|
| 124 | + gh release download "$TAG" \ |
| 125 | + --repo ${{ env.REPO }} \ |
| 126 | + --dir /tmp/artifacts \ |
| 127 | + --pattern "shipit-x86_64-unknown-linux-gnu" \ |
| 128 | + --pattern "shipit-x86_64-apple-darwin" \ |
| 129 | + --pattern "shipit-aarch64-apple-darwin" |
| 130 | +
|
| 131 | + SHA_LINUX=$(sha256sum /tmp/artifacts/shipit-x86_64-unknown-linux-gnu | awk '{print $1}') |
| 132 | + SHA_MACOS_X86=$(sha256sum /tmp/artifacts/shipit-x86_64-apple-darwin | awk '{print $1}') |
| 133 | + SHA_MACOS_ARM=$(sha256sum /tmp/artifacts/shipit-aarch64-apple-darwin | awk '{print $1}') |
| 134 | +
|
| 135 | + echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 136 | + echo "TAG=$TAG" >> "$GITHUB_ENV" |
| 137 | + echo "SHA_LINUX=$SHA_LINUX" >> "$GITHUB_ENV" |
| 138 | + echo "SHA_MACOS_X86=$SHA_MACOS_X86" >> "$GITHUB_ENV" |
| 139 | + echo "SHA_MACOS_ARM=$SHA_MACOS_ARM" >> "$GITHUB_ENV" |
| 140 | +
|
| 141 | + - name: Generate install.sh |
| 142 | + run: | |
| 143 | + cat > install.sh << 'INSTALL_EOF' |
| 144 | + #!/bin/sh |
| 145 | + # shipit installer — https://github.com/trollefson/shipit |
| 146 | + set -e |
| 147 | +
|
| 148 | + REPO="trollefson/shipit" |
| 149 | + BINARY="shipit" |
| 150 | + INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" |
| 151 | +
|
| 152 | + OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 153 | + ARCH=$(uname -m) |
| 154 | +
|
| 155 | + case "$OS" in |
| 156 | + linux) |
| 157 | + case "$ARCH" in |
| 158 | + x86_64) ARTIFACT="shipit-x86_64-unknown-linux-gnu" ;; |
| 159 | + *) echo "Unsupported arch: $ARCH" >&2; exit 1 ;; |
| 160 | + esac ;; |
| 161 | + darwin) |
| 162 | + case "$ARCH" in |
| 163 | + x86_64) ARTIFACT="shipit-x86_64-apple-darwin" ;; |
| 164 | + arm64) ARTIFACT="shipit-aarch64-apple-darwin" ;; |
| 165 | + *) echo "Unsupported arch: $ARCH" >&2; exit 1 ;; |
| 166 | + esac ;; |
| 167 | + *) |
| 168 | + echo "Unsupported OS: $OS" >&2; exit 1 ;; |
| 169 | + esac |
| 170 | +
|
| 171 | + LATEST=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \ |
| 172 | + | grep '"tag_name"' | head -1 \ |
| 173 | + | sed 's/.*"tag_name": *"\(.*\)".*/\1/') |
| 174 | +
|
| 175 | + URL="https://github.com/${REPO}/releases/download/${LATEST}/${ARTIFACT}" |
| 176 | + echo "Downloading shipit ${LATEST} (${ARTIFACT})..." |
| 177 | +
|
| 178 | + TMP=$(mktemp) |
| 179 | + trap 'rm -f "$TMP"' EXIT |
| 180 | +
|
| 181 | + curl -fsSL "$URL" -o "$TMP" |
| 182 | + chmod +x "$TMP" |
| 183 | +
|
| 184 | + if [ -w "$INSTALL_DIR" ]; then |
| 185 | + mv "$TMP" "${INSTALL_DIR}/${BINARY}" |
| 186 | + else |
| 187 | + sudo mv "$TMP" "${INSTALL_DIR}/${BINARY}" |
| 188 | + fi |
| 189 | +
|
| 190 | + echo "shipit installed to ${INSTALL_DIR}/${BINARY}" |
| 191 | + INSTALL_EOF |
| 192 | + chmod +x install.sh |
| 193 | +
|
| 194 | + - name: Upload install.sh to release |
| 195 | + env: |
| 196 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 197 | + run: | |
| 198 | + gh release upload "${{ env.TAG }}" install.sh \ |
| 199 | + --repo ${{ env.REPO }} \ |
| 200 | + --clobber |
| 201 | +
|
| 202 | + - name: Generate Homebrew formula |
| 203 | + run: | |
| 204 | + mkdir -p Formula |
| 205 | + cat > Formula/shipit.rb << EOF |
| 206 | + class Shipit < Formula |
| 207 | + desc "A CLI for managing git releases" |
| 208 | + homepage "https://github.com/${{ env.REPO }}" |
| 209 | + version "${{ env.VERSION }}" |
| 210 | + license "MIT" |
| 211 | +
|
| 212 | + on_macos do |
| 213 | + on_arm do |
| 214 | + url "https://github.com/${{ env.REPO }}/releases/download/v${{ env.VERSION }}/shipit-aarch64-apple-darwin" |
| 215 | + sha256 "${{ env.SHA_MACOS_ARM }}" |
| 216 | + end |
| 217 | + on_intel do |
| 218 | + url "https://github.com/${{ env.REPO }}/releases/download/v${{ env.VERSION }}/shipit-x86_64-apple-darwin" |
| 219 | + sha256 "${{ env.SHA_MACOS_X86 }}" |
| 220 | + end |
| 221 | + end |
| 222 | +
|
| 223 | + on_linux do |
| 224 | + on_intel do |
| 225 | + url "https://github.com/${{ env.REPO }}/releases/download/v${{ env.VERSION }}/shipit-x86_64-unknown-linux-gnu" |
| 226 | + sha256 "${{ env.SHA_LINUX }}" |
| 227 | + end |
| 228 | + end |
| 229 | +
|
| 230 | + def install |
| 231 | + bin.install Dir["shipit*"].first => "shipit" |
| 232 | + end |
| 233 | +
|
| 234 | + test do |
| 235 | + system bin/"shipit", "--version" |
| 236 | + end |
| 237 | + end |
| 238 | + EOF |
| 239 | +
|
| 240 | + - name: Push formula to Homebrew tap |
| 241 | + env: |
| 242 | + TAP_TOKEN: ${{ secrets.TAP_TOKEN }} |
| 243 | + run: | |
| 244 | + git config --global user.name "github-actions[bot]" |
| 245 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 246 | +
|
| 247 | + git clone "https://x-access-token:${TAP_TOKEN}@github.com/${{ env.TAP_REPO }}.git" tap |
| 248 | + mkdir -p tap/Formula |
| 249 | + cp Formula/shipit.rb tap/Formula/shipit.rb |
| 250 | +
|
| 251 | + cd tap |
| 252 | + git add Formula/shipit.rb |
| 253 | + git diff --cached --quiet || \ |
| 254 | + git commit -m "shipit ${{ env.VERSION }}" |
| 255 | + git push |
0 commit comments