Skip to content

Fix printf error with CHANGES variable #31

Fix printf error with CHANGES variable

Fix printf error with CHANGES variable #31

Workflow file for this run

name: Build and Release
on:
push:
branches:
- main
paths:
- 'Sources/SwiftMacPackage/main.swift'
- '.github/workflows/release.yml'
permissions:
contents: write
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
version-changed: ${{ steps.check-tag.outputs.changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from main.swift
id: get-version
run: |
VERSION=$(grep 'let version = ' Sources/SwiftMacPackage/main.swift | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Check if version tag exists
id: check-tag
run: |
VERSION="${{ steps.get-version.outputs.version }}"
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "Tag v$VERSION already exists"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Tag v$VERSION does not exist - will create release"
fi
build-and-release:
needs: check-version
if: needs.check-version.outputs.version-changed == 'true'
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Swift
uses: swift-actions/setup-swift@v2
- name: Build for Apple Silicon (arm64)
run: |
echo "Building for Apple Silicon (arm64)..."
swift build --configuration release --arch arm64
# Verify architecture
echo "Verifying swiftmac binary:"
file .build/release/swiftmac
lipo -info .build/release/swiftmac
- name: Create release archive
run: |
VERSION="${{ needs.check-version.outputs.version }}"
echo "Building swiftmac version $VERSION (Apple Silicon only)"
# Create release directory
mkdir -p swiftmac
# Copy arm64 binary and frameworks
cp .build/release/swiftmac swiftmac/
cp -rf .build/release/ogg.framework swiftmac/
cp -rf .build/release/vorbis.framework swiftmac/
# Copy support files
cp swiftmac-voices.el swiftmac/
cp cloud-swiftmac swiftmac/
cp log-swiftmac swiftmac/
# Copy documentation
cp LICENSE swiftmac/
cp Readme.org swiftmac/
cp Readme.emacspeak.org swiftmac/
# Create tarball
tar -czf swiftmac-$VERSION.tar.gz swiftmac
echo "Release archive created: swiftmac-$VERSION.tar.gz"
ls -lh swiftmac-$VERSION.tar.gz
shell: bash
- name: Generate release notes
run: |
VERSION="${{ needs.check-version.outputs.version }}"
echo "Generating release notes..."
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
CHANGES=$(git log --pretty=format:"- %s" -10)
else
CHANGES=$(git log --pretty=format:"- %s" ${LAST_TAG}..HEAD)
fi
# Create release notes using printf to avoid heredoc YAML issues
{
printf "## SwiftMac %s\n\n" "$VERSION"
printf "**Apple Silicon Release** (arm64)\n\n"
printf "### Requirements\n\n"
printf "- macOS with Apple Silicon (M1, M2, M3, M4, or newer)\n"
printf "- Emacspeak installed\n\n"
printf "### Installation\n\n"
printf "**1. Download and extract:**\n\n"
printf '```bash\n'
printf "curl -L https://github.com/robertmeta/swiftmac/releases/download/v%s/swiftmac-%s.tar.gz | tar xz\n" "$VERSION" "$VERSION"
printf "cd swiftmac\n"
printf '```\n\n'
printf "**2. Install to Emacspeak:**\n\n"
printf '```bash\n'
printf "# Copy binary and frameworks\n"
printf 'cp -rf swiftmac ogg.framework vorbis.framework $EMACSPEAK_DIR/servers/\n\n'
printf "# Copy support scripts\n"
printf 'cp cloud-swiftmac log-swiftmac $EMACSPEAK_DIR/servers/\n\n'
printf "# Copy voice configuration\n"
printf 'cp swiftmac-voices.el $EMACSPEAK_DIR/lisp/\n\n'
printf "# Update .servers file\n"
printf 'cd $EMACSPEAK_DIR/servers\n'
printf 'echo "swiftmac" >> .servers\n'
printf 'echo "log-swiftmac" >> .servers\n'
printf 'echo "cloud-swiftmac" >> .servers\n'
printf 'sort -u .servers -o .servers\n'
printf '```\n\n'
printf "**3. Configure Emacs:**\n\n"
printf "Add to your Emacs init file:\n\n"
printf '```emacs-lisp\n'
printf '(setenv "EMACSPEAK_DIR" "/path/to/.emacspeak") ; Set your path\n'
printf '(load-file "/path/to/.emacspeak/lisp/emacspeak-setup.el")\n'
printf '(dtk-select-server "swiftmac")\n'
printf '```\n\n'
printf "### Changes\n\n"
echo "$CHANGES"
printf "\n\n---\n\n"
printf "For more information, see the [full documentation](https://github.com/robertmeta/swiftmac).\n"
} > RELEASE_NOTES.md
echo "Release notes created"
cat RELEASE_NOTES.md
- name: Create GitHub Release with gh CLI
run: |
VERSION="${{ needs.check-version.outputs.version }}"
echo "Creating release v$VERSION using gh CLI..."
gh release create "v$VERSION" \
"swiftmac-$VERSION.tar.gz" \
--title "SwiftMac $VERSION" \
--notes-file RELEASE_NOTES.md \
--latest
echo "✅ Release created successfully!"
echo "📦 Download: https://github.com/robertmeta/swiftmac/releases/download/v$VERSION/swiftmac-$VERSION.tar.gz"
echo "🔗 View release: https://github.com/robertmeta/swiftmac/releases/tag/v$VERSION"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update latest release symlink
run: |
VERSION="${{ needs.check-version.outputs.version }}"
echo "Released SwiftMac version $VERSION"
echo "Download: https://github.com/robertmeta/swiftmac/releases/download/v$VERSION/swiftmac-$VERSION.tar.gz"