Skip to content

Commit

Permalink
Established placement for HTML API download (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitra-mylarappachar authored Nov 7, 2022
1 parent 1915d99 commit 284c5cb
Show file tree
Hide file tree
Showing 5 changed files with 3,018 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/commit-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -x
# (C) Copyright 2022 Hewlett Packard Enterprise Development LP
#

set -eu

WATCH_DIR=${WATCH_DIR:-.}

if [[ -n `git status -s ${WATCH_DIR}` ]]
then
git add ${WATCH_DIR}
git commit -m "${GIT_COMMIT_MESSAGE:-commit changes}"
else
echo "${WATCH_DIR} is already up-to-date"
exit 0
fi

REMOTE="${REMOTE:-https://x-access-token:${GITHUB_TOKEN}@github.com/${REPOSITORY}}"

MAX_RETRIES=${MAX_RETRIES:-3}
ATTEMPT=0
while true
do
if git push "${REMOTE}"
then
break
fi

ATTEMPT=$((ATTEMPT + 1))
if [[ ${ATTEMPT} -ge ${MAX_RETRIES} ]]
then
echo "Failed to successfully sync with remote after ${MAX_RETRIES} attempts"
exit 1
fi

echo "Try ${ATTEMPT}: failed to push, waiting 2 seconds before fetching latest and retrying..."

sleep 2

git pull --rebase "${REMOTE}"
done

echo "Successfully pushed latest changes to remote"
46 changes: 46 additions & 0 deletions .github/workflows/html.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#(C) Copyright 2022 Hewlett Packard Enterprise Development LP

name: HTML Doc

on:
push:
branches:
- master

jobs:
ci:
runs-on: ubuntu-20.04
steps:
- name: Checkout workspace
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.13.2

- name: Install dependencies
run: |
# redocly CLI
npm i -g redoc-cli
# yq
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O yq
chmod +x yq
export PATH=${PATH}:`pwd`
- name: Generate HTML doc
run: (cd v1 && make gen-html)

- name: Commit changes
run: .github/workflows/commit-changes.sh
env:
WATCH_DIR: "v1/html"
GIT_AUTHOR_NAME: ${{ github.actor }}
GIT_AUTHOR_EMAIL: ${{ github.actor }}@users.noreply.github.com
GIT_COMMITTER_NAME: GitHub Actions
GIT_COMMITTER_EMAIL: actions@github.com
GIT_COMMIT_MESSAGE: |
[dependabot skip] Sync changes with gen-html
BRANCH_REF: ${{ github.event.pull_request.head.ref }}
REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 8 additions & 3 deletions build/html_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@

set -euo pipefail

if [ $# -ne 1 ]; then
echo "usage: $0 <API_Spec_file_path>" 1>&2
if [ $# -lt 1 ]; then
echo "usage: $0 <API_Spec_file_path> [<output_file_path>]" 1>&2
exit 1
fi

OUTPUT_FILE="index.html"
if [[ ! -z "$2" ]]; then
OUTPUT_FILE="${2}"
fi

API_FILE=$1

TEMP_DIR=$(mktemp -d)
Expand All @@ -37,4 +42,4 @@ yq -i '.info.description={"$ref": "./html/docs/api_description.md"}' ${TEMP_MAIN
yq -i '.externalDocs={"description":"API Versioning", "url":"https://www.hpe.com/us/en/software/licensing.html"}' ${TEMP_MAIN_FILE}

# generate HTML file.
redoc-cli build -o ./html/GLPCE_BMaaS_API_Spec.html ${TEMP_MAIN_FILE}
redoc-cli build -o ${OUTPUT_FILE} ${TEMP_MAIN_FILE}
3 changes: 2 additions & 1 deletion v1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ fixup: api_files vendor

.PHONY: gen-html
gen-html:
@(cd ../build; bash html_generate.sh ${PWD}/api/swagger/swagger.yaml)
(cd ../build; \
bash -x html_generate.sh ${PWD}/api/swagger/swagger.yaml ${PWD}/html/index.html)
2,919 changes: 2,919 additions & 0 deletions v1/html/index.html

Large diffs are not rendered by default.

0 comments on commit 284c5cb

Please sign in to comment.