Manual DMG Build #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Manual DMG Build | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag (e.g. v0.1.0)" | |
| required: true | |
| type: string | |
| release_name: | |
| description: "Release name (optional)" | |
| required: false | |
| type: string | |
| draft: | |
| description: "Create release as draft" | |
| required: false | |
| type: boolean | |
| default: false | |
| prerelease: | |
| description: "Mark as prerelease" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-dmg: | |
| runs-on: macos-14 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: Build DMG | |
| run: | | |
| chmod +x ./build-electron.sh | |
| ./build-electron.sh | |
| - name: Publish DMG to Public Repo Release | |
| env: | |
| GH_TOKEN: ${{ secrets.PUBLIC_REPO_TOKEN }} | |
| run: | | |
| PUBLIC_REPO="${{ secrets.PUBLIC_RELEASE_REPO }}" | |
| TAG="${{ inputs.tag }}" | |
| RELEASE_NAME="${{ inputs.release_name || inputs.tag }}" | |
| DRAFT="${{ inputs.draft }}" | |
| PRERELEASE="${{ inputs.prerelease }}" | |
| # Build gh release create flags | |
| FLAGS="" | |
| if [ "$DRAFT" = "true" ]; then FLAGS="$FLAGS --draft"; fi | |
| if [ "$PRERELEASE" = "true" ]; then FLAGS="$FLAGS --prerelease"; fi | |
| # Generate changelog from source repo commits since last tag | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -n "$PREV_TAG" ]; then | |
| NOTES=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s" --no-merges) | |
| else | |
| NOTES=$(git log --pretty=format:"- %s" --no-merges -20) | |
| fi | |
| # Create release (or use existing one) | |
| if gh release view "$TAG" --repo "$PUBLIC_REPO" > /dev/null 2>&1; then | |
| echo "Release $TAG already exists, uploading assets..." | |
| else | |
| gh release create "$TAG" \ | |
| --repo "$PUBLIC_REPO" \ | |
| --target main \ | |
| --title "$RELEASE_NAME" \ | |
| --notes "$NOTES" \ | |
| $FLAGS | |
| fi | |
| # Upload DMG files and latest.json | |
| DMG_NAME=$(basename frontend/dist-electron/*.dmg) | |
| echo "{\"version\":\"${TAG}\",\"dmg\":\"${DMG_NAME}\"}" > frontend/dist-electron/latest.json | |
| gh release upload "$TAG" \ | |
| --repo "$PUBLIC_REPO" \ | |
| --clobber \ | |
| frontend/dist-electron/*.dmg \ | |
| frontend/dist-electron/latest.json | |
| - name: Update Public Repo README with Changelog | |
| env: | |
| GH_TOKEN: ${{ secrets.PUBLIC_REPO_TOKEN }} | |
| run: | | |
| PUBLIC_REPO="${{ secrets.PUBLIC_RELEASE_REPO }}" | |
| WORK=$(mktemp -d) | |
| git clone "https://x-access-token:${GH_TOKEN}@github.com/${PUBLIC_REPO}.git" "$WORK" --depth=1 | |
| cd "$WORK" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Build changelog from all releases | |
| { | |
| echo "# SillyAgent Releases" | |
| echo "" | |
| echo "Download the latest version of SillyAgent." | |
| echo "" | |
| echo "[](https://github.com/${PUBLIC_REPO}/releases/latest)" | |
| echo "" | |
| echo "## Changelog" | |
| echo "" | |
| gh release list --repo "$PUBLIC_REPO" --limit 100 --json tagName,publishedAt \ | |
| -q 'sort_by(.publishedAt) | reverse | .[].tagName' \ | |
| | while read -r REL_TAG; do | |
| BODY=$(gh release view "$REL_TAG" --repo "$PUBLIC_REPO" --json body -q '.body' 2>/dev/null) | |
| echo "### ${REL_TAG}" | |
| echo "" | |
| [ -n "$BODY" ] && echo "$BODY" && echo "" | |
| gh release view "$REL_TAG" --repo "$PUBLIC_REPO" --json assets \ | |
| -q '.assets[] | select(.name | endswith(".dmg")) | "- [Download \(.name)](\(.url))"' 2>/dev/null | |
| echo "" | |
| echo "---" | |
| echo "" | |
| done | |
| } > README.md | |
| git add README.md | |
| if git diff --cached --quiet; then | |
| echo "README unchanged, skipping commit" | |
| else | |
| git commit -m "docs: update changelog for ${{ inputs.tag }}" | |
| git push | |
| fi |