-
Notifications
You must be signed in to change notification settings - Fork 371
114 lines (97 loc) · 3.63 KB
/
release.yml
File metadata and controls
114 lines (97 loc) · 3.63 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
name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
name: Create Release PR or Publish
permissions:
contents: write
pull-requests: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create release pull request or publish
id: changesets
uses: changesets/action@v1
with:
publish: pnpm release
commit: "chore: version packages"
title: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HUSKY: 0
- name: Update Homebrew tap
if: >-
github.ref == 'refs/heads/main' &&
steps.changesets.outputs.published == 'true' &&
contains(steps.changesets.outputs.publishedPackages, '"cloudburn"')
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
VERSION=$(node -p "require('./packages/cloudburn/package.json').version")
TARBALL_URL="https://registry.npmjs.org/cloudburn/-/cloudburn-${VERSION}.tgz"
# Retry up to 5 times to handle npm CDN propagation delay
for i in 1 2 3 4 5; do
SHA256=$(curl -sfSL "$TARBALL_URL" | shasum -a 256 | cut -d ' ' -f 1) && break
SHA256=""
echo "Tarball not yet available, retrying in 15s (attempt $i/5)..."
sleep 15
done
if [ -z "$SHA256" ]; then
echo "::error::Failed to download tarball after 5 attempts"
exit 1
fi
cat > /tmp/cloudburn.rb <<FORMULA
class Cloudburn < Formula
desc "CLI for cloud cost optimization"
homepage "https://cloudburn.io/docs"
url "${TARBALL_URL}"
sha256 "${SHA256}"
license "Apache-2.0"
depends_on "node"
def install
system "npm", "install", *std_npm_args
bin.install_symlink libexec.glob("bin/*")
end
test do
assert_match version.to_s, shell_output("#{bin}/cloudburn --version")
end
end
FORMULA
# Remove leading whitespace from heredoc
sed -i 's/^ //' /tmp/cloudburn.rb
# Push updated formula to the homebrew tap repo
CONTENT=$(base64 -w 0 < /tmp/cloudburn.rb)
EXISTING_SHA=$(curl -sf -H "Authorization: token $HOMEBREW_TAP_TOKEN" \
"https://api.github.com/repos/towardsthecloud/homebrew-tap/contents/Formula/cloudburn.rb" \
| jq -r '.sha // empty') || EXISTING_SHA=""
JSON_PAYLOAD=$(jq -n \
--arg message "chore: update cloudburn to ${VERSION}" \
--arg content "$CONTENT" \
--arg sha "$EXISTING_SHA" \
'if $sha == "" then {message: $message, content: $content} else {message: $message, content: $content, sha: $sha} end')
curl -sfS -X PUT \
-H "Authorization: token $HOMEBREW_TAP_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/towardsthecloud/homebrew-tap/contents/Formula/cloudburn.rb" \
-d "$JSON_PAYLOAD"