Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pelican/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,24 @@ runs:
if: ${{ inputs.gfm == 'true' }}
shell: bash
env:
WORKDIR: /opt/pelican-asf # where to build GFM
GFM_VERSION: '0.28.3.gfm.12' # ensure we agree with build-cmark.sh script
run: |
if [[ -z $LIBCMARKDIR ]] # define LIBCMARKDIR if it is not already
then
# set up the GFM environment
export LIBCMARKDIR=/opt/pelican-asf/gfm-${GFM_VERSION} # arbitrary, but should contain version
mkdir -p $LIBCMARKDIR
echo "LIBCMARKDIR=${LIBCMARKDIR}" >>$GITHUB_ENV # needed for the build step
fi

# Does the GFM build already exist?
if [[ -n $LIBCMARKDIR && -d $LIBCMARKDIR ]]
if [[ -f $LIBCMARKDIR/libcmark-gfm.so ]]
then
echo "Already have GFM binary at $LIBCMARKDIR, skipping build"
exit 0 # nothing more to do in this step
fi
{
echo "Creating GFM binary in ${LIBCMARKDIR}"
# disable stdout unless debug is on
if [ "${{ inputs.debug }}" == 'true' ]
then
Expand All @@ -78,15 +86,8 @@ runs:
else
exec >/dev/null
fi
# Don't pollute site checkout
mkdir -p $WORKDIR
pushd $WORKDIR
# build the code and define LIBCMARKDIR
bash ${{ github.action_path }}/build-cmark.sh $GFM_VERSION | grep "export LIBCMARKDIR" >/tmp/libcmarkdir.$$
source /tmp/libcmarkdir.$$
popd
# ensure LIBCMARKDIR is defined for subsequent steps
echo "LIBCMARKDIR=${LIBCMARKDIR}" >> $GITHUB_ENV
# build the code and define LIBCMARKDIR under $WORKDIR
bash ${{ github.action_path }}/build-cmark.sh $GFM_VERSION $LIBCMARKDIR
Copy link

@jsoref jsoref Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a $GITHUB_ACTION_PATH which you should generally use (and you should never use ${{ ... }} inside a run: block)

}

- name: Generate website from markdown
Expand Down
61 changes: 25 additions & 36 deletions pelican/build-cmark.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
#!/bin/bash
#
# Build the cmark-gfm library and extensions within CURRENT DIRECTORY.
# Build the cmark-gfm library and extensions in a temporary directory
#
# The binary output will be under: cmark-gfm-$VERSION/lib
# The binary output will be under: LIBCMARKDIR
#
# USAGE:
# $ build-cmark.sh [ VERSION [ TARDIR ] ]
# $ build-cmark.sh VERSION LIBCMARKDIR [TARFILE]
#
# VERSION: defaults to 0.28.3.gfm.12
# TARDIR: where to find a downloaded/cached tarball of the cmark
# code, or where to place a tarball
# VERSION: e.g. 0.28.3.gfm.12
# LIBCMARKDIR: where to put the binary library files
# TARFILE: local copy of the tarfile; must be for the correct version! (optional)
#

# Echo all of our steps if DEBUG_STEPS is set
test -n "$DEBUG_STEPS" && set -x

set -e # early exit if any step fails

#VERSION=0.28.3.gfm.20 ### not yet
VERSION=0.28.3.gfm.12
if [ "$1" != "" ]; then VERSION="$1"; fi

# The tarball exists here, or will be downloaded here.
TARDIR="."
if [ "$2" != "" ]; then TARDIR="$2"; fi
VERSION=${1:?version}
LIBCMARKDIR=${2:?library output}
TARFILE=$3

ARCHIVES="https://github.com/github/cmark-gfm/archive/refs/tags"
LOCAL="${TARDIR}/cmark-gfm.$VERSION.orig.tar.gz"
TARNAME="cmark-gfm.$VERSION.orig.tar.gz"
TARDIR="cmark-gfm-$VERSION"

# WARNING: this must agree with the parent directory in the tar file or the build will fail
EXTRACTED_AS="cmark-gfm-$VERSION"
# Work in a temporary directory
TEMP=$(mktemp -d)

# Follow redirects, and place the result into known name $LOCAL
if [ -f "$LOCAL" ]; then
echo "Using cached tarball: ${LOCAL}" >&2
if [[ -f $TARFILE ]]
then
echo "Found tar!"
cp $TARFILE $TEMP # do this before cd to allow for relative paths
cd $TEMP
else
echo "Fetching $VERSION from cmark archives" >&2
curl -sSL --fail -o "$LOCAL" "$ARCHIVES/$VERSION.tar.gz"
cd $TEMP
echo "Fetching $VERSION from cmark archives" >&2
curl -sSL --fail -o "$TARNAME" "$ARCHIVES/$VERSION.tar.gz"
fi

# Clean anything old, then extract and build.
### somebody smart could peek into the .tgz. ... MEH
if [ -d "$EXTRACTED_AS" ]; then rm -r "$EXTRACTED_AS"; fi
tar xzf "$LOCAL"
pushd "$EXTRACTED_AS" >/dev/null
tar xzf "$TARNAME"
pushd "$TARDIR" >/dev/null
mkdir build
pushd build >/dev/null
cmake --version >&2
Expand All @@ -53,14 +50,6 @@ pushd "$EXTRACTED_AS" >/dev/null
} > build.log
popd >/dev/null

mkdir lib
cp -Pp build/src/lib* lib/
cp -Pp build/extensions/lib* lib/
cp -Pp build/src/lib* ${LIBCMARKDIR}/
cp -Pp build/extensions/lib* ${LIBCMARKDIR}/
popd >/dev/null

# These files/dir may need a reference with LD_LIBRARY_PATH.
# gfm.py wants this lib/ in LIBCMARKDIR.
# ls -laF "$EXTRACTED_AS/lib/"

# Provide a handy line for copy/paste.
echo "export LIBCMARKDIR='$(pwd)/$EXTRACTED_AS/lib'"