Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Automated-Publish-Docs CI #824

Merged
merged 15 commits into from
Jul 10, 2024
Merged
100 changes: 100 additions & 0 deletions .github/workflows/automated-publish-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Automated-Publish-Docs

on:
push:
branches:
- v*.*
paths-ignore:
- 'github/**'

jobs:
env:
runs-on: ubuntu-latest
outputs:
CURRENT_BRANCH: ${{ steps.calculate-env.outputs.current_branch }}
NEWEST_VERSION: ${{ steps.calculate-env.outputs.newest_version }}
ALIAS: ${{ steps.calculate-env.outputs.alias }}
TITLE: ${{ steps.calculate-env.outputs.title }}
SLACK_CHANNEL: "docs-review"
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get all v*.* branches
id: calculate-env
run: |
BRANCHES=$(git branch --list --all | grep -v master | grep 'origin/v*.*' | sed -n -E 's:.*/(v[0-9]+\.[0-9]+).*:\1:p' | sort -Vu)
NEWEST_VERSION=$(printf '%s\n' "${BRANCHES[@]}" | sort -V | tail -n 1)
CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
ALIAS=$CURRENT_BRANCH-alias
TITLE=$(echo $CURRENT_BRANCH | cut -b 2-)
echo current_branch=$CURRENT_BRANCH >> $GITHUB_OUTPUT
echo newest_version=$NEWEST_VERSION >> $GITHUB_OUTPUT
echo alias=$ALIAS >> $GITHUB_OUTPUT
echo title=$TITLE >> $GITHUB_OUTPUT

if [[ "$CURRENT_BRANCH" == "$NEWEST_VERSION" ]]; then
echo "Deploying $NEWEST_VERSION as latest..."
else
echo "Deploying $CURRENT_BRANCH which is not the latest version ( => $NEWEST_VERSION )..."
fi

install-dependencies-and-deploy:
name: Install Dependencies and Deploy
needs: [env]
runs-on: ubuntu-latest
steps:
- name: checkout latest
uses: actions/checkout@v4
with:
ref: ${{ needs.env.outputs.CURRENT_BRANCH }}
fetch-depth: 0

- 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: Configure Git User
run: |
git config user.name "circleci-runai"
git config user.email "[email protected]"

- name: deploy mkdocs
run: |
if [[ "${{ needs.env.outputs.CURRENT_BRANCH }}" == "${{ needs.env.outputs.NEWEST_VERSION }}" ]]; then
echo "Deploying ${{ needs.env.outputs.NEWEST_VERSION }} as latest..."
mike list
git fetch origin gh-pages --depth=1
mike deploy ${{ needs.env.outputs.CURRENT_BRANCH }} ${{ needs.env.outputs.ALIAS }} latest --title=${{ needs.env.outputs.TITLE }} --push --update-aliases
mike set-default latest --push
mike list
else
echo "Deploying ${{ needs.env.outputs.CURRENT_BRANCH }} which is not the latest version ( => ${{ needs.env.outputs.NEWEST_VERSION }} )..."
mike list
git fetch origin gh-pages --depth=1
mike deploy ${{ needs.env.outputs.CURRENT_BRANCH }} ${{ needs.env.outputs.ALIAS }} --title=${{ needs.env.outputs.TITLE }} --push
mike list
fi

haimlevy2006 marked this conversation as resolved.
Show resolved Hide resolved
slack-notification:
name: Slack Notification
needs: [env, install-dependencies-and-deploy]
if: always()
runs-on: ubuntu-latest
steps:
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
SLACK_TITLE: "RunAI-Docs: Version ${{ needs.env.outputs.CURRENT_BRANCH }} Deployment ${{ contains(needs.*.result, 'failure') && 'failed' || 'completed successfully' }}"
SLACK_MESSAGE_ON_SUCCESS: "Docs were updated successfully for version ${{ needs.env.outputs.TITLE }}"
SLACK_MESSAGE_ON_FAILURE: "Docs update FAILED for version ${{ needs.env.outputs.TITLE }}"
MSG_MINIMAL: true
SLACK_FOOTER: ""
30 changes: 0 additions & 30 deletions .github/workflows/ci.yml.old

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/create-preview-env-on-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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'
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'
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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
aws-region: ${{ secrets.AWS_DEFAULT_REGION}}

- name: Sync output to S3
run: |
Expand Down
Loading