mirror of https://github.com/tiangolo/fastapi.git
🔥 Cleanup after upgrade for Docs Previews GitHub Action (#2248)
* 🔧 Upload docs artifacts even on push to avoid breaking Preview Docs * 🔥 Remove replaced GitHub Action get-artifact * 🔥 Remove GitHub Action Watch Docs Previews, replaced with Preview Docs * 🔥 Remove commented backup configs in Preview Docs GitHub Action * 🔥 Remove no longer needed utils scripts
This commit is contained in:
parent
c75c13c3b0
commit
e1755f4fa6
|
|
@ -1,7 +0,0 @@
|
||||||
FROM python:3.7
|
|
||||||
|
|
||||||
RUN pip install httpx "pydantic==1.5.1"
|
|
||||||
|
|
||||||
COPY ./app /app
|
|
||||||
|
|
||||||
CMD ["python", "/app/main.py"]
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
name: "Get Artifact"
|
|
||||||
description: "Get artifact, possibly uploaded by a PR, useful to deploy docs previews"
|
|
||||||
author: "Sebastián Ramírez <tiangolo@gmail.com>"
|
|
||||||
inputs:
|
|
||||||
token:
|
|
||||||
description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
|
|
||||||
required: true
|
|
||||||
name:
|
|
||||||
description: 'Artifact name'
|
|
||||||
required: true
|
|
||||||
path:
|
|
||||||
description: 'Where to store the artifact'
|
|
||||||
required: true
|
|
||||||
runs:
|
|
||||||
using: 'docker'
|
|
||||||
image: 'Dockerfile'
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
import logging
|
|
||||||
from datetime import datetime
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
import httpx
|
|
||||||
from pydantic import BaseModel, BaseSettings, SecretStr
|
|
||||||
|
|
||||||
github_api = "https://api.github.com"
|
|
||||||
netlify_api = "https://api.netlify.com"
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
|
||||||
input_name: str
|
|
||||||
input_token: SecretStr
|
|
||||||
input_path: str
|
|
||||||
github_repository: str
|
|
||||||
github_event_path: Path
|
|
||||||
github_event_name: Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
class Artifact(BaseModel):
|
|
||||||
id: int
|
|
||||||
node_id: str
|
|
||||||
name: str
|
|
||||||
size_in_bytes: int
|
|
||||||
url: str
|
|
||||||
archive_download_url: str
|
|
||||||
expired: bool
|
|
||||||
created_at: datetime
|
|
||||||
updated_at: datetime
|
|
||||||
|
|
||||||
|
|
||||||
class ArtifactResponse(BaseModel):
|
|
||||||
total_count: int
|
|
||||||
artifacts: List[Artifact]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
settings = Settings()
|
|
||||||
logging.info(f"Using config: {settings.json()}")
|
|
||||||
github_headers = {
|
|
||||||
"Authorization": f"token {settings.input_token.get_secret_value()}"
|
|
||||||
}
|
|
||||||
response = httpx.get(
|
|
||||||
f"{github_api}/repos/{settings.github_repository}/actions/artifacts",
|
|
||||||
headers=github_headers,
|
|
||||||
)
|
|
||||||
data = response.json()
|
|
||||||
artifacts_response = ArtifactResponse.parse_obj(data)
|
|
||||||
use_artifact: Optional[Artifact] = None
|
|
||||||
for artifact in artifacts_response.artifacts:
|
|
||||||
if artifact.name == settings.input_name:
|
|
||||||
use_artifact = artifact
|
|
||||||
break
|
|
||||||
assert use_artifact
|
|
||||||
file_response = httpx.get(
|
|
||||||
use_artifact.archive_download_url, headers=github_headers, timeout=30
|
|
||||||
)
|
|
||||||
zip_file = Path(settings.input_path)
|
|
||||||
zip_file.write_bytes(file_response.content)
|
|
||||||
logging.info("Finished")
|
|
||||||
|
|
@ -23,10 +23,8 @@ jobs:
|
||||||
- name: Build Docs
|
- name: Build Docs
|
||||||
run: python3.7 ./scripts/docs.py build-all
|
run: python3.7 ./scripts/docs.py build-all
|
||||||
- name: Zip docs
|
- name: Zip docs
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
run: bash ./scripts/zip-docs.sh
|
run: bash ./scripts/zip-docs.sh
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v2
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
with:
|
with:
|
||||||
name: docs-zip
|
name: docs-zip
|
||||||
path: ./docs.zip
|
path: ./docs.zip
|
||||||
|
|
|
||||||
|
|
@ -5,30 +5,12 @@ on:
|
||||||
- Build Docs
|
- Build Docs
|
||||||
types:
|
types:
|
||||||
- completed
|
- completed
|
||||||
# workflow_dispatch:
|
|
||||||
# inputs:
|
|
||||||
# pr:
|
|
||||||
# description: Pull Request number
|
|
||||||
# required: true
|
|
||||||
# name:
|
|
||||||
# description: Artifact name for zip file with docs
|
|
||||||
# required: true
|
|
||||||
# commit:
|
|
||||||
# description: Commit SHA hash
|
|
||||||
# required: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
# - uses: ./.github/actions/get-artifact
|
|
||||||
# with:
|
|
||||||
# token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
# name: ${{ github.event.inputs.name }}
|
|
||||||
# path: ./archive.zip
|
|
||||||
# - name: Unzip docs
|
|
||||||
# run: bash ./scripts/unzip-docs.sh
|
|
||||||
- name: Download Artifact Docs
|
- name: Download Artifact Docs
|
||||||
uses: dawidd6/action-download-artifact@v2.9.0
|
uses: dawidd6/action-download-artifact@v2.9.0
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
# name: Watch Docs Previews
|
|
||||||
# on:
|
|
||||||
# schedule:
|
|
||||||
# - cron: "0 * * * *"
|
|
||||||
|
|
||||||
# jobs:
|
|
||||||
# deploy:
|
|
||||||
# runs-on: ubuntu-18.04
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@v2
|
|
||||||
# - uses: ./.github/actions/watch-previews
|
|
||||||
# with:
|
|
||||||
# token: ${{ secrets.ACTIONS_TOKEN }}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
#! /usr/bin/env bash
|
|
||||||
|
|
||||||
set -x
|
|
||||||
set -e
|
|
||||||
|
|
||||||
PR=${PR:?Variable not set}
|
|
||||||
DEPLOY_URL=${DEPLOY_URL:?Variable not set}
|
|
||||||
GITHUB_TOKEN=${GITHUB_TOKEN:?Variable not set}
|
|
||||||
COMMIT=${COMMIT:?Variable not set}
|
|
||||||
|
|
||||||
curl \
|
|
||||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
|
||||||
https://api.github.com/repos/tiangolo/fastapi/issues/${PR}/comments \
|
|
||||||
-d '{"body": "📝 Docs preview for commit '"${COMMIT} at: ${DEPLOY_URL}"'"}'
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
#! /usr/bin/env bash
|
|
||||||
|
|
||||||
set -x
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ -d ./site/ ]; then
|
|
||||||
rm -rf ./site/
|
|
||||||
fi
|
|
||||||
unzip archive.zip
|
|
||||||
# Double zipped by GitHub when downlading the archive
|
|
||||||
unzip docs.zip
|
|
||||||
rm -rf archive.zip
|
|
||||||
rm -rf docs.zip
|
|
||||||
Loading…
Reference in New Issue