Skip to content

Commit

Permalink
workflow: get fork and branch upon pull_request and push events (#489)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mwithi authored Oct 29, 2024
1 parent 80f445d commit 60bc04e
Show file tree
Hide file tree
Showing 3 changed files with 472 additions and 411 deletions.
33 changes: 31 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,40 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Debug GitHub variables
run: |
echo "GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}"
echo "GITHUB_HEAD_REPOSITORY: ${GITHUB_HEAD_REPOSITORY}"
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}"
echo "GITHUB_REF: ${GITHUB_REF}"
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}"
- name: Determine PR source branch and fork repository
id: vars
run: |
echo "BRANCH_NAME=${GITHUB_HEAD_REF:-develop}" >> $GITHUB_ENV
echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY:-informatici/openhospital-core}" >> $GITHUB_ENV
# Get branch name from either pull_request or push context
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
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
# 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
fi
- name: Log variables
run: |
echo "FORK_REPO: ${{ env.FORK_REPO }}"
echo "BRANCH_NAME: ${{ env.BRANCH_NAME }}"
- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
33 changes: 31 additions & 2 deletions .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,40 @@ jobs:
with:
persist-credentials: false

- name: Debug GitHub variables
run: |
echo "GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}"
echo "GITHUB_HEAD_REPOSITORY: ${GITHUB_HEAD_REPOSITORY}"
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}"
echo "GITHUB_REF: ${GITHUB_REF}"
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}"
- name: Determine PR source branch and fork repository
id: vars
run: |
echo "BRANCH_NAME=${GITHUB_HEAD_REF:-develop}" >> $GITHUB_ENV
echo "FORK_REPO=${GITHUB_HEAD_REPOSITORY:-informatici/openhospital-core}" >> $GITHUB_ENV
# Get branch name from either pull_request or push context
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
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
# 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
fi
- name: Log variables
run: |
echo "FORK_REPO: ${{ env.FORK_REPO }}"
echo "BRANCH_NAME: ${{ env.BRANCH_NAME }}"
- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
Loading

0 comments on commit 60bc04e

Please sign in to comment.