Workflow file for this run
This file contains 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: Update dcstore.xml file if necessary | |
on: | |
release: | |
types: | |
- released | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "dcstore" | |
dcstore: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Setup PHP | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.0' | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v4 | |
# Back to default branch | |
- name: Back to default branch of repository | |
shell: bash | |
run: | | |
echo "git fetch && git switch ${{github.event.repository.default_branch}}" | |
git fetch | |
git switch ${{github.event.repository.default_branch}} | |
# Run PHP code | |
- name: Run PHP code | |
id: getversion | |
shell: php {0} | |
run: | | |
<?php | |
$version = ''; | |
$dcmin = '2.0'; | |
if (file_exists('dcstore.xml')) { | |
$df = file_get_contents('./_define.php'); | |
if (preg_match('/registerModule\((.*?),(.*?)[\'\"],(.*?)[\'\"],(.*?)[\'\"](.*?)[\'\"](.*?)(,.*)\)/s',$df,$matches)) { | |
if (isset($matches[5])) { | |
$version = $matches[5]; | |
if (isset($matches[7])) { | |
$str = $matches[7]; | |
if (preg_match('/\[(.*?)[\'\"]core[\'\"](.*?),(.*?)[\'\"](.*?)[\'\"](.*?)\]/s',$str,$submatches)) { | |
$dcmin = $submatches[4]; | |
} | |
} | |
} | |
} | |
if ($version !== '') { | |
$ds = file_get_contents('dcstore.xml'); | |
if ($ds) { | |
$ds = preg_replace('/<version>(.*?)<\/version>/s',"<version>$version</version>",$ds); | |
$ds = preg_replace('/download\/(.*?)\//s',"download/$version/",$ds); | |
$ds = preg_replace('/(.*)-(.*?).zip/s',"$1-$version.zip",$ds); | |
$ds = preg_replace('/<da:dcmin>(.*?)<\/da:dcmin>/s',"<da:dcmin>$dcmin</da:dcmin>",$ds); | |
if ($ds) { | |
file_put_contents('dcstore.xml',$ds); | |
} | |
} | |
} | |
} | |
file_put_contents(getenv('GITHUB_OUTPUT'), "module_version=$version\n", FILE_APPEND); | |
file_put_contents(getenv('GITHUB_OUTPUT'), "module_dcmin=$dcmin\n", FILE_APPEND); | |
# Cope with returned versions | |
- name: Log output of the script | |
shell: bash | |
run: echo "${{steps.getversion.outputs.module_version}} (Dotclear ${{steps.getversion.outputs.module_dcmin}}+)" | |
# Log default branch | |
- name: Log output the default branch | |
shell: bash | |
run: echo "The default branch is ${{github.event.repository.default_branch}}" | |
# Update dcstore.xml if necessary | |
- name: Update dcstore | |
id: update-dcstore | |
shell: bash | |
run: | | |
cat dcstore.xml | |
test=$(git diff --name-only -- dcstore.xml) | |
if [[ "$test" != "" ]]; then | |
echo "dcstore.xml modified, need to be commit" | |
echo "set credentials" | |
git config user.email "carnet.franck.paul@gmail.com" | |
git config user.name "franck-paul" | |
echo "git add dcstore.xml" | |
git add dcstore.xml | |
echo "git commit" | |
git commit -m "Update dcstore.xml - version ${{steps.getversion.outputs.module_version}} - Dotclear ${{steps.getversion.outputs.module_dcmin}}+" | |
echo "git push" | |
git push | |
else | |
echo "nothing to do" | |
fi | |
# Notification via Telegram | |
- name: Send Telegram Message Ok | |
uses: appleboy/telegram-action@master | |
env: | |
GITHUB_CONTEXT: ${{toJSON(github)}} | |
with: | |
to: ${{ secrets.TELEGRAM_ID }} | |
token: ${{ secrets.TELEGRAM_TOKEN }} | |
format: markdown | |
message: | | |
→ Update *dcstore.xml* file if necessary | |
Repository: *${{github.repository}}* | |
Version: *${{steps.getversion.outputs.module_version}}* (Dotclear ${{steps.getversion.outputs.module_dcmin}}+) | |
Branch: *${{ github.ref }}* | |
Owner: *${{github.repository_owner}}* | |
🍺 |