Skip to content

Commit

Permalink
xmlns improvements, template file hierarchy improvements (#100)
Browse files Browse the repository at this point in the history
* Improving xmlns detection on xhtml type
* Fixing xml unserializing in child types
* Internal cleanup & refactor
  • Loading branch information
dcarbone authored Apr 25, 2024
1 parent 0070f93 commit 62d5072
Show file tree
Hide file tree
Showing 50 changed files with 4,084 additions and 946 deletions.
64 changes: 64 additions & 0 deletions .github/actions/load-fhir-validator/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Load FHIR Validator'
description: 'Downloads and caches a FHIR validator jar'

inputs:
version:
required: false
description: 'Version of validator to download'
default: '6.3.4'

base-url:
required: false
description: 'Base download URL'
default: 'https://github.com/hapifhir/org.hl7.fhir.core/releases/download'

filename:
required: false
description: 'Validator filename'
default: 'validator_cli.jar'

runs:
using: composite
steps:
- id: vars
shell: bash -e {0}
# language=sh
run: |
echo 'url=${{ inputs.base-url }}/${{ inputs.version }}/${{ inputs.filename }}' >> $GITHUB_OUTPUT
echo 'cache-key=fhir-validator-${{ inputs.version }}-2' >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: cache
with:
path: |
${{ github.workspace }}/bin
/home/runner/.fhir
key: '${{ steps.vars.outputs.cache-key }}'

- name: 'Install Java'
if: steps.cache.outputs.cache-hit != 'true' && steps.cache.outputs.cache-hit != true
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 18

- name: 'Download and cache extensions'
if: steps.cache.outputs.cache-hit != 'true' && steps.cache.outputs.cache-hit != true
shell: bash -e {0}
# language=sh
run: |
echo '::group::Downloading validator_cli.jar ${{ inputs.version }}'
mkdir -p '${{ github.workspace }}/bin'
wget -q '${{ steps.vars.outputs.url }}' -O '${{ github.workspace }}/bin/${{ inputs.filename }}'
echo '::endgroup::'
echo '::group::Caching validator assets'
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 1.0.2
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 1.4.0
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 3.0.2
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 4.0.1
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 4.1.0
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 4.3.0
java -jar '${{ github.workspace }}/bin/validator_cli.jar' -version 5.0.0
echo '::endgroup::'
71 changes: 71 additions & 0 deletions .github/actions/load-fhir-xsd/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Load FHIR XSD'
description: 'Downloads and caches a a version of FHIR source files'

inputs:
version:
required: true
description: 'Version to download'

base-url:
required: false
description: 'Base FHIR URL'
default: 'https://hl7.org/fhir'

filename:
required: false
description: 'Name of xsd file'
default: 'fhir-all-xsd.zip'

user-agent:
required: false
description: 'User agent string to use'
default: 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'

outputs:
cache-key:
description: 'Actions Cache key'
value: '${{ steps.vars.cache-key }}'

runs:
using: composite
steps:
- id: vars
shell: bash -e {0}
# language=sh
run: |
_month="$(date "+%Y%m")"
_cache_key="fhir-source-${{ inputs.version }}-${_month}-1"
_dl_url="${{ inputs.base-url}}/${{ inputs.version }}/${{ inputs.filename }}"
_cache_dir="${{ github.workspace }}/input"
_xsd_cache_dir="${_cache_dir}/${{ inputs.version }}"
_zip_filename="${_cache_dir}/${{ inputs.version }}.zip"
echo "cache-key=${_cache_key}" >> $GITHUB_OUTPUT
echo "cache-dir=${_cache_dir}" >> $GITHUB_OUTPUT
echo "xsd-cache-dir=${_xsd_cache_dir}" >> $GITHUB_OUTPUT
echo "url=${_dl_url}" >> $GITHUB_OUTPUT
echo "zip-filename=${_zip_filename}" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: cache
with:
path: '${{ steps.vars.outputs.cache-dir }}'
key: '${{ steps.vars.outputs.cache-key }}'

- name: 'Download'
if: steps.cache.outputs.cache-hit != 'true' && steps.cache.outputs.cache-hit != true
shell: bash -e {0}
# language=sh
run: |
mkdir -p '${{ steps.vars.outputs.xsd-cache-dir }}'
curl \
-L \
-A '${{ inputs.user-agent }}' \
-o '${{ steps.vars.outputs.zip-filename }}' \
'${{ steps.vars.outputs.url }}'
unzip -o -qq '${{ steps.vars.outputs.zip-filename }}' -d '${{ steps.vars.outputs.xsd-cache-dir }}'
ls -l '${{ steps.vars.outputs.cache-dir}}'
ls -l '${{ steps.vars.outputs.xsd-cache-dir }}'
70 changes: 53 additions & 17 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,35 @@ on:
- 'phpunit.xml'

jobs:
load-fhir-source:
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
fhir-version: [ 'DSTU1', 'DSTU2', 'STU3', 'R4', 'R5' ]

name: 'Download ${{ matrix.fhir-version }} Source'
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/load-fhir-xsd
with:
version: '${{ matrix.fhir-version }}'


load-fhir-validator:
runs-on: ubuntu-22.04
name: 'Download FHIR Validator'
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/load-fhir-validator

run:
runs-on: ubuntu-22.04
needs:
- load-fhir-source
- load-fhir-validator
strategy:
fail-fast: false
matrix:
Expand All @@ -43,59 +70,68 @@ jobs:
- php-version: '8.3'
phpunit-version: '11.1'
paratest-version: '7'
name: ${{ matrix.fhir-version }} - PHP ${{ matrix.php-version }} - PHPUnit ${{ matrix.phpunit-version }}
name: '${{ matrix.fhir-version }} - PHP ${{ matrix.php-version }} - PHPUnit ${{ matrix.phpunit-version }}'
steps:
- uses: actions/checkout@v4
- name: 'Check the stuff out'
uses: actions/checkout@v4

- name: 'Load FHIR ${{ matrix.fhir-version }} Source'
uses: ./.github/actions/load-fhir-xsd
with:
version: '${{ matrix.fhir-version }}'

- name: 'Install FHIR validator'
uses: ./.github/actions/load-fhir-validator

- uses: shivammathur/setup-php@v2
- name: 'Install PHP'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: libxml simplexml json zip
# https://github.com/mheap/phpunit-github-actions-printer/blob/master/.github/workflows/ci.yml#L32

- uses: dcarbone/install-jq-action@v2
- name: 'Install jq'
uses: dcarbone/install-jq-action@v2
with:
force: true

- name: 'Set Composer Dep Versions'
# language=sh
run: |
tmpf="$(mktemp)"
jq -rcM '."require-dev"."phpunit/phpunit" = "^${{ matrix.phpunit-version }}" | ."require-dev"."brianium/paratest" = "^${{ matrix.paratest-version }}"' composer.json > "${tmpf}"
mv "${tmpf}" composer.json
- name: 'Get Composer Cache Directory'
id: composer-cache
# language=sh
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ hashFiles('**/composer.lock') }}"

