--- /dev/null
+name: "Deploy Artifact to Netlify"
+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'
--- /dev/null
+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")
## Latest changes
+* Add new GitHub Actions to preview docs from PRs. PR [#1738](https://github.com/tiangolo/fastapi/pull/1738).
* Add XML test coverage to support GitHub Actions. PR [#1737](https://github.com/tiangolo/fastapi/pull/1737).
* Update badges and remove Travis now that GitHub Actions is the main CI. PR [#1736](https://github.com/tiangolo/fastapi/pull/1736).
* Add GitHub Actions for CI, move from Travis. PR [#1735](https://github.com/tiangolo/fastapi/pull/1735).