Merge pull request #672 from aws-samples/github-actions/update-contri… #258
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Published API Documantation | |
on: | |
push: | |
branches: | |
- main | |
- v1 | |
- v2 | |
jobs: | |
deploy-docs: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: "3.11" | |
- name: Install dependencies | |
run: | | |
pip install poetry | |
cd backend | |
poetry install | |
- name: Set Environment Variables | |
run: | | |
echo "AWS_DEFAULT_REGION=us-east-1" >> $GITHUB_ENV | |
echo "PUBLISHED_API_ID=api_id" >> $GITHUB_ENV | |
- name: Start FastAPI server | |
run: | | |
cd backend | |
poetry run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 & | |
sleep 10 | |
env: | |
AWS_REGION: ${{ env.AWS_REGION }} | |
- name: Download OpenAPI JSON | |
run: | | |
wget http://127.0.0.1:8000/openapi.json -O openapi.json | |
- name: Install redoc-cli | |
run: | | |
npm install -g redoc-cli | |
- name: Generate REDOC static HTML | |
run: | | |
mkdir -p redoc | |
npx redoc-cli bundle openapi.json -o docs/index.html | |
- name: Kill FastAPI server | |
run: | | |
pids=$(pgrep -f "uvicorn app.main:app") | |
for pid in $pids; do | |
kill $pid | |
done | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./docs |