Skip to content

Build IGs

Build IGs #35

name: Build changed IGs
on:
push:
branches:
- main
workflow_dispatch:
inputs:
ig:
description: "IG to build (select 'changed' to build only changed IGs)"
type: choice
required: true
default: changed
options:
- changed
- core
- diga
- erp-chrg
- erp-eu
- rx
- server
- t-register
jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest
env:
BUILD_USE_IGTOOLS: "false"
BUILD_GENERATE_DRAWIO_IMAGES: "false"
INSTALL_SUSHI_DEPS: "skip"
DRAWIO_APP: "/usr/local/bin/drawio"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
- name: Install tooling
run: |
sudo apt-get update
sudo apt-get install -y zsh
npm install -g fsh-sushi
sudo wget -q https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64 -O /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
- name: Install Firely Terminal (fhir)
run: |
dotnet tool install --tool-path /usr/local/bin Firely.Terminal
- name: Install Jekyll
run: |
gem install jekyll bundler
- name: Install igtools
run: |
python -m pip install --upgrade pipx
python -m pipx install git+https://github.com/onyg/req-tooling.git
- name: Install draw.io (headless)
if: env.BUILD_GENERATE_DRAWIO_IMAGES == 'true'
run: |
sudo apt-get update
sudo apt-get install -y jq xvfb
drawio_url=$(curl -s https://api.github.com/repos/jgraph/drawio-desktop/releases/latest \
| jq -r '.assets[] | select(.name | endswith(".AppImage")) | .browser_download_url' \
| head -n 1)
echo "Downloading draw.io from $drawio_url"
sudo curl -L "$drawio_url" -o /usr/local/bin/drawio.appimage
sudo chmod +x /usr/local/bin/drawio.appimage
printf '%s\n' \
'#!/usr/bin/env bash' \
'set -euo pipefail' \
'exec xvfb-run -a /usr/local/bin/drawio.appimage "$@"' \
| sudo tee /usr/local/bin/drawio >/dev/null
sudo chmod +x /usr/local/bin/drawio
- name: Determine IGs to build
id: igs
shell: bash
run: |
set -euo pipefail
manual_ig="${{ github.event.inputs.ig }}"
if [[ -n "$manual_ig" && "$manual_ig" != "changed" ]]; then
echo "ig_list=$manual_ig" >> "$GITHUB_OUTPUT"
exit 0
fi
base_sha="${{ github.event.before }}"
head_sha="${{ github.sha }}"
if [[ "$base_sha" == "0000000000000000000000000000000000000000" ]]; then
base_sha=$(git rev-list --max-parents=0 "$head_sha")
fi
mapfile -t files < <(git diff --name-only "$base_sha" "$head_sha")
declare -A igs=()
for f in "${files[@]}"; do
if [[ "$f" =~ ^igs/([^/]+)/ ]]; then
igs["${BASH_REMATCH[1]}"]=1
fi
done
ig_list=("${!igs[@]}")
if [[ ${#ig_list[@]} -eq 0 ]]; then
echo "ig_list=" >> "$GITHUB_OUTPUT"
exit 0
fi
ig_list_sorted=$(printf "%s\n" "${ig_list[@]}" | sort -u | tr '\n' ' ' | xargs)
echo "ig_list=$ig_list_sorted" >> "$GITHUB_OUTPUT"
- name: Install FHIR packages
if: steps.igs.outputs.ig_list != ''
shell: bash
run: |
set -euo pipefail
cache_dir="${FHIR_PACKAGE_CACHE_DIR:-$HOME/.fhir/packages}"
mkdir -p "$cache_dir"
for ig in ${{ steps.igs.outputs.ig_list }}; do
cfg="igs/$ig/sushi-config.yaml"
[[ -f "$cfg" ]] || continue
mapfile -t deps < <(yq eval '.dependencies // {} | to_entries | .[] | "\(.key) \(.value)"' "$cfg")
for dep in "${deps[@]}"; do
pkg="${dep%% *}"
ver="${dep#* }"
[[ -z "$pkg" || -z "$ver" ]] && continue
fhir install "$pkg" "$ver"
done
done
- name: Download IG Publisher
if: steps.igs.outputs.ig_list != ''
run: ./update-publisher.sh -y
- name: Build IGs
if: steps.igs.outputs.ig_list != ''
run: ./build-all.sh --ig ${{ steps.igs.outputs.ig_list }}
- name: Report deploy count
if: steps.igs.outputs.ig_list != ''
shell: bash
run: |
set -euo pipefail
total=0
ref_name="${GITHUB_REF_NAME}"
for ig in ${{ steps.igs.outputs.ig_list }}; do
out_dir="igs/$ig/output"
if [[ -d "$out_dir" ]]; then
count=$(find "$out_dir" -type f | wc -l | tr -d ' ')
total=$((total + count))
fi
id=$(yq -r '.id // ""' "igs/$ig/sushi-config.yaml")
version=$(yq -r '.version // ""' "igs/$ig/sushi-config.yaml")
id=${id#de.gematik.}
id=${id//./-}
if [[ "$ref_name" == "main" ]]; then
prefix="ig/fhir/$id/$version"
else
prefix="ig/fhir/$id/build/$version"
fi
echo "deploy target: gs://gematik_gemspec_fhir_prod-0/$prefix"
done
echo "deploying $total files"
- name: Prepare GitHub Pages content
if: steps.igs.outputs.ig_list != ''
shell: bash
run: |
set -euo pipefail
pages_dir="pages"
ref_name="${GITHUB_REF_NAME}"
rm -rf "$pages_dir"
mkdir -p "$pages_dir"
for ig in ${{ steps.igs.outputs.ig_list }}; do
out_dir="igs/$ig/output"
if [[ -d "$out_dir" ]]; then
id=$(yq -r '.id // ""' "igs/$ig/sushi-config.yaml")
version=$(yq -r '.version // ""' "igs/$ig/sushi-config.yaml")
id=${id#de.gematik.}
id=${id//./-}
if [[ "$ref_name" == "main" ]]; then
target_dir="$pages_dir/$id/$version"
else
target_dir="$pages_dir/$id/build/$version"
fi
mkdir -p "$target_dir"
cp -R "$out_dir"/. "$target_dir"/
fi
done
- name: Publish to GitHub Pages
if: steps.igs.outputs.ig_list != ''
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./pages
publish_branch: gh-pages
keep_files: true
- name: No IG changes
if: steps.igs.outputs.ig_list == ''
run: echo "No IG changes detected; skipping build."