Manual DMG Build #13
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: Set Version from Tag | |
| run: | | |
| VERSION="${{ inputs.tag }}" | |
| VERSION="${VERSION#v}" | |
| npm --prefix frontend version "$VERSION" --no-git-tag-version --allow-same-version | |
| - 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 | |
| # Tag source repo so future releases can diff against it | |
| git tag "$TAG" 2>/dev/null || true | |
| git push origin "$TAG" 2>/dev/null || true | |
| # Generate changelog from source repo commits since last tag | |
| PREV_TAG=$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || echo "") | |
| if [ -n "$PREV_TAG" ]; then | |
| NOTES=$(git log "${PREV_TAG}..${TAG}" --pretty=format:"- %s" --no-merges) | |
| else | |
| NOTES=$(git log "$TAG" --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 | |
| gh release upload "$TAG" \ | |
| --repo "$PUBLIC_REPO" \ | |
| --clobber \ | |
| frontend/dist-electron/*.dmg | |
| - 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 "No changes, skipping commit" | |
| else | |
| git commit -m "release: ${TAG}" | |
| git push | |
| fi |