Refactor build-flex.yml to streamline release artifact preparation #42
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: | | |
mkdir -p release | |
find . -type f -name "flex-*" -exec ls -la {} \; | |
- name: Prepare release artifacts | |
run: | | |
# Copy executables directly from artifact folders to release directory | |
cp ./flex-linux/flex-linux ./release/flex-linux 2>/dev/null || echo "Linux executable not found" | |
cp ./flex-windows.exe/flex-windows.exe ./release/flex-windows.exe 2>/dev/null || echo "Windows executable not found" | |
cp ./flex-macos/flex-macos ./release/flex-macos 2>/dev/null || echo "macOS executable not found" | |
# Set permissions | |
chmod +x ./release/* 2>/dev/null || true | |
# List contents of release directory to verify | |
echo "Contents of release directory:" | |
ls -la ./release/ | |
- name: Checkout repository for tag information | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get next version number | |
id: calc_version | |
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 | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: v${{ steps.calc_version.outputs.next_version }} | |
name: Release v${{ steps.calc_version.outputs.next_version }} | |
body: | | |
## Flex Language Interpreter v${{ steps.calc_version.outputs.next_version }} | |
This release contains pre-built executables for all major platforms: | |
- **Linux**: Download `flex-linux` | |
- **Windows**: Download `flex-windows.exe` | |
- **macOS**: Download `flex-macos` | |
### Installation | |
1. Download the appropriate executable for your platform | |
2. Make it executable (Linux/macOS): `chmod +x flex-*` | |
3. Run it: `./flex-linux yourfile.flex` (or appropriate executable name) | |
generate_release_notes: false | |
draft: false | |
prerelease: false | |
files_from_path: true | |
fail_on_unmatched_files: false | |
files: >- | |
./release/flex-linux | |
./release/flex-windows.exe | |
./release/flex-macos |