|
| 1 | +name: Sphinx Build and Sync to S3 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + - prod |
| 8 | + - test |
| 9 | + |
| 10 | +jobs: |
| 11 | + build_and_sync: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v1 |
| 15 | + |
| 16 | + - name: Install Poetry |
| 17 | + run: | |
| 18 | + curl -sSL https://install.python-poetry.org | python - |
| 19 | +
|
| 20 | + - name: Install Pandoc |
| 21 | + run: | |
| 22 | + sudo apt-get update |
| 23 | + sudo apt-get install -y pandoc |
| 24 | +
|
| 25 | + - name: Set up Python |
| 26 | + uses: actions/setup-python@v2 |
| 27 | + with: |
| 28 | + python-version: '3.x' |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip |
| 33 | + pip install pytest sphinx recommonmark sphinx_markdown_tables sphinx_markdown_builder nbsphinx sphinx-rtd-theme pandas requests tqdm pydantic coverage coverage-badge |
| 34 | +
|
| 35 | + - name: Run tests and generate coverage badge |
| 36 | + run: | |
| 37 | + coverage run -m pytest ./tests/api/ |
| 38 | + coverage html |
| 39 | + mv htmlcov apidocs/source/ |
| 40 | + rm ./apidocs/source/coverage.svg |
| 41 | + coverage-badge -o apidocs/source/coverage.svg |
| 42 | +
|
| 43 | + - name: Build HTML with Sphinx |
| 44 | + run: | |
| 45 | + cd apidocs |
| 46 | + make html |
| 47 | + |
| 48 | + - name: Get bucket name |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + branch=$(echo ${GITHUB_REF#refs/heads/}); \ |
| 52 | + if [ $branch == 'develop' ]; \ |
| 53 | + then bucket=openprotein-docs-dev; \ |
| 54 | + elif [ $branch == 'prod' ]; \ |
| 55 | + then bucket=openprotein-docs-prod; \ |
| 56 | + elif [ $branch == 'test' ]; \ |
| 57 | + then bucket=openprotein-docs-dev; \ |
| 58 | + else exit 1; fi; \ |
| 59 | + echo $bucket; \ |
| 60 | + echo "bucket=$bucket" >> $GITHUB_OUTPUT |
| 61 | + id: bucket_name |
| 62 | + |
| 63 | + - name: Get distribution ID |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + branch=$(echo ${GITHUB_REF#refs/heads/}); \ |
| 67 | + if [ $branch == 'develop' ]; \ |
| 68 | + then dist=E3SMW2DYY71HHW; \ |
| 69 | + elif [ $branch == 'prod' ]; \ |
| 70 | + then dist=E1CUT1CP31D5NK; \ |
| 71 | + elif [ $branch == 'test' ]; \ |
| 72 | + then dist=E3SMW2DYY71HHW; \ |
| 73 | + else exit 1; fi; \ |
| 74 | + echo $dist; \ |
| 75 | + echo "dist=$dist" >> $GITHUB_OUTPUT |
| 76 | + id: dist_id |
| 77 | + |
| 78 | + - name: Configure AWS credentials |
| 79 | + uses: aws-actions/configure-aws-credentials@v1 |
| 80 | + with: |
| 81 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 82 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 83 | + aws-region: us-east-1 |
| 84 | + |
| 85 | + - name: Sync apidocs to S3 |
| 86 | + env: |
| 87 | + AWS_S3_BUCKET: ${{ steps.bucket_name.outputs.bucket }} |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + aws s3 sync apidocs/build/html s3://${AWS_S3_BUCKET}/apidocs/ |
| 91 | +
|
| 92 | + - name: Invalidate CloudFront cache |
| 93 | + env: |
| 94 | + DISTRIBUTION_ID: ${{ steps.dist_id.outputs.dist }} |
| 95 | + run: | |
| 96 | + aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION_ID} --paths "/apidocs/*" |
0 commit comments