1+ name : Build and Release
2+ on :
3+ push :
4+ tags :
5+ - ' v*'
6+ permissions :
7+ contents : write
8+ jobs :
9+ build-and-release :
10+ name : Build and Release
11+ runs-on : ${{ matrix.os }}
12+ strategy :
13+ matrix :
14+ include :
15+ # macOS builds
16+ - os : macos-latest
17+ TARGET : macos-amd64
18+ CMD_BUILD : >
19+ PYTHONOPTIMIZE=1 pyinstaller cloud-cli.spec &&
20+ cd dist/ &&
21+ tar czf ../cloud-cli-darwin-amd64.tar.gz cloud-cli
22+ OUT_FILE_NAME : cloud-cli-darwin-amd64.tar.gz
23+ - os : macos-14
24+ TARGET : macos-arm64
25+ CMD_BUILD : >
26+ PYTHONOPTIMIZE=1 pyinstaller cloud-cli.spec &&
27+ cd dist/ &&
28+ tar czf ../cloud-cli-darwin-arm64.tar.gz cloud-cli
29+ OUT_FILE_NAME : cloud-cli-darwin-arm64.tar.gz
30+
31+ # Linux builds
32+ - os : ubuntu-latest
33+ TARGET : linux-amd64
34+ CMD_BUILD : >
35+ PYTHONOPTIMIZE=1 pyinstaller cloud-cli.spec &&
36+ cd dist/ &&
37+ tar czf ../cloud-cli-linux-amd64.tar.gz cloud-cli
38+ OUT_FILE_NAME : cloud-cli-linux-amd64.tar.gz
39+ - os : ubuntu-latest
40+ TARGET : linux-arm64
41+ CMD_BUILD : >
42+ PYTHONOPTIMIZE=1 pyinstaller cloud-cli.spec &&
43+ cd dist/ &&
44+ tar czf ../cloud-cli-linux-arm64.tar.gz cloud-cli
45+ OUT_FILE_NAME : cloud-cli-linux-arm64.tar.gz
46+
47+ # Windows builds
48+ - os : windows-latest
49+ TARGET : windows-amd64
50+ CMD_BUILD : >
51+ set PYTHONOPTIMIZE=1 &&
52+ pyinstaller cloud-cli.spec &&
53+ cd dist &&
54+ tar -a -c -f ../cloud-cli-windows-amd64.zip cloud-cli
55+ OUT_FILE_NAME : cloud-cli-windows-amd64.zip
56+ - os : windows-latest
57+ TARGET : windows-arm64
58+ CMD_BUILD : >
59+ set PYTHONOPTIMIZE=1 &&
60+ pyinstaller cloud-cli.spec &&
61+ cd dist &&
62+ tar -a -c -f ../cloud-cli-windows-arm64.zip cloud-cli
63+ OUT_FILE_NAME : cloud-cli-windows-arm64.zip
64+
65+ steps :
66+ - uses : actions/checkout@v4
67+ - name : Set up Python
68+ uses : actions/setup-python@v5
69+ with :
70+ python-version : ' 3.13'
71+ - name : Install dependencies
72+ run : |
73+ python -m pip install --upgrade pip
74+ pip install -r requirements.txt
75+ pip install pyinstaller
76+ - name : Build binary
77+ run : ${{ matrix.CMD_BUILD }}
78+ - name : Generate SHA256
79+ run : |
80+ if [ "${{ runner.os }}" = "macOS" ]; then
81+ shasum -a 256 ${{ matrix.OUT_FILE_NAME }} > ${{ matrix.OUT_FILE_NAME }}.sha256
82+ else
83+ sha256sum ${{ matrix.OUT_FILE_NAME }} > ${{ matrix.OUT_FILE_NAME }}.sha256
84+ fi
85+ - name : Upload artifacts
86+ uses : actions/upload-artifact@v3
87+ with :
88+ name : ${{ matrix.TARGET }}
89+ path : |
90+ ${{ matrix.OUT_FILE_NAME }}
91+ ${{ matrix.OUT_FILE_NAME }}.sha256
92+
93+ create-release :
94+ name : Create Release
95+ needs : build-and-release
96+ runs-on : ubuntu-latest
97+ permissions :
98+ contents : write
99+ steps :
100+ - name : Download artifacts
101+ uses : actions/download-artifact@v3
102+ - name : Create Release
103+ id : create_release
104+ uses : softprops/action-gh-release@v1
105+ with :
106+ files : |
107+ */cloud-cli-*.tar.gz
108+ */cloud-cli-*.zip
109+ */cloud-cli-*.sha256
110+ generate_release_notes : true
111+
112+ update-brew :
113+ name : Update Brew Formula
114+ needs : create-release
115+ runs-on : ubuntu-latest
116+ steps :
117+ - name : Checkout brew tap repo
118+ uses : actions/checkout@v4
119+ with :
120+ repository : o37-autoforge/homebrew-cloudscript
121+ token : ${{ secrets.BREW_TAP_TOKEN }}
122+ - name : Debug environment
123+ run : |
124+ echo "GitHub ref: $GITHUB_REF"
125+ echo "GitHub repository: ${{ github.repository }}"
126+ echo "Current directory contents:"
127+ ls -la
128+ - name : Download release artifacts and update formula
129+ run : |
130+ # Get version from tag
131+ VERSION=${GITHUB_REF#refs/tags/v}
132+ echo "Processing version: $VERSION"
133+
134+ # Get the release information including assets
135+ REPO_PATH="${{ github.repository }}"
136+ echo "Repository path: $REPO_PATH"
137+
138+ RELEASE_INFO=$(curl -s -H "Authorization: token ${{ secrets.BREW_TAP_TOKEN }}" \
139+ "https://api.github.com/repos/${REPO_PATH}/releases/tags/v${VERSION}")
140+
141+ echo "Got release info for v${VERSION}"
142+
143+ # Extract assets URL
144+ ASSETS_URL=$(echo "$RELEASE_INFO" | jq -r '.assets_url')
145+ echo "Assets URL: $ASSETS_URL"
146+
147+ # Function to get SHA from asset
148+ get_sha() {
149+ local pattern=$1
150+ local sha=$(curl -sL -H "Authorization: token ${{ secrets.BREW_TAP_TOKEN }}" \
151+ "$ASSETS_URL" | \
152+ jq -r ".[] | select(.name | test(\"$pattern\")) | .browser_download_url" | \
153+ xargs curl -sL | cut -d' ' -f1)
154+ echo "$sha"
155+ }
156+
157+ # Get SHA256 values
158+ ARM64_SHA256=$(get_sha "darwin-arm64.tar.gz.sha256$")
159+ echo "ARM64 SHA256: $ARM64_SHA256"
160+
161+ AMD64_SHA256=$(get_sha "darwin-amd64.tar.gz.sha256$")
162+ echo "AMD64 SHA256: $AMD64_SHA256"
163+
164+ LINUX_SHA256=$(get_sha "linux-amd64.tar.gz.sha256$")
165+ echo "LINUX SHA256: $LINUX_SHA256"
166+
167+ # Verify we got all SHAs
168+ if [ -z "$ARM64_SHA256" ] || [ -z "$AMD64_SHA256" ] || [ -z "$LINUX_SHA256" ]; then
169+ echo "Error: Failed to get one or more SHA256 values"
170+ echo "Release info:"
171+ echo "$RELEASE_INFO" | jq '.'
172+ exit 1
173+ fi
174+
175+ echo "Formula file before changes:"
176+ cat Formula/cloudscript.rb
177+
178+ # Update formula file with more precise sed patterns
179+ sed -i "s/version \".*\"/version \"$VERSION\"/" Formula/cloudscript.rb
180+ sed -i "s|v[0-9.]*\/cloud-cli|v$VERSION\/cloud-cli|g" Formula/cloudscript.rb
181+
182+ # More specific SHA256 replacements
183+ sed -i "/if Hardware::CPU.arm?/,/else/s/sha256 \".*\"/sha256 \"$ARM64_SHA256\"/" Formula/cloudscript.rb
184+ sed -i "/else/,/end/s/sha256 \".*\"/sha256 \"$AMD64_SHA256\"/" Formula/cloudscript.rb
185+ sed -i "/on_linux/,/end/s/sha256 \".*\"/sha256 \"$LINUX_SHA256\"/" Formula/cloudscript.rb
186+
187+ echo "Formula file after changes:"
188+ cat Formula/cloudscript.rb
189+ - name : Commit and push changes
190+ run : |
191+ git config --global user.name 'GitHub Action'
192+ git config --global user.email 'action@github.com'
193+ git add Formula/cloudscript.rb
194+ git commit -m "Update formula to version ${GITHUB_REF#refs/tags/}"
195+ git push
196+
197+ copy-to-repo :
198+ name : Copy Binaries to Target Repository
199+ needs : create-release
200+ runs-on : ubuntu-latest
201+ steps :
202+ - name : Download all artifacts
203+ uses : actions/download-artifact@v3
204+ with :
205+ path : ./binaries
206+
207+ - name : Checkout target repository
208+ uses : actions/checkout@v4
209+ with :
210+ repository : o37-autoforge/web-cloudscript
211+ token : ${{ secrets.TARGET_REPO_TOKEN }}
212+ path : target-repo
213+
214+ - name : Copy binaries
215+ run : |
216+ mkdir -p target-repo/binaries
217+ cp -r binaries/*/*.tar.gz target-repo/binaries/ || true
218+ cp -r binaries/*/*.zip target-repo/binaries/ || true
219+ cp -r binaries/*/*.sha256 target-repo/binaries/ || true
220+
221+ - name : Commit and push changes
222+ run : |
223+ cd target-repo
224+ git config --global user.name 'GitHub Action'
225+ git config --global user.email 'action@github.com'
226+ git add binaries/
227+ git commit -m "Update binaries"
228+ git push
0 commit comments