Skip to content

Update Publisher

Update Publisher #50

name: Update Publisher
on:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
packages: write
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
has_update: ${{ steps.compare_versions.outputs.has_update == 'true' && steps.check_pr.outputs.existing_pr != 'true' }}
latest_release: ${{ steps.compare_versions.outputs.latest_release }}
steps:
- uses: actions/checkout@v4
- name: Get latest HL7 release
run: |
LATEST_RELEASE=$(
curl -sL \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/HL7/fhir-ig-publisher/releases/latest \
| jq -r .tag_name
)
echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_ENV
- name: Print latest release
run: |
echo "Latest release: $LATEST_RELEASE"
- name: Get current container version
id: get_current_version
run: |
CURRENT_VERSION=$(grep "container:" .github/workflows/qa-report.yaml | sed -E 's|.*:([0-9]+\.[0-9]+\.[0-9]+).*|\1|')
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
run: |
echo "Latest: $LATEST_RELEASE"
echo "Current: $CURRENT_VERSION"
echo "latest_release=$LATEST_RELEASE" >> "$GITHUB_OUTPUT"
if [ "$LATEST_RELEASE" = "$CURRENT_VERSION" ]; then
echo "has_update=false" >> "$GITHUB_OUTPUT"
echo "Versions are identical. Skipping update."
else
echo "has_update=true" >> "$GITHUB_OUTPUT"
echo "New version found. Continuing."
fi
- name: Check for existing pull request
id: check_pr
if: steps.compare_versions.outputs.has_update == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_COUNT=$(gh pr list \
--state open \
--search "Update publisher to $LATEST_RELEASE" \
--json number \
--jq 'length')
echo "Existing PRs: $PR_COUNT"
if [ "$PR_COUNT" -gt 0 ]; then
echo "An open PR already exists."
echo "existing_pr=true" >> $GITHUB_OUTPUT
else
echo "No open PR exists."
echo "existing_pr=false" >> "$GITHUB_OUTPUT"
fi
update-publisher:
needs: check-version
if: needs.check-version.outputs.has_update == 'true'
runs-on: ubuntu-latest
env:
LATEST_RELEASE: ${{ needs.check-version.outputs.latest_release }}
APP_AUTHOR_NAME: ${{ github.triggering_actor }}
APP_AUTHOR_EMAIL: "fhir@medcom.dk"
steps:
- uses: actions/checkout@v4
- name: Generate app token
id: token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.FHIR_PUBLICATION_BOT_APP_ID }}
private-key: ${{ secrets.PUBLISHER_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: fhir-publishing
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & push Docker image
uses: docker/build-push-action@v5
with:
push: true
build-args: |
IG_PUB_VERSION=${{ env.LATEST_RELEASE }}
tags: ghcr.io/medcomdk/medcom-github-actions-container:${{ env.LATEST_RELEASE }}
- name: Update qa-report.yaml workflow with latest publisher version
run: |
echo "Updating qa-report.yaml with latest publisher version: ${LATEST_RELEASE}"
sed -i -E \
"s|(container:[[:space:]]+[^[:space:]]+):[^[:space:]]+|\1:${LATEST_RELEASE}|" \
./.github/workflows/qa-report.yaml
- name: Verify qa-report.yaml update
run: |
grep -q "container:.*${LATEST_RELEASE}" ./.github/workflows/qa-report.yaml
- name: Update publish.yaml workflow with latest publisher version
run: |
echo "Updating publish.yaml with latest publisher version: ${LATEST_RELEASE}"
sed -i -E \
"s|(container:[[:space:]]+[^[:space:]]+):[^[:space:]]+|\1:${LATEST_RELEASE}|" \
./.github/workflows/publish.yaml
- name: Verify publish.yaml update
run: |
grep -q "container:.*${LATEST_RELEASE}" ./.github/workflows/publish.yaml
- name: Configure Git
run: |
git config --global user.name "${{ env.APP_AUTHOR_NAME }}"
git config --global user.email "${{ env.APP_AUTHOR_EMAIL }}"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ steps.token.outputs.token }}
commit-message: "Update publisher to ${{ env.LATEST_RELEASE }}"
branch: "update-publisher-${{ env.LATEST_RELEASE }}-run-${{ github.run_number }}"
title: "Update publisher to ${{ env.LATEST_RELEASE }}"
body: |
This PR was automatically generated by the Update Publisher workflow.
Publisher version: ${{ env.LATEST_RELEASE }}
base: main