- name: 'Cache downloaded FHIR sources'
- name: 'Cache Composer Stuff'
uses: actions/cache@v4
with:
path: ./input
key: "fhir-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ hashFiles('**/composer.lock') }}"
path: ${{ steps.composer-cache.outputs.dir }}
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ hashFiles('composer.lock') }}"

- name: 'Install Composer deps'
# language=sh
run: |
rm composer.lock
composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: 'Generate code'
# language=sh
run: |
./bin/generate.sh --useExisting --versions '${{ matrix.fhir-version }}'
- uses: actions/setup-java@v4
- name: 'Install Java'
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 18

- name: 'Install FHIR validator'
run: |
wget --quiet https://github.com/hapifhir/org.hl7.fhir.core/releases/download/6.3.4/validator_cli.jar -O ./bin/validator_cli.jar
- name: 'Run tests'
# language=sh
run: |
./vendor/bin/paratest -c 'phpunit/${{ matrix.fhir-version }}.xml'
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/vendor
/composer.lock
/tmp
.idea/
.svn/
tmp/
vendor/
/*.iml
/.idea
/.svn
/.*.cache
2 changes: 1 addition & 1 deletion bin/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'testEndpoint' => 'https://hapi.fhir.org/baseDstu3',
],
'R4' => [
'url' => 'https://www.hl7.org/fhir/R4/fhir-all-xsd.zip',
'url' => 'https://hl7.org/fhir/R4/fhir-all-xsd.zip',
'namespace' => '\\HL7\\FHIR\\R4',
'testEndpoint' => 'https://hapi.fhir.org/baseR4',
],
Expand Down
6 changes: 3 additions & 3 deletions bin/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function is_dir_empty(string $dir): bool

if ($download) {
// Download zip file...
echo sprintf('Downloading %s from %s%s', $version, $url, PHP_EOL);
echo sprintf('Downloading %s from %s to %s%s', $version, $url, $zip_file_name, PHP_EOL);
$fh = fopen($zip_file_name, 'w');
$ch = curl_init($url);
curl_setopt_array(
Expand Down Expand Up @@ -511,9 +511,9 @@ function is_dir_empty(string $dir): bool

$builder = new Builder($build_config, $definition);
if ($only_library) {
$builder->renderFHIRClasses();
$builder->writeFhirTypeFiles();
} elseif ($only_tests) {
$builder->renderTestClasses();
$builder->writeFhirTestFiles();
} else {
$builder->render();
}
Expand Down
Loading

0 comments on commit 62d5072

Please sign in to comment.