From 915e5449ee444119760ea62d866532aef24dc188 Mon Sep 17 00:00:00 2001 From: Winford Date: Thu, 15 Aug 2024 13:14:24 -0700 Subject: [PATCH] Fix publish docs for branches There was a bug in the tests for GitHub environment variables that led to the build system using the push rule rather than the merge rule for determining the branch name, in this case using an undefined environment variable which resulted in an empty branch name. Determining the correct branch or tag name from within cmake using GitHub environment variables is unreliable, so instead the correct name is determined by the workflows, which set an environment variable that can be used by cmake. Signed-off-by: Winford --- .github/workflows/build-docs.yaml | 9 +++++++++ .github/workflows/publish-docs.yaml | 3 +++ doc/CMakeLists.txt | 11 ++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml index 9883a5d54..e2c20908e 100644 --- a/.github/workflows/build-docs.yaml +++ b/.github/workflows/build-docs.yaml @@ -77,6 +77,15 @@ jobs: python3 -m pip install breathe python3 -m pip install pygments + - name: Set docs target name + shell: bash + run: | + if [[ ${{ github.ref_name }} == *"/merge" ]]; then + echo "AVM_DOCS_NAME=${{github.event.pull_request.base.ref}}" >> "$GITHUB_ENV"; + else + echo "AVM_DOCS_NAME=${{ github.ref_name }}" >> "$GITHUB_ENV"; + fi + - uses: actions/checkout@v4 with: repository: ${{ vars.GITHUB_REPOSITORY }} diff --git a/.github/workflows/publish-docs.yaml b/.github/workflows/publish-docs.yaml index 8b599e075..ff8e52f9e 100644 --- a/.github/workflows/publish-docs.yaml +++ b/.github/workflows/publish-docs.yaml @@ -38,6 +38,9 @@ jobs: # The type of runner that the job will run on runs-on: ubuntu-latest + env: + AVM_DOCS_NAME: ${{ github.ref_name }} + # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index e03a1e418..9367cd5cb 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -58,16 +58,13 @@ add_custom_target(edown-escript # Get the version tree name, tag if this is a tagged commit, otherwise get the current branch name. if ($ENV{CI}) - if (NOT (DEFINED ENV{GITHUB_BASE_REF}) AND ($ENV{GITHUB_REPOSITORY} STREQUAL "atomvm/AtomVM")) - set(DOC_TREE_VERSION $ENV{GITHUB_REF_NAME}) - message("CI Publishing documentation for ${DOC_TREE_VERSION}") - elseif ($ENV{GITHUB_REPOSITORY} STREQUAL "atomvm/AtomVM") - set(DOC_TREE_VERSION $ENV{GITHUB_HEAD_REF}) - message("CI Test building documentation for ${DOC_TREE_VERSION}") + if ($ENV{GITHUB_REPOSITORY} STREQUAL "atomvm/AtomVM") + set(DOC_TREE_VERSION $ENV{AVM_DOCS_NAME}) + message("CI building documentation for target branch ${DOC_TREE_VERSION}") else() set(DOC_TREE_VERSION $ENV{GITHUB_REF_NAME}) message("CI Test building documentation for $ENV{GITHUB_REPOSITORY} on branch ${DOC_TREE_VERSION}") - endif (NOT (DEFINED ENV{GITHUB_BASE_REF}) AND ($ENV{GITHUB_REPOSITORY} STREQUAL "atomvm/AtomVM")) + endif ($ENV{GITHUB_REPOSITORY} STREQUAL "atomvm/AtomVM") else() execute_process(COMMAND "bash" "-c" "tag=$(git for-each-ref --points-at=HEAD --format='%(refname:lstrip=2)' refs/tags); ( [ $tag ] && echo $tag )|| git branch --show-current" OUTPUT_VARIABLE