Skip to content

Commit 04408eb

Browse files
committed
fix(workflows): log GITHUB_TOKEN usage in Homebrew update script for better debugging
1 parent 4ccd9b6 commit 04408eb

2 files changed

Lines changed: 68 additions & 77 deletions

File tree

.github/workflows/scripts/update-homebrew.js renamed to .github/workflows/scripts/generate-homebrew.js

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const { join } = require("path");
66
const { createHash } = require("crypto");
77

88
/**
9-
* Update Homebrew formula with new version and checksums
9+
* Generate Homebrew formula with new version and checksums
1010
* @param {string} version - Version string (e.g., "0.1.0")
1111
*/
12-
async function updateHomebrew(version) {
13-
console.log(`🍺 Updating Homebrew formula to v${version}...`);
12+
async function generateHomebrew(version) {
13+
console.log(`🍺 Generating Homebrew formula for v${version}...`);
1414

1515
// Validate version format
1616
if (!/^\d+\.\d+\.\d+$/.test(version)) {
@@ -170,63 +170,20 @@ async function updateHomebrew(version) {
170170

171171
// Write updated formula
172172
writeFileSync(formulaPath, updatedFormula);
173-
console.log("✅ Updated Formula/occtx.rb");
173+
console.log("✅ Generated Formula/occtx.rb");
174174

175175
// Show the updated content
176-
console.log("\n📄 Updated formula content:");
176+
console.log("\n📄 Generated formula content:");
177177
console.log("=" .repeat(50));
178178
console.log(updatedFormula);
179179
console.log("=" .repeat(50));
180180

181-
// Commit and push to homebrew-tap
182-
console.log("\n🚀 Committing and pushing changes...");
183-
try {
184-
// Configure git if needed
185-
try {
186-
execSync('git config user.name', { cwd: homebrewPath, stdio: 'pipe' });
187-
} catch {
188-
execSync('git config user.name "GitHub Actions"', { cwd: homebrewPath });
189-
execSync('git config user.email "actions@github.com"', { cwd: homebrewPath });
190-
}
191-
192-
// Add changes
193-
execSync("git add .", { cwd: homebrewPath });
194-
195-
// Check if there are changes to commit
196-
try {
197-
execSync("git diff --cached --exit-code", { cwd: homebrewPath, stdio: 'pipe' });
198-
console.log("ℹ️ No changes to commit");
199-
return;
200-
} catch {
201-
// There are changes, continue with commit
202-
}
203-
204-
// Commit with detailed message
205-
const commitMessage = `Update occtx to version ${version}
206-
207-
- Version: ${version}
208-
- macOS ARM64: ${checksums['macos-aarch64']}
209-
- macOS x86_64: ${checksums['macos-x86_64']}
210-
- Linux ARM64: ${checksums['linux-aarch64']}
211-
- Linux x86_64: ${checksums['linux-x86_64']}
212-
- Release: https://github.com/hungthai1401/occtx/releases/tag/v${version}
213-
214-
Auto-updated by GitHub Actions`;
215-
216-
execSync(`git commit -m "${commitMessage}"`, { cwd: homebrewPath });
217-
// Push using the token if available (for GitHub Actions)
218-
const token = process.env.GITHUB_TOKEN;
219-
if (token) {
220-
execSync(`git remote set-url origin https://${token}@github.com/hungthai1401/homebrew-tap.git`, { cwd: homebrewPath });
221-
}
222-
execSync("git push origin main", { cwd: homebrewPath });
223-
console.log("✅ Pushed to homebrew-tap repository");
224-
} catch (error) {
225-
console.error("❌ Failed to update homebrew-tap:", error.message);
226-
process.exit(1);
227-
}
181+
// File generation completed - commit/push will be handled by GitHub Actions
182+
console.log("\n✅ Formula file generated successfully!");
183+
console.log("📝 Changes are ready for commit by GitHub Actions");
228184

229-
console.log(`\n🍺 Homebrew formula updated to v${version} successfully! 🎉`);
185+
console.log(`\n🍺 Homebrew formula generated for v${version} successfully! 🎉`);
186+
console.log("📝 GitHub Actions will now commit and push the changes.");
230187

231188
// Summary
232189
console.log("\n📊 Summary:");
@@ -238,7 +195,7 @@ Auto-updated by GitHub Actions`;
238195
}
239196

240197
// Export for use in other scripts
241-
module.exports = { updateHomebrew };
198+
module.exports = { generateHomebrew };
242199

243200
// Allow direct execution
244201
if (require.main === module) {
@@ -247,16 +204,16 @@ if (require.main === module) {
247204
console.error("❌ Version is required!");
248205
console.error("");
249206
console.error("Usage:");
250-
console.error(" node .github/workflows/scripts/update-homebrew.js <version>");
251-
console.error(" OCCTX_VERSION=1.0.0 node .github/workflows/scripts/update-homebrew.js");
207+
console.error(" node .github/workflows/scripts/generate-homebrew.js <version>");
208+
console.error(" OCCTX_VERSION=1.0.0 node .github/workflows/scripts/generate-homebrew.js");
252209
console.error("");
253210
console.error("Examples:");
254-
console.error(" node .github/workflows/scripts/update-homebrew.js 1.0.0");
255-
console.error(" OCCTX_VERSION=1.0.0 node .github/workflows/scripts/update-homebrew.js");
211+
console.error(" node .github/workflows/scripts/generate-homebrew.js 1.0.0");
212+
console.error(" OCCTX_VERSION=1.0.0 node .github/workflows/scripts/generate-homebrew.js");
256213
process.exit(1);
257214
}
258215

259-
updateHomebrew(version).catch((error) => {
216+
generateHomebrew(version).catch((error) => {
260217
console.error("❌ Script failed:", error.message);
261218
process.exit(1);
262219
});

.github/workflows/update-homebrew-tap.yml

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,29 @@ jobs:
4545
with:
4646
node-version: '18'
4747

48-
- name: Update Homebrew formula using Node.js script
48+
- name: Clone Homebrew tap repository
4949
run: |
50-
# Configure git for the script
51-
git config --global user.name "github-actions[bot]"
52-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
53-
5450
# Clone homebrew-tap repository with authentication
55-
git clone https://${{ secrets.GITHUB_TOKEN }}@github.com/hungthai1401/homebrew-tap.git homebrew-tap
51+
git clone https://${{ secrets.PAT }}@github.com/hungthai1401/homebrew-tap.git homebrew-tap
5652
57-
# Run the Node.js update script
58-
echo "🚀 Updating Homebrew formula..."
59-
node .github/workflows/scripts/update-homebrew.js ${{ steps.version.outputs.version }}
53+
- name: Generate Homebrew formula using Node.js script
54+
run: |
55+
# Run the Node.js script to generate the formula file
56+
echo "🚀 Generating Homebrew formula..."
57+
node .github/workflows/scripts/generate-homebrew.js ${{ steps.version.outputs.version }}
6058
env:
6159
OCCTX_VERSION: ${{ steps.version.outputs.version }}
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6360

6461
- name: Verify formula was updated
6562
run: |
6663
echo "🔍 Verifying formula update was successful..."
64+
cd homebrew-tap
6765
68-
if [ -f "homebrew-tap/Formula/occtx.rb" ]; then
66+
if [ -f "Formula/occtx.rb" ]; then
6967
echo "✅ Formula file exists"
7068
7169
# Check if version was updated
72-
if grep -q "version \"${{ steps.version.outputs.version }}\"" homebrew-tap/Formula/occtx.rb; then
70+
if grep -q "version \"${{ steps.version.outputs.version }}\"" Formula/occtx.rb; then
7371
echo "✅ Version updated successfully"
7472
else
7573
echo "❌ Version was not updated"
@@ -79,12 +77,12 @@ jobs:
7977
# Basic syntax check if Ruby is available
8078
if command -v ruby >/dev/null 2>&1; then
8179
echo "🔍 Running Ruby syntax check..."
82-
if ruby -c homebrew-tap/Formula/occtx.rb 2>/dev/null; then
80+
if ruby -c Formula/occtx.rb 2>/dev/null; then
8381
echo "✅ Ruby syntax check passed"
8482
else
8583
echo "❌ Ruby syntax check failed"
8684
echo "📄 Formula content for debugging:"
87-
cat homebrew-tap/Formula/occtx.rb
85+
cat Formula/occtx.rb
8886
exit 1
8987
fi
9088
else
@@ -93,21 +91,21 @@ jobs:
9391
echo "🔍 Basic file validation..."
9492
9593
# Basic validation without Ruby
96-
if grep -q "class Occtx < Formula" homebrew-tap/Formula/occtx.rb; then
94+
if grep -q "class Occtx < Formula" Formula/occtx.rb; then
9795
echo "✅ Formula class definition found"
9896
else
9997
echo "❌ Formula class definition not found"
10098
exit 1
10199
fi
102100
103-
if grep -q "def install" homebrew-tap/Formula/occtx.rb; then
101+
if grep -q "def install" Formula/occtx.rb; then
104102
echo "✅ Install method found"
105103
else
106104
echo "❌ Install method not found"
107105
exit 1
108106
fi
109107
110-
if grep -q "sha256" homebrew-tap/Formula/occtx.rb; then
108+
if grep -q "sha256" Formula/occtx.rb; then
111109
echo "✅ SHA256 hashes found"
112110
else
113111
echo "❌ SHA256 hashes not found"
@@ -118,8 +116,44 @@ jobs:
118116
fi
119117
120118
echo "📄 Final formula content:"
121-
cat homebrew-tap/Formula/occtx.rb
119+
cat Formula/occtx.rb
122120
else
123121
echo "❌ Formula file not found"
124122
exit 1
125123
fi
124+
125+
- name: Commit and push changes to Homebrew tap
126+
run: |
127+
cd homebrew-tap
128+
129+
# Set the remote URL with the token
130+
git remote set-url origin https://x-access-token:${{ secrets.PAT }}@github.com/hungthai1401/homebrew-tap.git
131+
132+
# Configure git
133+
git config user.name "github-actions[bot]"
134+
git config user.email "github-actions[bot]@users.noreply.github.com"
135+
136+
# Check if there are changes to commit
137+
if git diff --quiet; then
138+
echo "ℹ️ No changes to commit"
139+
exit 0
140+
fi
141+
142+
# Add changes
143+
git add .
144+
145+
# Create commit message with version details
146+
cat > commit_message.txt << EOF
147+
Update occtx to version ${{ steps.version.outputs.version }}
148+
149+
- Version: ${{ steps.version.outputs.version }}
150+
- Release: https://github.com/hungthai1401/occtx/releases/tag/v${{ steps.version.outputs.version }}
151+
152+
Auto-updated by GitHub Actions
153+
EOF
154+
155+
# Commit and push
156+
git commit -F commit_message.txt
157+
git push origin main
158+
159+
echo "✅ Successfully pushed changes to homebrew-tap repository"

0 commit comments

Comments
 (0)