Skip to content

Commit

Permalink
Better handling of trigger events in docs CI (#4094)
Browse files Browse the repository at this point in the history
Signed-off-by: EduPonz <[email protected]>
  • Loading branch information
EduPonz authored Dec 4, 2023
1 parent 41f7627 commit e8464b6
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions .github/workflows/documentation-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ name: Documentation build and test
on:
workflow_dispatch:
inputs:
optional_documentation_branch:
description: 'Optional Documentation branch name'
required: false
documentation_branch:
description: 'Documentation branch name'
required: true
type: string
default: '2.11.x'

push:
branches:
Expand All @@ -28,7 +29,7 @@ concurrency:
cancel-in-progress: true

env:
ACTION_BRANCH_NAME: ${{ github.head_ref }}
ACTION_BRANCH_NAME: ${{ github.ref }}

jobs:
ubuntu-build-and-test-documentation:
Expand Down Expand Up @@ -58,36 +59,56 @@ jobs:
- name: Determine the Fast DDS Documentation branch to be used
run: |
TEMP_BRANCH=${{ inputs.optional_documentation_branch }}
DOC_REPO=https://github.com/eProsima/fast-dds-docs.git
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO $TEMP_BRANCH | wc -l)
if [[ -z "$TEMP_BRANCH" || ${RESPONSE_CODE} == "0" ]]
if [[ ${{ github.event_name }} == "push" ]]
then
echo "ACTION_BRANCH_NAME=${{ github.ref }}" >> $GITHUB_ENV
echo "Push event: using pushed branch '${{ github.ref }}' for docs repository"
elif [[ ${{ github.event_name }} == "workflow_dispatch" ]]
then
echo "ACTION_BRANCH_NAME=${{ inputs.documentation_branch }}" >> $GITHUB_ENV
echo "Workflow dispatch event: using input branch '${{ inputs.documentation_branch }}' for docs repository"
elif [[ ${{ github.event_name }} == "pull_request" ]]
then
DOCS_REPO=https://github.com/eProsima/fast-dds-docs.git
# Attempt to use PR's source branch
TEMP_BRANCH=${{ github.head_ref }}
echo "$given '${{ inputs.optional_documentation_branch }}' branch DOES NOT exist, using head '${{ github.head_ref }}'"
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO $TEMP_BRANCH | wc -l)
RESPONSE_CODE=$(git ls-remote --heads $DOCS_REPO $TEMP_BRANCH | wc -l)
if [[ ${RESPONSE_CODE} == "0" ]]
then
echo "PR source branch '$TEMP_BRANCH' branch DOES NOT exist in $DOCS_REPO"
# Attempt to use PR's base branch
TEMP_BRANCH=${{ github.base_ref }}
echo "head '${{ github.head_ref }}' branch DOES NOT exist, using base '${{ github.base_ref }}'"
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO $TEMP_BRANCH | wc -l)
RESPONSE_CODE=$(git ls-remote --heads $DOCS_REPO $TEMP_BRANCH | wc -l)
if [[ ${RESPONSE_CODE} == "0" ]]
then
echo "ACTION_BRANCH_NAME=2.11.x" >> $GITHUB_ENV
echo "base '${{ github.base_ref }}' branch DOES NOT exist, using '2.11.x'"
else
echo "ACTION_BRANCH_NAME=${{ github.base_ref }}" >> $GITHUB_ENV
echo "PR base branch '$TEMP_BRANCH' branch DOES NOT exist in $DOCS_REPO"
# Attempt to use version's branch, which will most likely be the base anyways.
# This is just in case the PR was to an intermediate branch
TEMP_BRANCH=2.11.x
RESPONSE_CODE=$(git ls-remote --heads $DOCS_REPO $TEMP_BRANCH | wc -l)
if [[ ${RESPONSE_CODE} == "0" ]]
then
# There are no more fallbacks, so we need to fail here
echo "Version branch '$TEMP_BRANCH' branch DOES NOT exist in $DOCS_REPO"
exit 1
fi
fi
else
echo "ACTION_BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
fi
else
echo "ACTION_BRANCH_NAME=${{ inputs.optional_documentation_branch }}" >> $GITHUB_ENV
echo "using given '${{ inputs.optional_documentation_branch }}' branch"
echo "ACTION_BRANCH_NAME=$TEMP_BRANCH" >> $GITHUB_ENV
echo "PR event: using deduced branch '$TEMP_BRANCH' for docs repository"
fi
- name: Download FastDDS documentation repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: eProsima/Fast-DDS-docs
path: src/fastdds-docs
Expand Down

0 comments on commit e8464b6

Please sign in to comment.