Refactor NSIS script creation in GitHub Actions workflow to use a sin… #10
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: Build and Release Flex | |
on: | |
push: | |
branches: [ main, master ] | |
tags: | |
- 'v*' # Run when tag is pushed (for versioned releases) | |
jobs: | |
build: | |
name: Build Flex for ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
include: | |
- os: ubuntu-latest | |
output_name: flex | |
asset_name: flex-linux | |
- os: windows-latest | |
output_name: flex.exe | |
asset_name: flex-windows | |
- os: macos-latest | |
output_name: flex | |
asset_name: flex-macos | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pyinstaller | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
shell: bash | |
- name: Run tests | |
run: | | |
cd src | |
python -m unittest discover -s flex_tester | |
shell: bash | |
- name: Build executable with PyInstaller | |
run: | | |
cd src | |
pyinstaller --onefile main.py -n flex | |
shell: bash | |
# Windows NSIS Installer | |
- name: Create Windows Installer | |
if: runner.os == 'Windows' | |
run: | | |
choco install nsis -y | |
mkdir -p installer | |
copy src\dist\flex.exe installer\ | |
xcopy src\flex_tester installer\examples\ /E /I | |
copy README.md installer\ | |
# Create a simple NSIS script file | |
( | |
echo !include "MUI2.nsh" | |
echo Name "Flex Programming Language" | |
echo OutFile "flex-windows-installer.exe" | |
echo InstallDir "$PROGRAMFILES\Flex" | |
echo RequestExecutionLevel admin | |
echo !insertmacro MUI_PAGE_WELCOME | |
echo !insertmacro MUI_PAGE_DIRECTORY | |
echo !insertmacro MUI_PAGE_INSTFILES | |
echo !insertmacro MUI_PAGE_FINISH | |
echo !insertmacro MUI_LANGUAGE "English" | |
echo Section | |
echo SetOutPath "$INSTDIR" | |
echo File /r "installer\*.*" | |
echo WriteUninstaller "$INSTDIR\uninstall.exe" | |
echo CreateDirectory "$SMPROGRAMS\Flex" | |
echo CreateShortcut "$SMPROGRAMS\Flex\Flex.lnk" "$INSTDIR\flex.exe" | |
echo CreateShortcut "$SMPROGRAMS\Flex\Uninstall.lnk" "$INSTDIR\uninstall.exe" | |
echo SectionEnd | |
echo Section "Uninstall" | |
echo Delete "$INSTDIR\uninstall.exe" | |
echo RMDir /r "$INSTDIR" | |
echo RMDir /r "$SMPROGRAMS\Flex" | |
echo SectionEnd | |
) > installer.nsi | |
# Compile the installer without PATH manipulation (which requires EnvVarUpdate.nsh) | |
makensis installer.nsi | |
shell: cmd | |
# macOS DMG Package | |
- name: Create macOS DMG | |
if: runner.os == 'macOS' | |
run: | | |
# Create app bundle structure | |
mkdir -p Flex.app/Contents/{MacOS,Resources} | |
cp src/dist/flex Flex.app/Contents/MacOS/ | |
cp -r src/flex_tester Flex.app/Contents/Resources/examples | |
cp README.md Flex.app/Contents/Resources/ | |
# Create Info.plist | |
cat > Flex.app/Contents/Info.plist << EOF | |
<?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>CFBundleExecutable</key> | |
<string>flex</string> | |
<key>CFBundleIconFile</key> | |
<string>flex.icns</string> | |
<key>CFBundleIdentifier</key> | |
<string>org.flex-lang.flex</string> | |
<key>CFBundleName</key> | |
<string>Flex</string> | |
<key>CFBundlePackageType</key> | |
<string>APPL</string> | |
<key>CFBundleVersion</key> | |
<string>1.0</string> | |
<key>NSHighResolutionCapable</key> | |
<true/> | |
</dict> | |
</plist> | |
EOF | |
# Install create-dmg | |
brew install create-dmg | |
# Create DMG | |
create-dmg \ | |
--volname "Flex Installer" \ | |
--volicon "Flex.app/Contents/Resources/flex.icns" \ | |
--window-pos 200 120 \ | |
--window-size 800 400 \ | |
--icon-size 100 \ | |
--icon "Flex.app" 200 190 \ | |
--hide-extension "Flex.app" \ | |
--app-drop-link 600 185 \ | |
"flex-macos.dmg" \ | |
"Flex.app" | |
shell: bash | |
continue-on-error: true # DMG creation might fail if icon is missing | |
# Linux AppImage | |
- name: Create Linux AppImage | |
if: runner.os == 'Linux' | |
run: | | |
# Install required tools | |
sudo apt-get update | |
sudo apt-get install -y wget fuse libfuse2 | |
# Download AppImage tools | |
wget -q https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool | |
chmod +x appimagetool | |
# Create AppDir structure | |
mkdir -p AppDir/usr/{bin,share/applications,share/icons/hicolor/256x256/apps,share/flex/examples} | |
cp src/dist/flex AppDir/usr/bin/ | |
cp -r src/flex_tester/* AppDir/usr/share/flex/examples/ | |
cp README.md AppDir/usr/share/flex/ | |
# Create desktop file | |
cat > AppDir/usr/share/applications/flex.desktop << EOF | |
[Desktop Entry] | |
Name=Flex | |
Comment=Flex Programming Language | |
Exec=flex | |
Icon=flex | |
Type=Application | |
Categories=Development; | |
Terminal=true | |
EOF | |
# Copy desktop file to root (required by AppImage) | |
cp AppDir/usr/share/applications/flex.desktop AppDir/ | |
# Create AppRun script | |
cat > AppDir/AppRun << EOF | |
#!/bin/sh | |
SELF=\$(readlink -f "\$0") | |
HERE=\${SELF%/*} | |
export PATH="\${HERE}/usr/bin:\${PATH}" | |
exec "\${HERE}/usr/bin/flex" "\$@" | |
EOF | |
chmod +x AppDir/AppRun | |
# Create AppImage | |
ARCH=x86_64 ./appimagetool AppDir flex-linux.AppImage | |
shell: bash | |
continue-on-error: true # Some parts might fail if dependencies are missing | |
# Package distribution (Unix) - keep this as backup for Linux | |
- name: Package distribution (Unix) | |
if: runner.os != 'Windows' | |
run: | | |
mkdir -p dist/flex | |
cp src/dist/flex dist/flex/ | |
cp -r src/flex_tester dist/flex/examples | |
cp README.md dist/flex/ | |
tar -czf flex-${{ matrix.asset_name }}.tar.gz -C dist flex | |
shell: bash | |
# Package distribution (Windows) - keep this as backup for Windows | |
- name: Package distribution (Windows) | |
if: runner.os == 'Windows' | |
run: | | |
mkdir -p dist\flex | |
copy src\dist\flex.exe dist\flex\ | |
xcopy src\flex_tester dist\flex\examples\ /E /I | |
copy README.md dist\flex\ | |
powershell Compress-Archive -Path dist\flex -DestinationPath flex-${{ matrix.asset_name }}.zip | |
shell: cmd | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: flex-${{ matrix.asset_name }} | |
path: | | |
flex-${{ matrix.asset_name }}.tar.gz | |
flex-${{ matrix.asset_name }}.zip | |
flex-windows-installer.exe | |
flex-macos.dmg | |
flex-linux.AppImage | |
if-no-files-found: ignore | |
release: | |
name: Create Release | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
- name: List downloaded files | |
run: find . -type f | sort | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: Flex ${{ github.ref_name }} | |
draft: false | |
prerelease: false | |
files: | | |
flex-linux*/*.tar.gz | |
flex-linux*/flex-linux.AppImage | |
flex-windows*/flex-windows-installer.exe | |
flex-windows*/*.zip | |
flex-macos*/flex-macos.dmg | |
flex-macos*/*.tar.gz | |
body: | | |
# Flex Programming Language ${{ github.ref_name }} | |
Cross-platform executable releases of the Flex programming language. | |
## Installation | |
### Windows | |
- Option 1: Download and run `flex-windows-installer.exe` for a full installer with start menu shortcuts | |
- Option 2: Download and extract `flex-windows.zip`, then run `flex.exe` | |
### macOS | |
- Option 1: Download `flex-macos.dmg`, open and drag to Applications folder | |
- Option 2: Download and extract `flex-macos.tar.gz`, then run `flex` | |
### Linux | |
- Option 1: Download `flex-linux.AppImage`, make executable with `chmod +x flex-linux.AppImage` and run | |
- Option 2: Download and extract `flex-linux.tar.gz`, then run `flex` | |
## Examples | |
Example code is included in the examples directory. | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Create a nightly release for testing when pushing to main but not tagging | |
nightly: | |
name: Create Nightly Build | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
- name: List downloaded files | |
run: find . -type f | sort | |
- name: Create or Update Nightly Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: Flex Nightly Build | |
tag_name: nightly | |
draft: false | |
prerelease: true | |
files: | | |
flex-linux*/*.tar.gz | |
flex-linux*/flex-linux.AppImage | |
flex-windows*/flex-windows-installer.exe | |
flex-windows*/*.zip | |
flex-macos*/flex-macos.dmg | |
flex-macos*/*.tar.gz | |
body: | | |
# Flex Programming Language (Nightly Build) | |
Latest development build of the Flex programming language. | |
This build is automatically updated with each push to the main branch. | |
## Download | |
### Windows | |
- Option 1: `flex-windows-installer.exe` (recommended) | |
- Option 2: `flex-windows.zip` | |
### macOS | |
- Option 1: `flex-macos.dmg` (recommended) | |
- Option 2: `flex-macos.tar.gz` | |
### Linux | |
- Option 1: `flex-linux.AppImage` (recommended) | |
- Option 2: `flex-linux.tar.gz` | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |