From f95195d4d5cfe1a6334580bc52fb811258a96256 Mon Sep 17 00:00:00 2001 From: Alessandro Domanico Date: Wed, 30 Oct 2024 13:07:41 +0100 Subject: [PATCH] workflow: generalize http response (#491) * Try to get pull-requests branches from fork * Fix fetch from origin * Debug remote and branch names * Fix no-single-branch * Adjust commit history depth * Clean workflow * Adjust openapi workflow * Add further checks and debug * Apply to openapi workflow * Update oh.yaml * Workaround logic, as it seems that GitHub variables are fickle * Generalize HTTP response * Apply to openapi.yml * Check if fork AND branch exists before to fallback * Apply to openapi.yml * Re-enable API tests --- .github/workflows/maven.yml | 4 ++-- .github/workflows/openapi.yml | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d5b64dc6..88f356ae 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -37,7 +37,7 @@ jobs: # Determine FORK_REPO with fallback logic if [[ -n "${GITHUB_HEAD_REPOSITORY}" ]]; then echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY}" >> $GITHUB_ENV - elif curl -s --head https://github.com/${GITHUB_ACTOR}/openhospital-core | grep "200 OK" > /dev/null; then + elif curl -s --head https://github.com/${GITHUB_ACTOR}/openhospital-core/tree/${BRANCH_NAME} | grep "HTTP/[12].* 2[0-9][0-9]" > /dev/null; then echo "FORK_REPO=${GITHUB_ACTOR}/openhospital-core" >> $GITHUB_ENV else echo "FORK_REPO=informatici/openhospital-core" >> $GITHUB_ENV @@ -69,4 +69,4 @@ jobs: popd - name: Build with Maven - run: mvn install -DskipTests=true + run: mvn install diff --git a/.github/workflows/openapi.yml b/.github/workflows/openapi.yml index 8790404c..8d508981 100644 --- a/.github/workflows/openapi.yml +++ b/.github/workflows/openapi.yml @@ -29,22 +29,20 @@ jobs: - name: Determine PR source branch and fork repository id: vars run: | - # Get branch name from either pull_request or push context + # Set BRANCH_NAME based on event type if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then - # Get branch and fork repo for PR events echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> $GITHUB_ENV - echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY:-informatici/openhospital-core}" >> $GITHUB_ENV - elif [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then - # Get branch name for push events + else echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV + fi - # Default FORK_REPO to main repository, with option to fallback if the fork exists - OWNER=${GITHUB_ACTOR} - if curl -s -o /dev/null -w "%{http_code}" "https://api.github.com/repos/${OWNER}/openhospital-core/branches/${GITHUB_REF##*/}" | grep -q "200"; then - echo "FORK_REPO=${OWNER}/openhospital-core" >> $GITHUB_ENV - else - echo "FORK_REPO=informatici/openhospital-core" >> $GITHUB_ENV - fi + # Determine FORK_REPO with fallback logic + if [[ -n "${GITHUB_HEAD_REPOSITORY}" ]]; then + echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY}" >> $GITHUB_ENV + elif curl -s --head https://github.com/${GITHUB_ACTOR}/openhospital-core/tree/${BRANCH_NAME} | grep "HTTP/[12].* 2[0-9][0-9]" > /dev/null; then + echo "FORK_REPO=${GITHUB_ACTOR}/openhospital-core" >> $GITHUB_ENV + else + echo "FORK_REPO=informatici/openhospital-core" >> $GITHUB_ENV fi - name: Log variables