Added whitespace around control characters #28
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: PHP Build+Test | |
on: [push] | |
#push: | |
# branches: [ "main" ] | |
#pull_request: | |
# branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
supported-php-versions: | |
runs-on: ubuntu-latest | |
name: Get supported PHP versions | |
outputs: | |
php-versions: ${{ steps.versions.outputs.range }} | |
steps: | |
- uses: tighten/phpreleases-action@v1 | |
id: versions | |
test: | |
needs: supported-php-versions | |
runs-on: ${{ matrix.operating-system }} | |
strategy: | |
matrix: | |
operating-system: [ubuntu-latest] | |
php-versions: ${{ fromJSON(needs.supported-php-versions.outputs.php-versions) }} | |
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install PHP ${{ matrix.php-versions }} | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
- name: Validate composer.json and composer.lock | |
run: composer validate --strict | |
- name: Get composer cache directory | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Cache Composer packages | |
uses: actions/cache@v3 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- name: Install dependencies | |
run: composer install --prefer-dist --no-progress | |
- name: Run tests | |
run: composer run-script test | |
deploy: | |
#if: github.ref_type == 'tag' | |
needs: [supported-php-versions, test] | |
permissions: | |
id-token: write | |
pages: write | |
runs-on: ubuntu-latest | |
name: Deploy to GitHub Pages | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get phpDocumentor | |
run: wget https://phpdoc.org/phpDocumentor.phar | |
- name: Install dependencies | |
run: composer install --prefer-dist --no-progress | |
- name: Generate phpDoc | |
run: composer run-script phpdoc | |
- name: Update documentation files with build information | |
uses: actions/github-script@v7 | |
id: replacements | |
with: | |
script: | | |
core.startGroup('set placeholders'); | |
const versions = ${{ needs.supported-php-versions.outputs.php-versions }}.sort().map(x => x.toString()); | |
const placeholders ={ | |
CURRENT_VERSION: '${{ github.ref_name }}', | |
MIN_PHP_VERSION: versions.slice(0, 1).join(''), | |
TESTED_PHP_VERSIONS: `${versions.slice(0, versions.length - 1).join(', ')}, and ${versions.slice(-1)}`, | |
}; | |
core.info(JSON.stringify(placeholders, null, 2)); | |
core.endGroup(); | |
const regex = /<!--\s*([A-Z_-]+)\s*-->.*?<!--\s*END \1-->/gi; | |
core.startGroup('search files'); | |
const patterns = ['**/*.md', '**/*.html']; | |
const globber = await glob.create(patterns.join('\n')) | |
const files = await globber.glob() | |
const fs = require('fs'); | |
for (const file of files) { | |
core.info(`${file}:`); | |
fs.readFile(file, 'utf8', (err, data) => { | |
if (err) { | |
core.error(err); | |
return; | |
} | |
let replacements = {}; | |
let match; | |
while (match = regex.exec(data)) { | |
const [replace, key] = match; | |
if (key in placeholders) { | |
if (replace in replacements) | |
continue; | |
replacements[replace] = placeholders[key]; | |
core.debug(`${replace} => ${placeholders[key]}`); | |
} else { | |
core.warning(`Found ${key} in ${file}, but no matching key found in placeholders`); | |
} | |
} | |
let newData = data; | |
for (const [key, value] of Object.entries(replacements)) { | |
newData = newData.replace(key, value); | |
} | |
if (newData !== data) { | |
fs.writeFile(file, newData, 'utf8', (err) => { | |
if (err) { | |
core.error(err); | |
return; | |
} | |
core.info(`\t${Object.entries(replacements).length} replacements made in ${file}`); | |
}); | |
} | |
}); | |
} | |
core.endGroup(); | |
- name: Upload GitHub Pages artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: docs/ | |
- name: Deploy GitHub Pages site | |
id: deployment | |
uses: actions/deploy-pages@v4 |