Skip to content

Commit bf8fe07

Browse files
authored
Merge pull request #824 from run-ai/add-automated-publish-docs-ci
Add Automated-Publish-Docs CI
2 parents 1dbc0af + c06cd4c commit bf8fe07

File tree

4 files changed

+180
-31
lines changed

4 files changed

+180
-31
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Automated-Publish-Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- v*.*
7+
paths-ignore:
8+
- 'github/**'
9+
10+
jobs:
11+
env:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
CURRENT_BRANCH: ${{ steps.calculate-env.outputs.current_branch }}
15+
NEWEST_VERSION: ${{ steps.calculate-env.outputs.newest_version }}
16+
ALIAS: ${{ steps.calculate-env.outputs.alias }}
17+
TITLE: ${{ steps.calculate-env.outputs.title }}
18+
SLACK_CHANNEL: "docs-review"
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Get all v*.* branches
24+
id: calculate-env
25+
run: |
26+
BRANCHES=$(git branch --list --all | grep -v master | grep 'origin/v*.*' | sed -n -E 's:.*/(v[0-9]+\.[0-9]+).*:\1:p' | sort -Vu)
27+
NEWEST_VERSION=$(printf '%s\n' "${BRANCHES[@]}" | sort -V | tail -n 1)
28+
CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
29+
ALIAS=$CURRENT_BRANCH-alias
30+
TITLE=$(echo $CURRENT_BRANCH | cut -b 2-)
31+
echo current_branch=$CURRENT_BRANCH >> $GITHUB_OUTPUT
32+
echo newest_version=$NEWEST_VERSION >> $GITHUB_OUTPUT
33+
echo alias=$ALIAS >> $GITHUB_OUTPUT
34+
echo title=$TITLE >> $GITHUB_OUTPUT
35+
36+
if [[ "$CURRENT_BRANCH" == "$NEWEST_VERSION" ]]; then
37+
echo "Deploying $NEWEST_VERSION as latest..."
38+
else
39+
echo "Deploying $CURRENT_BRANCH which is not the latest version ( => $NEWEST_VERSION )..."
40+
fi
41+
42+
install-dependencies-and-deploy:
43+
name: Install Dependencies and Deploy
44+
needs: [env]
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: checkout latest
48+
uses: actions/checkout@v4
49+
with:
50+
ref: ${{ needs.env.outputs.CURRENT_BRANCH }}
51+
fetch-depth: 0
52+
53+
- name: setup python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: '3.9'
57+
cache: 'pip' # caching pip dependencies
58+
59+
- name: install dependencies
60+
run: |
61+
pip3 install -r requirements.txt
62+
63+
- name: Configure Git User
64+
run: |
65+
git config user.name "circleci-runai"
66+
git config user.email "circleci-runai@run.ai"
67+
68+
- name: deploy mkdocs
69+
run: |
70+
if [[ "${{ needs.env.outputs.CURRENT_BRANCH }}" == "${{ needs.env.outputs.NEWEST_VERSION }}" ]]; then
71+
echo "Deploying ${{ needs.env.outputs.NEWEST_VERSION }} as latest..."
72+
mike list
73+
git fetch origin gh-pages --depth=1
74+
mike deploy ${{ needs.env.outputs.CURRENT_BRANCH }} ${{ needs.env.outputs.ALIAS }} latest --title=${{ needs.env.outputs.TITLE }} --push --update-aliases
75+
mike set-default latest --push
76+
mike list
77+
else
78+
echo "Deploying ${{ needs.env.outputs.CURRENT_BRANCH }} which is not the latest version ( => ${{ needs.env.outputs.NEWEST_VERSION }} )..."
79+
mike list
80+
git fetch origin gh-pages --depth=1
81+
mike deploy ${{ needs.env.outputs.CURRENT_BRANCH }} ${{ needs.env.outputs.ALIAS }} --title=${{ needs.env.outputs.TITLE }} --push
82+
mike list
83+
fi
84+
85+
slack-notification:
86+
name: Slack Notification
87+
needs: [env, install-dependencies-and-deploy]
88+
if: always()
89+
runs-on: ubuntu-latest
90+
steps:
91+
- name: Slack Notification
92+
uses: rtCamp/action-slack-notify@v2
93+
env:
94+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
95+
SLACK_COLOR: ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
96+
SLACK_TITLE: "RunAI-Docs: Version ${{ needs.env.outputs.CURRENT_BRANCH }} Deployment ${{ contains(needs.*.result, 'failure') && 'failed' || 'completed successfully' }}"
97+
SLACK_MESSAGE_ON_SUCCESS: "Docs were updated successfully for version ${{ needs.env.outputs.TITLE }}"
98+
SLACK_MESSAGE_ON_FAILURE: "Docs update FAILED for version ${{ needs.env.outputs.TITLE }}"
99+
MSG_MINIMAL: true
100+
SLACK_FOOTER: ""

.github/workflows/ci.yml.old

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Create Preview Environment on PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, closed]
6+
branches:
7+
- master
8+
- v*.*
9+
10+
jobs:
11+
build-and-deploy:
12+
if: github.event.action != 'closed'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: setup python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.9'
22+
cache: 'pip' # caching pip dependencies
23+
24+
- name: install dependencies
25+
run: |
26+
pip3 install -r requirements.txt
27+
28+
- name: mkdocs-build-action
29+
run: |
30+
mkdocs build
31+
32+
- name: Install AWS CLI
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install awscli -y
36+
37+
- name: Sync S3 bucket for preview
38+
env:
39+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
42+
run: |
43+
aws s3 sync ./site/ s3://${{ secrets.AWS_S3_BUCKET_NAME }}/PR-${{ github.event.number }} --delete
44+
45+
- name: Invalidate CloudFront cache
46+
env:
47+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
48+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
49+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
50+
run: |
51+
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/PR-${{ github.event.number }}/*"
52+
53+
- name: Comment on PR with preview URL
54+
uses: actions/github-script@v6
55+
with:
56+
script: |
57+
github.rest.issues.createComment({
58+
issue_number: context.issue.number,
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
body: `Preview environment URL: https://d161wck8lc3ih2.cloudfront.net/PR-${{ github.event.number }}/`
62+
})
63+
64+
cleanup:
65+
if: github.event.action == 'closed'
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Install AWS CLI
69+
run: |
70+
sudo apt-get update
71+
sudo apt-get install awscli -y
72+
73+
- name: Remove PR directory from S3 bucket
74+
env:
75+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
76+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
77+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
78+
run: |
79+
aws s3 rm s3://${{ secrets.AWS_S3_BUCKET_NAME }}/PR-${{ github.event.number }} --recursive

.github/workflows/deploy-staging.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
4343
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44-
aws-region: us-east-1
44+
aws-region: ${{ secrets.AWS_DEFAULT_REGION}}
4545

4646
- name: Sync output to S3
4747
run: |

0 commit comments

Comments
 (0)