Skip to content

Commit

Permalink
chore: install pandoc in codegen (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
whynowy authored Jul 13, 2024
1 parent 54a5f77 commit 3bc753c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ jobs:
run: |
echo /home/runner/go/bin >> $GITHUB_PATH
echo /usr/local/bin >> $GITHUB_PATH
- name: Install pandoc
run: |
set -eux -o pipefail
PANDOC_VERSION=3.2.1
PANDOC_ZIP=pandoc-$PANDOC_VERSION-linux-amd64.tar.gz
curl -OL https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/$PANDOC_ZIP
sudo tar xvzf $PANDOC_ZIP --strip-components 1 -C /usr/local
rm -f $PANDOC_ZIP
echo /usr/local/pandoc-$PANDOC_VERSION/bin >> $GITHUB_PATH
- name: Get dependencies
run: go mod download
- name: Make codegen
Expand Down
17 changes: 2 additions & 15 deletions hack/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,15 @@ ensure_vendor() {
go mod vendor
}

# TODO: Install it in Makefile
ensure_pandoc() {
if [ "`command -v pandoc`" = "" ]; then
warning "Please install pandoc with - brew install pandoc"
exit 1
fi

if [ "`pandoc -v | head -1 | awk '{print $2}'`" != "3.2.1" ]; then
warning "Please upgrade pandoc to version 3.2.1 with - brew upgrade pandoc"
exit 1
fi
}

ensure_node(){
if [ "`command -v node`" = "" ]; then
if [[ "`command -v node`" = "" ]]; then
warning "Please install node with - brew install node"
exit 1
fi
}

ensure_yarn(){
if [ "`command -v yarn`" = "" ]; then
if [[ "`command -v yarn`" = "" ]]; then
warning "Please install yarn with - brew install yarn"
exit 1
fi
Expand Down
54 changes: 51 additions & 3 deletions hack/update-api-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set -o pipefail
source $(dirname $0)/library.sh
header "updating api docs"

ensure_pandoc
ensure_vendor
make_fake_paths

Expand All @@ -24,9 +23,58 @@ go run ${FAKE_REPOPATH}/vendor/github.com/ahmetb/gen-crd-api-reference-docs/main
-out-file "${FAKE_REPOPATH}/docs/APIs.html" \
-template-dir "${FAKE_REPOPATH}/hack/api-docs-template"

# Setup - https://pandoc.org/installing.html
install-pandoc() {
# pandoc version
PANDOC_VERSION=3.2.1

pandoc --from markdown --to gfm ${FAKE_REPOPATH}/docs/APIs.html > ${FAKE_REPOPATH}/docs/APIs.md
if [[ "`command -v pandoc`" != "" ]]; then
if [[ "`pandoc -v | head -1 | awk '{print $2}'`" != "${PANDOC_VERSION}" ]]; then
warning "Existing pandoc version does not match the requirement (${PANDOC_VERSION}), will download a new one..."
else
PANDOC_BINARY="`command -v pandoc`"
return
fi
fi

PD_REL="https://github.com/jgm/pandoc/releases"
OS=$(uname_os)
ARCH=$(uname_arch)

echo "OS: $OS ARCH: $ARCH"

BINARY_NAME="pandoc-${PANDOC_VERSION}-${OS}-${ARCH}.zip"
if [[ "$OS" = "darwin" ]]; then
if [[ "$ARCH" = "arm64" ]]; then
BINARY_NAME="pandoc-${PANDOC_VERSION}-arm64-macOS.zip"
elif [[ "$ARCH" = "amd64" ]]; then
BINARY_NAME="pandoc-${PANDOC_VERSION}-x86_64-macOS.zip"
fi
elif [[ "$OS" = "linux" ]]; then
if [[ "$ARCH" = "arm64" ]]; then
BINARY_NAME="pandoc-${PANDOC_VERSION}-linux-arm64.tar.gz"
elif [[ "$ARCH" = "amd64" ]]; then
BINARY_NAME="pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz"
fi
fi
BINARY_URL=$PD_REL/download/${PANDOC_VERSION}/${BINARY_NAME}
echo "Downloading $BINARY_URL"

tmp=$(mktemp -d)
trap 'rm -rf ${tmp}' EXIT

curl -sL -o ${tmp}/${BINARY_NAME} $BINARY_URL
if [[ "$BINARY_NAME" =~ .zip$ ]]; then
unzip ${tmp}/${BINARY_NAME} -d ${tmp}
for a in `ls -d -1 ${tmp}/* | grep pandoc | grep -v zip`; do mv $a/* ${tmp}; rmdir $a; done
elif [[ "$BINARY_NAME" =~ .tar.gz$ ]]; then
tar xvzf ${tmp}/${BINARY_NAME} --strip-components 1 -C ${tmp}/
fi
PANDOC_BINARY="${tmp}/bin/pandoc"
}

install-pandoc

${PANDOC_BINARY} --from markdown --to gfm ${FAKE_REPOPATH}/docs/APIs.html > ${FAKE_REPOPATH}/docs/APIs.md

rm ${FAKE_REPOPATH}/docs/APIs.html

0 comments on commit 3bc753c

Please sign in to comment.