Skip to content

Test Hello World On Latest Release #699

Test Hello World On Latest Release

Test Hello World On Latest Release #699

name: Test Hello World On Latest Release
on:
schedule:
- cron: '0 */12 * * *'
workflow_dispatch:
jobs:
test-release:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
asset: linux-x86-64-tcc.zip
chemical_executable: chemical
binary_name: helloworld
- os: ubuntu-latest
asset: linux-x86-64.zip
chemical_executable: chemical
binary_name: helloworld
- os: windows-latest
asset: windows-x64-tcc.zip
chemical_executable: chemical.exe
binary_name: main.exe
- os: windows-latest
asset: windows-x64.zip
chemical_executable: chemical.exe
binary_name: main.exe
runs-on: ${{ matrix.os }}
steps:
- name: Create main.ch source file (Linux)
if: runner.os != 'Windows'
run: |
echo "@extern" > main.ch
echo "public func printf(format : *char, _ : any...)" >> main.ch
echo "public func main() : int {" >> main.ch
echo " printf(\"hello world\")" >> main.ch
echo " return 0;" >> main.ch
echo "}" >> main.ch
shell: bash
- name: Create main.ch source file (Windows)
if: runner.os == 'Windows'
run: |
# Only create main.ch if it doesn't already exist
if (!(Test-Path -Path main.ch)) {
Set-Content -Path main.ch -Value @(
'@extern',
'public func printf(format : *char, _ : any...)',
'public func main() : int {',
' printf("hello world")',
' return 0;',
'}'
)
}
shell: pwsh
- name: Download release asset (Linux)
if: runner.os != 'Windows'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Fetching release information (including pre-releases)..."
releases=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases")
ASSET_URL=$(echo "$releases" | jq -r '[.[] | select(.assets | map(.name) | index("${{ matrix.asset }}"))] | .[0].assets[] | select(.name=="${{ matrix.asset }}") | .browser_download_url')
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
echo "Error: Asset ${{ matrix.asset }} not found in any release."
exit 1
fi
echo "Downloading asset from $ASSET_URL"
curl -L -o asset.zip "$ASSET_URL"
shell: bash
- name: Download release asset (Windows)
if: runner.os == 'Windows'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Write-Host "Fetching release information (including pre-releases)..."
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/${env:GITHUB_REPOSITORY}/releases" -Headers @{ Authorization = "token $env:GITHUB_TOKEN" }
$assetName = "${{ matrix.asset }}"
$release = $releases | Where-Object { $_.assets -and ($_.assets | Where-Object { $_.name -eq $assetName }) } | Select-Object -First 1
if (-not $release) {
Write-Error "Error: Asset $assetName not found in any release."
exit 1
}
$asset = $release.assets | Where-Object { $_.name -eq $assetName }
if (-not $asset) {
Write-Error "Error: Asset $assetName not found in the selected release."
exit 1
}
Write-Host "Downloading asset from $($asset.browser_download_url)"
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile asset.zip
shell: pwsh
- name: Extract asset (Linux)
if: runner.os != 'Windows'
run: |
unzip -o -q asset.zip || true
shell: bash
- name: Extract asset (Windows)
if: runner.os == 'Windows'
run: |
Expand-Archive -Path asset.zip -DestinationPath .
shell: pwsh
- name: Compile source code (Linux)
if: runner.os != 'Windows'
run: |
# Determine the release root
release_root=$(find . -maxdepth 1 -type d ! -path "." | head -n 1)
if [ -z "$release_root" ]; then
echo "Error: No release directory found."
exit 1
fi
echo "Using release root: $release_root"
# Copy main.ch if not present.
if [ ! -f "$release_root/main.ch" ]; then
cp main.ch "$release_root/"
fi
pushd "$release_root"
# Run compiler command and capture its output.
./${{ matrix.chemical_executable }} main.ch -o ${{ matrix.binary_name }} -v | tee compile_output.txt
popd
shell: bash
- name: Compile source code (Windows)
if: runner.os == 'Windows'
run: |
$releaseRoot = "."
$dirs = Get-ChildItem -Directory -Path .
if ($dirs.Count -eq 1) {
$releaseRoot = $dirs[0].FullName
}
Write-Host "Using release root: $releaseRoot"
# Copy main.ch if not present.
if (-not (Test-Path -Path "$releaseRoot\main.ch")) {
Copy-Item -Path main.ch -Destination $releaseRoot
}
Push-Location $releaseRoot
# Run compiler command and capture its output.
.\${{ matrix.chemical_executable }} main.ch -o ${{ matrix.binary_name }} -v | Tee-Object -FilePath compile_output.txt
Pop-Location
shell: pwsh
- name: Run compiled program and capture combined output (Linux)
if: runner.os != 'Windows'
run: |
# Determine the release root
release_root=$(find . -maxdepth 1 -type d ! -path "." | head -n 1)
if [ -z "$release_root" ]; then
echo "Error: No release directory found."
exit 1
fi
echo "Using release root: $release_root"
pushd "$release_root"
# Append marker and executable output to compile_output.txt.
echo "EXECUTABLE OUTPUT" >> compile_output.txt
./${{ matrix.binary_name }} >> compile_output.txt
popd
cp "$release_root/compile_output.txt" "${{ matrix.asset }}-output.txt"
shell: bash
- name: Run compiled program and capture combined output (Windows)
if: runner.os == 'Windows'
run: |
$releaseRoot = "."
$dirs = Get-ChildItem -Directory -Path .
if ($dirs.Count -eq 1) {
$releaseRoot = $dirs[0].FullName
}
Write-Host "Using release root: $releaseRoot"
Push-Location $releaseRoot
# Append marker and executable output to compile_output.txt.
Add-Content -Path compile_output.txt -Value "EXECUTABLE OUTPUT"
.\${{ matrix.binary_name }} | Out-File -Append compile_output.txt
Pop-Location
if ($releaseRoot -eq $env:GITHUB_WORKSPACE) {
Rename-Item -Path "$releaseRoot\compile_output.txt" -NewName "${{ matrix.asset }}-output.txt"
} else {
Copy-Item -Path "$releaseRoot\compile_output.txt" -Destination "$env:GITHUB_WORKSPACE\${{ matrix.asset }}-output.txt"
}
shell: pwsh
- name: Upload output artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset }}-output
path: ${{ matrix.asset }}-output.txt