Skip to content

Rasheedat/cicd

Rasheedat/cicd #6

Workflow file for this run

name: Build and Deploy SyDEVS
on:
push:
tags:
- 'v*'
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
# Step 1: Checkout repository
- name: Checkout Repository
uses: actions/checkout@v3
# Step 2: Setup build tools based on OS
- name: Setup Build Tools on Windows
if: runner.os == 'Windows'
run: choco install visualstudio2022buildtools --yes
shell: powershell
- name: Install Dependencies (Ubuntu)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y build-essential cmake
# Step 3: Configure Build Environment
- name: Configure Build
run: cmake -S . -B build
shell: bash
# Step 4: Build Project
- name: Build Project
run: cmake --build build --config Release --parallel
shell: bash
# Step 5: Prepare Artifacts
- name: Prepare Artifacts
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
# Linux-specific commands (Bash)
mkdir -p artifacts/lib artifacts/include/sydevs/core artifacts/include/sydevs/systems artifacts/include/sydevs/time
cp src/sydevs/core/*.h artifacts/include/sydevs/core || true
cp src/sydevs/systems/*.h artifacts/include/sydevs/systems || true
cp src/sydevs/time/*.h artifacts/include/sydevs/time || true
cp build/lib*.so artifacts/lib || cp build/Release/SyDEVS.lib artifacts/lib || true
zip -r artifacts_linux.zip artifacts
elif [[ "$RUNNER_OS" == "Windows" ]]; then
# Windows-specific commands (PowerShell)
pwsh -Command "
New-Item -ItemType Directory -Force -Path artifacts\\lib, artifacts\\include\\sydevs\\core, artifacts\\include\\sydevs\\systems, artifacts\\include\\sydevs\\time;
Copy-Item -Path src\\sydevs\\core\\*.h -Destination artifacts\\include\\sydevs\\core -Force;
Copy-Item -Path src\\sydevs\\systems\\*.h -Destination artifacts\\include\\sydevs\\systems -Force;
Copy-Item -Path src\\sydevs\\time\\*.h -Destination artifacts\\include\\sydevs\\time -Force;
Copy-Item -Path build\\lib*.so -Destination artifacts\\lib -Force;
Copy-Item -Path build\\Release\\SyDEVS.lib -Destination artifacts\\lib -Force;
Compress-Archive -Path artifacts\\* -DestinationPath artifacts_windows.zip
"
fi
shell: bash
# Step 6: Upload Artifacts for Debugging
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: |
artifacts_linux.zip
artifacts_windows.zip
deploy:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
steps:
# Step 1: Checkout Repository
- name: Checkout Repository
uses: actions/checkout@v3
# Step 2: Download Build Artifacts
- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: ./
# Step 3: Create GitHub Release
- name: Create GitHub Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
# Upload the artifact for Ubuntu
file: artifacts_linux.zip
asset_name: SyDEVS_Release_${{ github.ref_name }}_ubuntu.zip
tag: ${{ github.ref_name }}
overwrite: false
body: "Release for SyDEVS version ${{ github.ref_name }} (Ubuntu build)"
- name: Create GitHub Release for Windows
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
# Upload the artifact for Windows
file: artifacts_windows.zip
asset_name: SyDEVS_Release_${{ github.ref_name }}_windows.zip
tag: ${{ github.ref_name }}
overwrite: false
body: "Release for SyDEVS version ${{ github.ref_name }} (Windows build)"