Skip to content

Commit

Permalink
Fix publish docs for branches
Browse files Browse the repository at this point in the history
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 <winford@object.stream>
  • Loading branch information
UncleGrumpy committed Aug 15, 2024
1 parent a239060 commit 792c342
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.base_ref }} ]]; then
echo "AVM_DOCS_NAME=${{ github.base_ref }}" >> "$GITHUB_ENV"
else
echo "AVM_DOCS_NAME=${{ github.ref_name }}" >> "$GITHUB_ENV"
fi
- uses: actions/checkout@v4
with:
repository: ${{ vars.GITHUB_REPOSITORY }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ name: Publish Docs
on:
# Triggers the workflow on pull request, tag events and pushes on main
push:
repositories:
- 'atomvm/AtomVM'
tags:
- '**'
branches:
Expand All @@ -38,6 +40,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
Expand Down
11 changes: 4 additions & 7 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 792c342

Please sign in to comment.