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 Flex Executables | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
build: | |
name: Build Flex Executable (${{ 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-linux | |
asset_name: flex-linux | |
- os: windows-latest | |
output_name: flex-windows | |
asset_name: flex-windows.exe | |
- os: macos-latest | |
output_name: flex-macos | |
asset_name: flex-macos | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pyinstaller | |
pip install ply==3.11 | |
- name: Build with PyInstaller for Linux/macOS | |
if: matrix.os != 'windows-latest' | |
run: | | |
cd src | |
pyinstaller --onefile --clean --name=${{ matrix.output_name }} \ | |
--add-data "flex_compiler:flex_compiler" \ | |
--add-data "flex_interpreter:flex_interpreter" \ | |
--add-data "flex_parser:flex_parser" \ | |
--add-data "flex_tokenizer:flex_tokenizer" \ | |
main.py | |
- name: Build with PyInstaller for Windows | |
if: matrix.os == 'windows-latest' | |
shell: cmd | |
run: | | |
cd src | |
pyinstaller --onefile --clean --name=${{ matrix.output_name }} ^ | |
--add-data "flex_compiler;flex_compiler" ^ | |
--add-data "flex_interpreter;flex_interpreter" ^ | |
--add-data "flex_parser;flex_parser" ^ | |
--add-data "flex_tokenizer;flex_tokenizer" ^ | |
main.py | |
- name: Set Executable Permissions (Linux/macOS) | |
if: matrix.os != 'windows-latest' | |
run: | | |
cd src/dist | |
chmod +x ${{ matrix.output_name }} | |
ls -la ${{ matrix.output_name }} | |
- name: Test Executable (Linux/macOS) | |
if: matrix.os != 'windows-latest' | |
run: | | |
cd src/dist | |
./${{ matrix.output_name }} --version | |
- name: Test Executable (Windows) | |
if: matrix.os == 'windows-latest' | |
run: | | |
cd src\dist | |
.\${{ matrix.output_name }}.exe --version | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.asset_name }} | |
path: src/dist/${{ matrix.output_name }}* | |
retention-days: 7 | |
release: | |
name: Create Release | |
needs: [build] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Download All Artifacts | |
uses: actions/download-artifact@v4 | |
- name: Display structure of downloaded files | |
run: ls -R | |
- name: Set Permissions for Downloaded Artifacts | |
run: | | |
chmod +x ./flex-linux/flex-linux || true | |
chmod +x ./flex-macos/flex-macos || true | |
ls -la ./flex-linux/flex-linux ./flex-macos/flex-macos || true | |
- name: Prepare release artifacts | |
run: | | |
mkdir -p release | |
# Debug the file structure | |
echo "Directory structure after downloading:" | |
find . -type f -name "flex-*" | sort | |
# Copy with platform-specific names for clarity | |
cp ./flex-linux/flex-linux release/flex-linux || true | |
cp ./flex-windows.exe/flex-windows.exe release/flex-windows.exe || true | |
cp ./flex-macos/flex-macos release/flex-macos || true | |
# Make sure executables have correct permissions | |
chmod +x release/* || true | |
echo "Release directory contents:" | |
ls -la release/ | |
- name: Checkout repository for tag information | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
path: repo | |
- name: Get next version number | |
id: calc_version | |
working-directory: repo | |
run: | | |
# Check if there are any existing tags that match vX format | |
if git tag -l "v[0-9]*" | grep -q .; then | |
# Get highest version number from existing tags | |
latest_version=$(git tag -l "v[0-9]*" | sort -V | tail -n1 | sed 's/v//') | |
next_version=$((latest_version + 1)) | |
else | |
# No existing version tags, start at 1 | |
next_version=1 | |
fi | |
echo "Next version will be: v$next_version" | |
echo "next_version=$next_version" >> $GITHUB_OUTPUT | |
# First create a tag without creating a release | |
- name: Create Git Tag | |
working-directory: repo | |
run: | | |
git config --local user.email "hassansonson2002@gmail.com" | |
git config --local user.name "hassan220022" | |
git tag -a v${{ steps.calc_version.outputs.next_version }} -m "Release v${{ steps.calc_version.outputs.next_version }}" | |
git push origin v${{ steps.calc_version.outputs.next_version }} | |
# Use the official GitHub Release API instead of the JavaScript approach | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
release/flex-linux | |
release/flex-windows.exe | |
release/flex-macos | |
generate_release_notes: false |