Skip to content

fix: Unescape shell variables in Cask heredoc #10

fix: Unescape shell variables in Cask heredoc

fix: Unescape shell variables in Cask heredoc #10

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*'
permissions:
contents: write # needed to create releases and upload assets
jobs:
build:
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Show Xcode version
run: |
xcode-select -p
xcodebuild -version
swift --version
- name: List schemes (debug)
run: |
xcodebuild -project NetworkMonitor.xcodeproj -list
- name: Build Release
run: |
xcodebuild \
-project NetworkMonitor.xcodeproj \
-scheme NetworkMonitor \
-configuration Release \
-derivedDataPath "$GITHUB_WORKSPACE/.build" \
CODE_SIGN_IDENTITY="-" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
ONLY_ACTIVE_ARCH=NO \
build
- name: Verify binary
run: |
APP="$GITHUB_WORKSPACE/.build/Build/Products/Release/NetworkMonitor.app"
ls -la "$APP/Contents/MacOS/"
echo "App size: $(du -sh "$APP" | cut -f1)"
- name: Sign ad-hoc
run: |
APP="$GITHUB_WORKSPACE/.build/Build/Products/Release/NetworkMonitor.app"
codesign --force --deep --sign "-" "$APP"
- name: Package
run: |
APP="$GITHUB_WORKSPACE/.build/Build/Products/Release/NetworkMonitor.app"
mkdir -p dist/daemon
cp -R "$APP" dist/
cp install.sh dist/
cp README.md dist/
chmod +x dist/install.sh
zip -r NetworkMonitor-release.zip dist/ -x "*.DS_Store" -x "__MACOSX/*"
echo "Zip size: $(du -sh NetworkMonitor-release.zip | cut -f1)"
unzip -l NetworkMonitor-release.zip
- name: Compute sha256
id: sha
run: |
SHA=$(shasum -a 256 NetworkMonitor-release.zip | awk '{print $1}')
echo "sha256=$SHA" >> "$GITHUB_OUTPUT"
echo "SHA-256: $SHA"
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
name: "Network Monitor ${{ github.ref_name }}"
body: |
## 🌐 Network Monitor ${{ github.ref_name }}
### How to install
**Option 1 — Homebrew (recommended)**
```
brew tap RandomUserUsingGitHub/tap
brew install --cask network-monitor
```
**Option 2 — Manual**
1. Download **NetworkMonitor-release.zip** below ↓
2. Unzip it
3. Drag `NetworkMonitor.app` → `/Applications`
4. Open Terminal and run:
```
bash install.sh
```
> If macOS says "unidentified developer": right-click → **Open** → **Open Anyway** (once only)
### Requirements
macOS 13 or later
### SHA-256
`${{ steps.sha.outputs.sha256 }}`
files: NetworkMonitor-release.zip
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout tap repo
uses: actions/checkout@v4
with:
repository: RandomUserUsingGitHub/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- name: Download release zip for sha256
run: |
VERSION="${GITHUB_REF_NAME#v}"
curl -sL -o release.zip "https://github.com/RandomUserUsingGitHub/NetworkMonitoring/releases/download/${GITHUB_REF_NAME}/NetworkMonitor-release.zip"
SHA=$(sha256sum release.zip | awk '{print $1}')
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "SHA256=$SHA" >> "$GITHUB_ENV"
echo "Version: $VERSION, SHA-256: $SHA"
- name: Update Cask formula
run: |
CASK="homebrew-tap/Casks/network-monitor.rb"
if [ ! -f "$CASK" ]; then
CASK="homebrew-tap/network-monitor.rb"
fi
cat <<EOF > "$CASK"
cask "network-monitor" do
version "${VERSION}"
sha256 "${SHA256}"
url "https://github.com/RandomUserUsingGitHub/NetworkMonitoring/releases/download/v${VERSION}/NetworkMonitor-release.zip"
name "Network Monitor"
desc "Lightweight macOS network monitoring app with live ping graph and IP tracking"
homepage "https://github.com/RandomUserUsingGitHub/NetworkMonitoring"
depends_on macos: ">= :ventura"
app "dist/NetworkMonitor.app"
postflight do
# Write default config if none exists
cfg_dir = File.expand_path("~/.config/network-monitor")
FileUtils.mkdir_p(cfg_dir)
cfg_file = "#{cfg_dir}/settings.json"
unless File.exist?(cfg_file)
File.write(cfg_file, <<~JSON)
{
"ping": { "host": "8.8.8.8", "interval_seconds": 2, "fail_threshold": 3,
"timeout_seconds": 2, "packet_size": 56, "history_size": 60 },
"ip_check": { "interval_seconds": 10 },
"notifications": { "sound": "Basso", "enabled": true, "censor_on_change": false },
"ui": { "theme": "green", "ping_graph_width": 60 },
"log": { "tail_lines": 7 }
}
JSON
end
# Install LaunchAgent
plist_dir = File.expand_path("~/Library/LaunchAgents")
FileUtils.mkdir_p(plist_dir)
plist_path = "#{plist_dir}/com.user.network-monitor.plist"
File.write(plist_path, <<~PLIST)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key> <string>com.user.network-monitor</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/NetworkMonitor.app/Contents/MacOS/NetworkMonitor</string>
<string>--daemon</string>
</array>
<key>RunAtLoad</key> <true/>
<key>KeepAlive</key> <true/>
<key>StandardOutPath</key> <string>/tmp/netmon_stdout.log</string>
<key>StandardErrorPath</key> <string>/tmp/netmon_stderr.log</string>
</dict>
</plist>
PLIST
system_command "/bin/launchctl", args: ["load", plist_path]
end
uninstall launchctl: "com.user.network-monitor",
delete: [
File.expand_path("~/Library/LaunchAgents/com.user.network-monitor.plist"),
File.expand_path("~/.local/bin/netmon-toggle.sh")
]
zap trash: [
"~/.config/network-monitor",
"~/.network_monitor.log",
"/tmp/.netmon_*",
"/tmp/netmon_stdout.log",
"/tmp/netmon_stderr.log",
]
end
EOF
echo "Updated Cask:"
head -5 "$CASK"
- name: Commit and push
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
cd homebrew-tap
git remote set-url origin "https://x-access-token:${TAP_TOKEN}@github.com/RandomUserUsingGitHub/homebrew-tap.git"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Casks/network-monitor.rb
git diff --cached --quiet && echo "No changes" && exit 0
git commit -m "Update network-monitor to ${VERSION}"
git push