Skip to content

test

test #43

Workflow file for this run

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
# 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
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
# First create a tag without creating a release
- name: Create Git Tag
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 }}
# Then create a release with just our executables
- name: Create Custom Release
id: create_release
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
// Create the release
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${process.env.NEXT_VERSION}`,
name: `Release v${process.env.NEXT_VERSION}`,
body: `## Flex Language Interpreter v${process.env.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)`,
draft: false,
prerelease: false,
generate_release_notes: false
});
// Function to upload a release asset
async function uploadAsset(filepath, contentType) {
try {
if (!fs.existsSync(filepath)) {
console.log(`File not found: ${filepath}`);
return;
}
const stats = fs.statSync(filepath);
const fileSize = stats.size;
const fileData = fs.readFileSync(filepath);
const filename = filepath.split('/').pop();
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: filename,
data: fileData,
headers: {
'content-type': contentType,
'content-length': fileSize
}
});
console.log(`Successfully uploaded ${filename}`);
} catch (error) {
console.error(`Error uploading ${filepath}: ${error.message}`);
}
}
// Upload the executables
await uploadAsset('release/flex-linux', 'application/octet-stream');
await uploadAsset('release/flex-windows.exe', 'application/octet-stream');
await uploadAsset('release/flex-macos', 'application/octet-stream');
core.setOutput('release_id', release.data.id);
env:
NEXT_VERSION: ${{ steps.calc_version.outputs.next_version }}