#
All checks were successful
FHIR IG CI/CD Pipeline with Version Persistence / build-ig (push) Successful in 6m8s
FHIR IG CI/CD Pipeline with Version Persistence / deploy (push) Successful in 8s

This commit is contained in:
2026-03-07 18:57:46 +06:00
parent dc43651043
commit d82e428e24

View File

@@ -3,7 +3,7 @@ name: FHIR IG CI/CD Pipeline with Version Persistence
on: on:
push: push:
tags: tags:
- 'v*.*.*' # Trigger on version tags like v0.3.0 - 'v*.*.*'
pull_request: pull_request:
branches: [ main ] branches: [ main ]
@@ -16,469 +16,522 @@ jobs:
runs-on: fhir-runner runs-on: fhir-runner
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Extract version from IG - name: Extract version from IG
id: version id: version
run: | run: |
# Extract version from ImplementationGuide resource VERSION=$(grep -oP '<version value="\K[^"]+' input/bd.fhir.core.xml | head -1)
VERSION=$(grep -oP '<version value="\K[^"]+' input/bd.fhir.core.xml | head -1)
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then
echo "ERROR: Could not extract version from ImplementationGuide XML" echo "ERROR: Could not extract version from ImplementationGuide XML"
exit 1
fi
echo "Extracted version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Determine if this is a release build (git tag) or dev build
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
BUILD_TYPE="release"
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
# Verify tag matches IG version
if [ "$TAG_VERSION" != "$VERSION" ]; then
echo "ERROR: Git tag version ($TAG_VERSION) doesn't match IG version ($VERSION)"
exit 1 exit 1
fi fi
else
BUILD_TYPE="dev" echo "Extracted version: $VERSION"
fi echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "build_type=$BUILD_TYPE" >> $GITHUB_OUTPUT if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "Build type: $BUILD_TYPE" BUILD_TYPE="release"
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
- name: Pre-build package-list.json and generate history.xml
run: | if [ "$TAG_VERSION" != "$VERSION" ]; then
VERSION="${{ steps.version.outputs.version }}" echo "ERROR: Git tag version ($TAG_VERSION) doesn't match IG version ($VERSION)"
BUILD_TYPE="${{ steps.version.outputs.build_type }}" exit 1
DATE=$(date +%Y-%m-%d) fi
else
# Export for Python BUILD_TYPE="dev"
export VERSION DATE fi
echo "📋 Preparing package-list.json and history.xml for IG Publisher..." echo "build_type=$BUILD_TYPE" >> $GITHUB_OUTPUT
echo "Build type: $BUILD_TYPE"
# Check if package-list.json exists in repo
if [ ! -f "package-list.json" ]; then - name: Prepare package-list.json and history.xml for IG Publisher
echo "⚠️ package-list.json not found in repo root" run: |
echo "Creating initial package-list.json..." VERSION="${{ steps.version.outputs.version }}"
cat > package-list.json << 'PKGEOF' BUILD_TYPE="${{ steps.version.outputs.build_type }}"
{ DATE=$(date +%Y-%m-%d)
"package-id": "bd.fhir.core",
"title": "Bangladesh Core FHIR Implementation Guide", export VERSION DATE BUILD_TYPE
"canonical": "https://fhir.dghs.gov.bd/core",
"introduction": "The Bangladesh Core FHIR IG defines national base profiles, value sets, and extensions for health data interoperability.", echo "📋 Preparing package-list.json and history.xml for IG Publisher..."
"list": [
{ if [ ! -f "package-list.json" ]; then
"version": "current", echo "⚠️ package-list.json not found in repo root"
"desc": "Continuous Integration Build (latest in version control)", echo "Creating initial package-list.json..."
"path": "https://fhir.dghs.gov.bd/core/", cat > package-list.json << 'PKGEOF'
"status": "ci-build", {
"current": true "package-id": "bd.fhir.core",
} "title": "Bangladesh Core FHIR Implementation Guide",
] "canonical": "https://fhir.dghs.gov.bd/core",
} "introduction": "The Bangladesh Core FHIR IG defines national base profiles, value sets, and extensions for health data interoperability.",
PKGEOF "list": [
fi {
"version": "current",
# For release builds, add the new version entry "desc": "Continuous Integration Build (latest in version control)",
if [ "$BUILD_TYPE" == "release" ]; then "path": "https://fhir.dghs.gov.bd/core/",
echo "📝 Adding version $VERSION to package-list.json..." "status": "ci-build",
"current": true
python3 << PYEOF }
import json ]
import os }
PKGEOF
version = os.environ.get('VERSION', '') fi
date = os.environ.get('DATE', '')
python3 << 'PYEOF'
with open('package-list.json', 'r') as f: import json
pkg_list = json.load(f) import os
import sys
# Check if this version already exists
version_exists = any(e['version'] == version for e in pkg_list['list']) version = os.environ.get('VERSION', '')
date = os.environ.get('DATE', '')
if not version_exists: build_type = os.environ.get('BUILD_TYPE', '')
new_entry = {
"version": version, with open('package-list.json', 'r', encoding='utf-8') as f:
"date": date, pkg_list = json.load(f)
"desc": f"Release {version}",
"path": f"https://fhir.dghs.gov.bd/core/{version}/", if 'list' not in pkg_list or not isinstance(pkg_list['list'], list):
"status": "trial-use", print("ERROR: package-list.json does not contain a valid 'list' array")
"sequence": "STU 1" sys.exit(1)
}
# Insert after 'current' entry current_entries = [e for e in pkg_list['list'] if e.get('version') == 'current']
pkg_list['list'].insert(1, new_entry) if not current_entries:
pkg_list['list'].insert(0, {
with open('package-list.json', 'w') as f: "version": "current",
json.dump(pkg_list, f, indent=2) "desc": "Continuous Integration Build (latest in version control)",
"path": "https://fhir.dghs.gov.bd/core/",
print(f"✅ Added version {version} to package-list.json") "status": "ci-build",
else: "current": True
print(f" Version {version} already exists in package-list.json") })
PYEOF
else if build_type == 'release':
echo " Dev build - using existing package-list.json without modifications" version_exists = any(e.get('version') == version for e in pkg_list['list'])
fi if not version_exists:
new_entry = {
# Validate JSON syntax "version": version,
echo "🔍 Validating package-list.json..." "date": date,
python3 -m json.tool package-list.json > /dev/null && echo "✅ Valid JSON" || (echo "❌ Invalid JSON!" && exit 1) "desc": f"Release {version}",
"path": f"https://fhir.dghs.gov.bd/core/{version}/",
# Copy to input/ for IG Publisher "status": "trial-use",
echo "📂 Ensuring package-list.json is in required locations..." "sequence": "STU 1"
cp package-list.json input/package-list.json }
# Generate static history.xml from package-list.json insert_index = 1
echo "📝 Generating static history.xml from package-list.json..." for i, entry in enumerate(pkg_list['list']):
mkdir -p input/pagecontent if entry.get('version') == 'current':
insert_index = i + 1
python3 << 'PYEOF' break
import json
import os pkg_list['list'].insert(insert_index, new_entry)
print(f"✅ Added version {version} to package-list.json")
# Ensure directory exists else:
os.makedirs('input/pagecontent', exist_ok=True) print(f" Version {version} already exists in package-list.json")
else:
with open('package-list.json', 'r') as f: print(" Dev build - using existing package-list.json without release modification")
pkg_list = json.load(f)
with open('package-list.json', 'w', encoding='utf-8') as f:
# Generate static XHTML json.dump(pkg_list, f, indent=2, ensure_ascii=False)
xml = '''<?xml version="1.0" encoding="UTF-8"?> PYEOF
<div xmlns="http://www.w3.org/1999/xhtml">
<p><b>Version History</b></p> echo "🔍 Validating package-list.json..."
python3 -m json.tool package-list.json > /dev/null && echo "✅ Valid JSON" || (echo "❌ Invalid JSON!" && exit 1)
<p>This page provides the version history for the Bangladesh Core FHIR Implementation Guide.</p>
echo "📂 Ensuring package-list.json is in required locations..."
<p>For a machine-readable version history, see <a href="package-list.json">package-list.json</a>.</p> mkdir -p input
cp package-list.json input/package-list.json
<p><b>Published Versions</b></p>
echo "📝 Generating static history.xml from package-list.json..."
<table class="grid"> mkdir -p input/pagecontent
<thead>
<tr> python3 << 'PYEOF'
<th>Version</th> import json
<th>Date</th> import os
<th>Status</th> from html import escape
<th>Description</th>
</tr> os.makedirs('input/pagecontent', exist_ok=True)
</thead>
<tbody> with open('package-list.json', 'r', encoding='utf-8') as f:
''' pkg_list = json.load(f)
# Add each version (skip 'current') xml = '''<?xml version="1.0" encoding="UTF-8"?>
for entry in pkg_list['list']: <div xmlns="http://www.w3.org/1999/xhtml">
if entry['version'] == 'current': <p><b>Version History</b></p>
continue
<p>This page provides the version history for the Bangladesh Core FHIR Implementation Guide.</p>
version = entry.get('version', 'Unknown')
date = entry.get('date', 'N/A') <p>For a machine-readable version history, see <a href="package-list.json">package-list.json</a>.</p>
status = entry.get('status', 'unknown')
desc = entry.get('desc', '') <p><b>Published Versions</b></p>
path = entry.get('path', '#')
<table class="grid">
xml += f''' <tr> <thead>
<td><a href="{path}">{version}</a></td> <tr>
<td>{date}</td> <th>Version</th>
<td>{status}</td> <th>Date</th>
<td>{desc}</td> <th>Status</th>
</tr> <th>Description</th>
''' </tr>
</thead>
xml += ''' </tbody> <tbody>
</table> '''
<p><b>Continuous Integration Build</b></p> published_found = False
''' for entry in pkg_list['list']:
if entry.get('version') == 'current':
# Add CI build info continue
for entry in pkg_list['list']:
if entry['version'] == 'current': published_found = True
path = entry.get('path', '') version = escape(entry.get('version', 'Unknown'))
xml += f''' <p>The latest development build is available at: <a href="{path}">{path}</a></p> date = escape(entry.get('date', 'N/A'))
<p><i>Note: This is a continuous integration build and may be unstable.</i></p> status = escape(entry.get('status', 'unknown'))
''' desc = escape(entry.get('desc', ''))
break path = escape(entry.get('path', '#'))
xml += '''</div> xml += f''' <tr>
''' <td><a href="{path}">{version}</a></td>
<td>{date}</td>
with open('input/pagecontent/history.xml', 'w') as f: <td>{status}</td>
f.write(xml) <td>{desc}</td>
</tr>
print("✅ Generated static history.xml") '''
print(f" File location: {os.path.abspath('input/pagecontent/history.xml')}")
print(f" File size: {os.path.getsize('input/pagecontent/history.xml')} bytes") if not published_found:
PYEOF xml += ''' <tr>
<td colspan="4">No published versions available yet.</td>
# Verify the file was created </tr>
if [ -f "input/pagecontent/history.xml" ]; then '''
echo "✅ Verified: history.xml exists"
echo " First 20 lines:" xml += ''' </tbody>
head -20 input/pagecontent/history.xml </table>
else
echo "❌ ERROR: history.xml was not created!" <p><b>Continuous Integration Build</b></p>
exit 1 '''
fi
current_entry = None
echo "✅ Pre-build preparation complete:" for entry in pkg_list['list']:
echo " - Root: $(pwd)/package-list.json" if entry.get('version') == 'current':
echo " - Input: $(pwd)/input/package-list.json" current_entry = entry
echo " - History: $(pwd)/input/pagecontent/history.xml (generated)" break
- name: Install Docker CLI if current_entry:
run: | path = escape(current_entry.get('path', 'https://fhir.dghs.gov.bd/core/'))
apt-get update xml += f''' <p>The latest development build is available at: <a href="{path}">{path}</a></p>
apt-get install -y docker.io <p><i>Note: This is a continuous integration build and may be unstable.</i></p>
docker --version '''
else:
- name: Build FHIR IG xml += ''' <p><i>No CI build entry found in package-list.json.</i></p>
run: | '''
echo "Building FHIR IG version ${{ steps.version.outputs.version }}..."
xml += '''</div>
CONTAINER_ID=$(docker create \ '''
hl7fhir/ig-publisher-base:latest \
/bin/bash -c "cp -r /home/publisher/ig /tmp/build && cd /tmp/build && _updatePublisher.sh -y && _genonce.sh") with open('input/pagecontent/history.xml', 'w', encoding='utf-8') as f:
f.write(xml)
echo "Container ID: $CONTAINER_ID"
print("✅ Generated static history.xml")
docker cp $(pwd)/. $CONTAINER_ID:/home/publisher/ig/ print(f" File location: {os.path.abspath('input/pagecontent/history.xml')}")
docker start -a $CONTAINER_ID print(f" File size: {os.path.getsize('input/pagecontent/history.xml')} bytes")
EXIT_CODE=$? PYEOF
# Copy outputs if [ -f "input/pagecontent/history.xml" ]; then
echo "Copying outputs from container..." echo "✅ Verified: history.xml exists"
docker cp $CONTAINER_ID:/tmp/build/output ./output || echo "Warning: No output directory" echo " First 20 lines:"
docker cp $CONTAINER_ID:/tmp/build/fsh-generated ./fsh-generated || echo "No FSH generated" head -20 input/pagecontent/history.xml
docker cp $CONTAINER_ID:/tmp/build/input-cache ./input-cache || echo "No input-cache" else
docker cp $CONTAINER_ID:/tmp/build/temp ./temp || echo "No temp directory" echo "❌ ERROR: history.xml was not created!"
exit 1
if [ $EXIT_CODE -ne 0 ]; then fi
echo "Build failed, showing logs:"
docker logs $CONTAINER_ID echo "✅ Pre-build preparation complete:"
docker rm $CONTAINER_ID echo " - Root: $(pwd)/package-list.json"
exit 1 echo " - Input: $(pwd)/input/package-list.json"
fi echo " - History: $(pwd)/input/pagecontent/history.xml"
docker rm $CONTAINER_ID - name: Emergency Disk Cleanup
run: |
if [ ! -f "output/index.html" ]; then echo "Disk usage before:"
echo "ERROR: Build failed - no index.html" df -h
exit 1
fi echo "Clearing tool cache..."
rm -rf /opt/hostedtoolcache/* || true
# Check if history.html was generated
echo "" rm -rf /usr/share/dotnet || true
echo "🔍 Checking for history.html..." rm -rf /usr/local/lib/android || true
if [ -f "output/history.html" ]; then rm -rf /opt/ghc || true
echo "✅ history.html generated successfully!" rm -rf ~/.fhir/packages || true
echo "📄 history.html size: $(ls -lh output/history.html | awk '{print $5}')"
else echo "Disk usage after:"
echo "⚠️ WARNING: history.html was NOT generated" df -h
echo "This might indicate an issue with the template or history.xml"
fi - name: Install Docker CLI
run: |
echo "✅ Build successful!" apt-get update
apt-get install -y docker.io
- name: Update package-feed.xml for releases docker --version
if: steps.version.outputs.build_type == 'release'
run: | - name: Build FHIR IG
VERSION="${{ steps.version.outputs.version }}" run: |
DATETIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) echo "Building FHIR IG version ${{ steps.version.outputs.version }}..."
cat > update-feed.py << 'EOF' CONTAINER_ID=$(docker create \
import sys hl7fhir/ig-publisher-base:latest \
import xml.etree.ElementTree as ET /bin/bash -c "cp -r /home/publisher/ig /tmp/build && cd /tmp/build && _updatePublisher.sh -y && _genonce.sh")
version = sys.argv[1] echo "Container ID: $CONTAINER_ID"
datetime_iso = sys.argv[2]
docker cp "$(pwd)/." "$CONTAINER_ID:/home/publisher/ig/"
ET.register_namespace('', 'http://www.w3.org/2005/Atom') docker start -a "$CONTAINER_ID"
EXIT_CODE=$?
tree = ET.parse('package-feed.xml')
root = tree.getroot() echo "Copying outputs from container..."
ns = {'atom': 'http://www.w3.org/2005/Atom'} docker cp "$CONTAINER_ID:/tmp/build/output" ./output || echo "Warning: No output directory"
docker cp "$CONTAINER_ID:/tmp/build/fsh-generated" ./fsh-generated || echo "No FSH generated"
updated_elem = root.find('atom:updated', ns) docker cp "$CONTAINER_ID:/tmp/build/input-cache" ./input-cache || echo "No input-cache"
if updated_elem is not None: docker cp "$CONTAINER_ID:/tmp/build/temp" ./temp || echo "No temp directory"
updated_elem.text = datetime_iso
if [ $EXIT_CODE -ne 0 ]; then
entry_exists = False echo "Build failed, showing logs:"
for entry in root.findall('atom:entry', ns): docker logs "$CONTAINER_ID"
title = entry.find('atom:title', ns) docker rm "$CONTAINER_ID"
if title is not None and version in title.text: exit 1
entry_exists = True fi
entry_updated = entry.find('atom:updated', ns)
if entry_updated is not None: docker rm "$CONTAINER_ID"
entry_updated.text = datetime_iso
break if [ ! -f "output/index.html" ]; then
echo "ERROR: Build failed - no index.html"
if not entry_exists: exit 1
new_entry = ET.Element('{http://www.w3.org/2005/Atom}entry') fi
title = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}title') echo ""
title.text = f"bd.fhir.core version {version}" echo "🔍 Checking for history.html..."
if [ -f "output/history.html" ]; then
link = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}link') echo "✅ history.html generated successfully!"
link.set('rel', 'alternate') echo "📄 history.html size: $(ls -lh output/history.html | awk '{print $5}')"
link.set('href', f"https://fhir.dghs.gov.bd/core/{version}/") else
echo "⚠️ WARNING: history.html was NOT generated"
entry_id = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}id') echo "This might indicate an issue with the template or history.xml/package-list.json"
entry_id.text = f"https://fhir.dghs.gov.bd/core/{version}/" fi
entry_updated = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}updated') echo "✅ Build successful!"
entry_updated.text = datetime_iso
- name: Ensure registry files in output for dev builds
summary = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}summary') if: steps.version.outputs.build_type == 'dev'
summary.text = f"Release {version} of Bangladesh Core FHIR Implementation Guide" run: |
cp package-list.json output/package-list.json
insert_pos = 0 if [ -f "package-feed.xml" ]; then
for i, child in enumerate(root): cp package-feed.xml output/package-feed.xml
if child.tag.endswith('entry'): fi
insert_pos = i echo "📋 Copied registry files for dev artifact"
break
insert_pos = i + 1 - name: Update package-feed.xml for releases
if: steps.version.outputs.build_type == 'release'
root.insert(insert_pos, new_entry) run: |
VERSION="${{ steps.version.outputs.version }}"
tree.write('output/package-feed.xml', encoding='utf-8', xml_declaration=True) DATETIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
print(f"✅ Updated package-feed.xml")
EOF cat > update-feed.py << 'EOF'
import sys
python3 update-feed.py "$VERSION" "$DATETIME" import xml.etree.ElementTree as ET
# Also copy the updated package-list.json to output version = sys.argv[1]
cp package-list.json output/package-list.json datetime_iso = sys.argv[2]
echo "📋 Updated registry files" ET.register_namespace('', 'http://www.w3.org/2005/Atom')
- name: Prepare deployment artifact tree = ET.parse('package-feed.xml')
run: | root = tree.getroot()
VERSION="${{ steps.version.outputs.version }}" ns = {'atom': 'http://www.w3.org/2005/Atom'}
BUILD_TYPE="${{ steps.version.outputs.build_type }}"
updated_elem = root.find('atom:updated', ns)
tar -czf ig-output.tar.gz -C output . if updated_elem is not None:
updated_elem.text = datetime_iso
echo "version=$VERSION" > deployment.env
echo "build_type=$BUILD_TYPE" >> deployment.env entry_exists = False
echo "build_date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> deployment.env for entry in root.findall('atom:entry', ns):
title = entry.find('atom:title', ns)
echo "📦 Output contents:" if title is not None and version in (title.text or ''):
ls -lh output/ | grep -E "(history\.html|package-list\.json|package-feed\.xml|index\.html)" || echo "Some files may be missing" entry_exists = True
entry_updated = entry.find('atom:updated', ns)
ls -lh ig-output.tar.gz if entry_updated is not None:
entry_updated.text = datetime_iso
- name: Upload artifact break
uses: actions/upload-artifact@v3
with: if not entry_exists:
name: ig-output new_entry = ET.Element('{http://www.w3.org/2005/Atom}entry')
path: |
ig-output.tar.gz title = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}title')
deployment.env title.text = f"bd.fhir.core version {version}"
package-list.json
package-feed.xml link = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}link')
retention-days: 30 link.set('rel', 'alternate')
link.set('href', f"https://fhir.dghs.gov.bd/core/{version}/")
entry_id = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}id')
entry_id.text = f"https://fhir.dghs.gov.bd/core/{version}/"
entry_updated = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}updated')
entry_updated.text = datetime_iso
summary = ET.SubElement(new_entry, '{http://www.w3.org/2005/Atom}summary')
summary.text = f"Release {version} of Bangladesh Core FHIR Implementation Guide"
insert_pos = 0
for i, child in enumerate(root):
if child.tag.endswith('entry'):
insert_pos = i
break
insert_pos = i + 1
root.insert(insert_pos, new_entry)
tree.write('output/package-feed.xml', encoding='utf-8', xml_declaration=True)
print("✅ Updated package-feed.xml")
EOF
python3 update-feed.py "$VERSION" "$DATETIME"
cp package-list.json output/package-list.json
echo "📋 Updated registry files"
- name: Prepare deployment artifact
run: |
VERSION="${{ steps.version.outputs.version }}"
BUILD_TYPE="${{ steps.version.outputs.build_type }}"
tar -czf ig-output.tar.gz -C output .
echo "version=$VERSION" > deployment.env
echo "build_type=$BUILD_TYPE" >> deployment.env
echo "build_date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> deployment.env
echo "📦 Output contents:"
ls -lh output/ | grep -E "(history\.html|package-list\.json|package-feed\.xml|index\.html)" || echo "Some files may be missing"
ls -lh ig-output.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ig-output
path: |
ig-output.tar.gz
deployment.env
package-list.json
package-feed.xml
retention-days: 30
deploy: deploy:
needs: build-ig needs: build-ig
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
steps: steps:
- name: Download artifact - name: Download artifact
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: ig-output name: ig-output
- name: Load deployment env - name: Load deployment env
id: deploy_info id: deploy_info
run: | run: |
source deployment.env source deployment.env
echo "version=$version" >> $GITHUB_OUTPUT echo "version=$version" >> $GITHUB_OUTPUT
echo "build_type=$build_type" >> $GITHUB_OUTPUT echo "build_type=$build_type" >> $GITHUB_OUTPUT
echo "build_date=$build_date" >> $GITHUB_OUTPUT echo "build_date=$build_date" >> $GITHUB_OUTPUT
echo "Deploying version: $version" echo "Deploying version: $version"
echo "Build type: $build_type" echo "Build type: $build_type"
- name: Deploy to server - name: Deploy to server
uses: appleboy/scp-action@v0.1.7 uses: appleboy/scp-action@v0.1.7
with: with:
host: ${{ secrets.DEPLOY_HOST }} host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }} username: ${{ secrets.DEPLOY_USER }}
password: ${{ secrets.DEPLOY_PASSWORD }} password: ${{ secrets.DEPLOY_PASSWORD }}
port: ${{ secrets.DEPLOY_PORT || 22 }} port: ${{ secrets.DEPLOY_PORT || 22 }}
source: "ig-output.tar.gz,deployment.env,package-list.json,package-feed.xml" source: "ig-output.tar.gz,deployment.env,package-list.json,package-feed.xml"
target: "/tmp/fhir-ig-deploy/" target: "/tmp/fhir-ig-deploy/"
- name: Execute deployment on server - name: Execute deployment on server
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
with: with:
host: ${{ secrets.DEPLOY_HOST }} host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }} username: ${{ secrets.DEPLOY_USER }}
password: ${{ secrets.DEPLOY_PASSWORD }} password: ${{ secrets.DEPLOY_PASSWORD }}
port: ${{ secrets.DEPLOY_PORT || 22 }} port: ${{ secrets.DEPLOY_PORT || 22 }}
script: | script: |
set -e set -e
source /tmp/fhir-ig-deploy/deployment.env source /tmp/fhir-ig-deploy/deployment.env
echo "==========================================" echo "=========================================="
echo "Deploying FHIR IG" echo "Deploying FHIR IG"
echo "Version: $version" echo "Version: $version"
echo "Build Type: $build_type" echo "Build Type: $build_type"
echo "Build Date: $build_date" echo "Build Date: $build_date"
echo "==========================================" echo "=========================================="
VERSIONS_DIR="/opt/fhir-ig/versions" VERSIONS_DIR="/opt/fhir-ig/versions"
mkdir -p "$VERSIONS_DIR" mkdir -p "$VERSIONS_DIR"
TARGET_DIR="$VERSIONS_DIR/$version" if [ "$build_type" = "release" ]; then
echo "📦 Deploying release version to: $TARGET_DIR" TARGET_DIR="$VERSIONS_DIR/$version"
echo "📦 Deploying release version to: $TARGET_DIR"
else
TARGET_DIR="$VERSIONS_DIR/dev"
echo "🔧 Deploying dev build to: $TARGET_DIR"
mkdir -p "$TARGET_DIR"
echo "Cleaning old dev files..."
rm -rf "$TARGET_DIR"/*
fi
mkdir -p "$TARGET_DIR" mkdir -p "$TARGET_DIR"
echo "Extracting IG output..." echo "Extracting IG output..."
tar -xzf /tmp/fhir-ig-deploy/ig-output.tar.gz -C "$TARGET_DIR" tar -xzf /tmp/fhir-ig-deploy/ig-output.tar.gz -C "$TARGET_DIR"
# Verify history.html was deployed if [ -f "$TARGET_DIR/history.html" ]; then
if [ -f "$TARGET_DIR/history.html" ]; then echo "✅ history.html deployed successfully"
echo "✅ history.html deployed successfully" else
else echo "⚠️ WARNING: history.html not found in deployment"
echo "⚠️ WARNING: history.html not found in deployment" fi
fi
cp /tmp/fhir-ig-deploy/package-list.json "$VERSIONS_DIR/package-list.json" cp /tmp/fhir-ig-deploy/package-list.json "$VERSIONS_DIR/package-list.json"
cp /tmp/fhir-ig-deploy/package-feed.xml "$VERSIONS_DIR/package-feed.xml" cp /tmp/fhir-ig-deploy/package-feed.xml "$VERSIONS_DIR/package-feed.xml"
echo "Updating 'current' symlink to point to $version" if [ "$build_type" = "release" ]; then
rm -f "$VERSIONS_DIR/current" echo "Updating 'current' symlink to point to $version"
ln -sf "$version" "$VERSIONS_DIR/current" rm -f "$VERSIONS_DIR/current"
ln -sf "$version" "$VERSIONS_DIR/current"
fi
cd /opt/fhir-ig cd /opt/fhir-ig
if [ ! -f "docker-compose.prod.yml" ]; then if [ ! -f "docker-compose.prod.yml" ]; then
echo "ERROR: docker-compose.prod.yml not found!" echo "ERROR: docker-compose.prod.yml not found!"
exit 1 echo "Please deploy the updated docker-compose.prod.yml and nginx.conf first"
fi exit 1
fi
docker compose -f docker-compose.prod.yml restart fhir-ig || \ docker compose -f docker-compose.prod.yml up -d --force-recreate fhir-ig
docker compose -f docker-compose.prod.yml up -d
rm -rf /tmp/fhir-ig-deploy rm -rf /tmp/fhir-ig-deploy
echo "==========================================" echo "=========================================="
echo "✅ Deployment completed successfully!" echo "✅ Deployment completed successfully!"
echo "Version $version is now available at:" echo "Version $version is now available at:"
echo " - https://fhir.dghs.gov.bd/core/$version/" if [ "$build_type" = "release" ]; then
echo " - https://fhir.dghs.gov.bd/core/$version/history.html" echo " - https://fhir.dghs.gov.bd/core/$version/"
echo " - https://fhir.dghs.gov.bd/core/ (current)" echo " - https://fhir.dghs.gov.bd/core/$version/history.html"
echo "==========================================" echo " - https://fhir.dghs.gov.bd/core/ (current)"
else
echo " - https://fhir.dghs.gov.bd/core/dev/"
fi
echo "=========================================="
echo "Available versions:" echo "Available versions:"
ls -lh "$VERSIONS_DIR" | grep -v total ls -lh "$VERSIONS_DIR" | grep -v total