Refactor CI templates to support dynamic build targets
This commit is contained in:
parent
77c668f7b6
commit
3b5a3882f6
5 changed files with 165 additions and 66 deletions
|
@ -13,6 +13,7 @@ This update introduces minor bug fixes & improvements
|
||||||
- Added new constant `%DEFAULT_BUILD_CONFIGURATION%` which points to the project's default build configuration
|
- Added new constant `%DEFAULT_BUILD_CONFIGURATION%` which points to the project's default build configuration
|
||||||
- Added new dynamic constant `%BUILD_OUTPUT_PATH%` which can be used as `%BUILD_OUTPUT_PATH%:release` to show the
|
- Added new dynamic constant `%BUILD_OUTPUT_PATH%` which can be used as `%BUILD_OUTPUT_PATH%:release` to show the
|
||||||
output path of a specific build configuration
|
output path of a specific build configuration
|
||||||
|
- Refactor CI templates to support dynamic build targets
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Refactor phpmake template to support dynamic build targets
|
- Refactor phpmake template to support dynamic build targets
|
||||||
|
|
|
@ -58,11 +58,60 @@ class GitHubWorkflowTemplate
|
||||||
mkdir($ci_dir, 0777, true);
|
mkdir($ci_dir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
IO::fwrite(
|
$template = IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'github_ci.yml.tpl');
|
||||||
$ci_dir . DIRECTORY_SEPARATOR . 'ncc_workflow.yml',
|
$default_configuration = $project_manager->getProjectConfiguration()->getBuild()->getDefaultConfiguration();
|
||||||
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(),
|
$builds = [];
|
||||||
IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'github_ci.yml.tpl')
|
$releases = [];
|
||||||
)
|
$downloads = [];
|
||||||
|
foreach($project_manager->getProjectConfiguration()->getBuild()->getBuildConfigurations() as $build_name)
|
||||||
|
{
|
||||||
|
$build_template = IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'github_ci_build.yml.tpl');
|
||||||
|
$build_template = str_replace('%TPL_BUILD_NAME%', $build_name, $build_template);
|
||||||
|
$build_template = str_replace('%TPL_BUILD_OUTPUT%',
|
||||||
|
$project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_name)->getOutput(),
|
||||||
|
$build_template
|
||||||
|
);
|
||||||
|
$builds[$build_name] = $build_template;
|
||||||
|
|
||||||
|
$download_template = IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'github_ci_download.yml.tpl');
|
||||||
|
$download_template = str_replace('%TPL_BUILD_NAME%', $build_name, $download_template);
|
||||||
|
$downloads[$build_name] = $download_template;
|
||||||
|
|
||||||
|
$release_template = str_repeat(' ', 12) . $build_name . DIRECTORY_SEPARATOR . basename(
|
||||||
|
$project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_name)->getOutput()
|
||||||
|
);
|
||||||
|
$releases[$build_name] = $release_template;
|
||||||
|
}
|
||||||
|
|
||||||
|
$build_jobs = '';
|
||||||
|
foreach($builds as $name => $build_template)
|
||||||
|
{
|
||||||
|
$build_jobs .= $build_template . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$download_jobs = '';
|
||||||
|
foreach($downloads as $name => $download_template)
|
||||||
|
{
|
||||||
|
$download_jobs .= $download_template . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$release_jobs = '';
|
||||||
|
foreach($releases as $name => $release_template)
|
||||||
|
{
|
||||||
|
$release_jobs .= $release_template . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$template = str_replace('%TPL_BUILDS%', $build_jobs, $template);
|
||||||
|
$template = str_replace('%TPL_DOWNLOAD_ARTIFACTS%', $download_jobs, $template);
|
||||||
|
$template = str_replace('%TPL_ARTIFACT_FILES%', $release_jobs, $template);
|
||||||
|
$template = str_replace('%TPL_BUILD_NAMES%', implode(', ', array_keys($builds)), $template);
|
||||||
|
$template = str_replace('%TPL_DEFAULT_BUILD_CONFIGURATION%', $default_configuration, $template);
|
||||||
|
$template = str_replace('%TPL_DEFAULT_ARTIFACT_BUILD_OUTPUT%', $default_configuration . DIRECTORY_SEPARATOR . basename(
|
||||||
|
$project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($default_configuration)->getOutput()
|
||||||
|
), $template);
|
||||||
|
|
||||||
|
IO::fwrite($ci_dir . DIRECTORY_SEPARATOR . 'ncc_workflow.yml',
|
||||||
|
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(), $template)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,56 +9,9 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
%TPL_BUILDS%
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: php:8.3
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
apt update -yqq
|
|
||||||
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
|
|
||||||
|
|
||||||
- name: Install phive
|
|
||||||
run: |
|
|
||||||
wget -O phive.phar https://phar.io/releases/phive.phar
|
|
||||||
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
|
|
||||||
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
|
|
||||||
gpg --verify phive.phar.asc phive.phar
|
|
||||||
chmod +x phive.phar
|
|
||||||
mv phive.phar /usr/local/bin/phive
|
|
||||||
|
|
||||||
- name: Install phab
|
|
||||||
run: |
|
|
||||||
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
|
|
||||||
|
|
||||||
- name: Install latest version of NCC
|
|
||||||
run: |
|
|
||||||
git clone https://git.n64.cc/nosial/ncc.git
|
|
||||||
cd ncc
|
|
||||||
make redist
|
|
||||||
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
|
|
||||||
if [ -z "$NCC_DIR" ]; then
|
|
||||||
echo "NCC build directory not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
php "$NCC_DIR/INSTALL" --auto
|
|
||||||
cd .. && rm -rf ncc
|
|
||||||
|
|
||||||
- name: Build project
|
|
||||||
run: |
|
|
||||||
ncc build --config release --log-level debug
|
|
||||||
|
|
||||||
- name: Upload build artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: %ASSEMBLY.NAME%_build
|
|
||||||
path: build/release/%ASSEMBLY.PACKAGE%.ncc
|
|
||||||
|
|
||||||
|
# Checking for phpunit.xml
|
||||||
check-phpunit:
|
check-phpunit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
|
@ -74,9 +27,55 @@ jobs:
|
||||||
else
|
else
|
||||||
echo "phpunit-exists=false" >> $GITHUB_OUTPUT
|
echo "phpunit-exists=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
# Checking for phpdoc.dist.xml
|
||||||
|
check-phpdoc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
phpdoc-exists: ${{ steps.check.outputs.phpdoc-exists }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Check for phpdoc.dist.xml
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
if [ -f phpdoc.dist.xml ]; then
|
||||||
|
echo "phpdoc-exists=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "phpdoc-exists=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
generate-phpdoc:
|
||||||
|
needs: [%TPL_DEFAULT_BUILD_CONFIGURATION%, check-phpdoc]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: php:8.3
|
||||||
|
if: needs.check-phpdoc.outputs.phpdoc-exists == 'true'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
apt update -yqq
|
||||||
|
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
|
||||||
|
|
||||||
|
- name: Download PHPDocumentor
|
||||||
|
run: |
|
||||||
|
wget https://phpdoc.org/phpDocumentor.phar
|
||||||
|
chmod +x phpDocumentor.phar
|
||||||
|
|
||||||
|
- name: Generate PHPDoc
|
||||||
|
run: |
|
||||||
|
php phpDocumentor.phar -d src -t docs
|
||||||
|
|
||||||
|
- name: Upload PHPDoc
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: documentation
|
||||||
|
path: docs
|
||||||
|
|
||||||
test:
|
test:
|
||||||
needs: [build, check-phpunit]
|
needs: [%TPL_BUILD_NAMES%, check-phpunit]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: php:8.3
|
image: php:8.3
|
||||||
|
@ -89,8 +88,8 @@ jobs:
|
||||||
- name: Download build artifacts
|
- name: Download build artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: %ASSEMBLY.NAME%_build
|
name: %TPL_DEFAULT_BUILD_CONFIGURATION%
|
||||||
path: %ASSEMBLY.NAME%_build # Adjust this to download the artifact directly under '%ASSEMBLY.NAME%_build'
|
path: %TPL_DEFAULT_BUILD_CONFIGURATION%
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
@ -128,15 +127,15 @@ jobs:
|
||||||
|
|
||||||
- name: Install NCC packages
|
- name: Install NCC packages
|
||||||
run: |
|
run: |
|
||||||
ncc package install --package="%ASSEMBLY.NAME%_build/%ASSEMBLY.PACKAGE%.ncc" --build-source --reinstall -y --log-level debug
|
ncc package install --package="%TPL_DEFAULT_ARTIFACT_BUILD_OUTPUT%" --build-source --reinstall -y --log-level debug
|
||||||
|
|
||||||
- name: Run PHPUnit tests
|
- name: Run PHPUnit tests
|
||||||
run: |
|
run: |
|
||||||
wget https://phar.phpunit.de/phpunit-11.3.phar
|
wget https://phar.phpunit.de/phpunit-11.3.phar
|
||||||
php phpunit-11.3.phar --configuration phpunit.xml
|
php phpunit-11.3.phar --configuration phpunit.xml
|
||||||
|
|
||||||
release:
|
upload-artifacts:
|
||||||
needs: [build, test]
|
needs: [%TPL_BUILD_NAMES%, test]
|
||||||
permissions: write-all
|
permissions: write-all
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
|
@ -147,16 +146,12 @@ jobs:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Download build artifacts
|
%TPL_DOWNLOAD_ARTIFACTS%
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: %ASSEMBLY.NAME%_build
|
|
||||||
path: %ASSEMBLY.NAME%_build
|
|
||||||
|
|
||||||
- name: Upload to GitHub Release
|
- name: Upload to GitHub Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
%ASSEMBLY.NAME%_build/%ASSEMBLY.PACKAGE%.ncc
|
%TPL_ARTIFACT_FILES%
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@ -0,0 +1,49 @@
|
||||||
|
%TPL_BUILD_NAME%:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: php:8.3
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
apt update -yqq
|
||||||
|
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
|
||||||
|
|
||||||
|
- name: Install phive
|
||||||
|
run: |
|
||||||
|
wget -O phive.phar https://phar.io/releases/phive.phar
|
||||||
|
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
|
||||||
|
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
|
||||||
|
gpg --verify phive.phar.asc phive.phar
|
||||||
|
chmod +x phive.phar
|
||||||
|
mv phive.phar /usr/local/bin/phive
|
||||||
|
|
||||||
|
- name: Install phab
|
||||||
|
run: |
|
||||||
|
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
|
||||||
|
|
||||||
|
- name: Install latest version of NCC
|
||||||
|
run: |
|
||||||
|
git clone https://git.n64.cc/nosial/ncc.git
|
||||||
|
cd ncc
|
||||||
|
make redist
|
||||||
|
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
|
||||||
|
if [ -z "$NCC_DIR" ]; then
|
||||||
|
echo "NCC build directory not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
php "$NCC_DIR/INSTALL" --auto
|
||||||
|
cd .. && rm -rf ncc
|
||||||
|
|
||||||
|
- name: Build project
|
||||||
|
run: |
|
||||||
|
ncc build --config %TPL_BUILD_NAME% --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: %TPL_BUILD_NAME%
|
||||||
|
path: %TPL_BUILD_OUTPUT%
|
|
@ -0,0 +1,5 @@
|
||||||
|
- name: Download %TPL_BUILD_NAME% artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: %TPL_BUILD_NAME%
|
||||||
|
path: %TPL_BUILD_NAME%
|
Loading…
Add table
Reference in a new issue