Merge pull request #1227 from run-ai/remove-placement-groups #811
Workflow file for this run
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: Create Preview Environment on PR | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize, closed] | |
branches: | |
- master | |
- v*.* | |
jobs: | |
build-and-deploy: | |
if: github.event.action != 'closed' && github.repository == 'run-ai/docs' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
cache: 'pip' # caching pip dependencies | |
- name: install dependencies | |
run: | | |
pip3 install -r requirements.txt | |
- name: mkdocs-build-action | |
run: | | |
mkdocs build | |
- name: Install AWS CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install awscli -y | |
- name: Sync S3 bucket for preview | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | |
run: | | |
aws s3 sync ./site/ s3://${{ secrets.AWS_S3_BUCKET_NAME }}/PR-${{ github.event.number }} --delete | |
- name: Invalidate CloudFront cache | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | |
run: | | |
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/PR-${{ github.event.number }}/*" | |
- name: Comment on PR with preview URL | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Preview environment URL: https://d161wck8lc3ih2.cloudfront.net/PR-${{ github.event.number }}/` | |
}) | |
cleanup: | |
if: github.event.action == 'closed' && github.repository == 'run-ai/docs' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install AWS CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install awscli -y | |
- name: Remove PR directory from S3 bucket | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | |
run: | | |
aws s3 rm s3://${{ secrets.AWS_S3_BUCKET_NAME }}/PR-${{ github.event.number }} --recursive |