diff --git a/.github/workflows/automated-publish-docs.yaml b/.github/workflows/automated-publish-docs.yaml new file mode 100644 index 0000000000..97c38ef47d --- /dev/null +++ b/.github/workflows/automated-publish-docs.yaml @@ -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 "circleci-runai@run.ai" + + - 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 + + 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: "" \ No newline at end of file diff --git a/.github/workflows/ci.yml.old b/.github/workflows/ci.yml.old deleted file mode 100644 index d2df9fef92..0000000000 --- a/.github/workflows/ci.yml.old +++ /dev/null @@ -1,30 +0,0 @@ -name: ci -on: - push: - branches: - - 'v*.*' - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: extract_branch - - name: action checkout - uses: actions/checkout@v3 - - name: Python step - uses: actions/setup-python@v4 - with: - python-version: 3.x - - name: Cache setup - uses: actions/cache@v2 - with: - key: ${{ github.ref }} - path: .cache - - name: install requirements - run: pip3 install -r requirements.txt - # run: mkdocs gh-deploy --force - - name: Deploy using mike - run: mike deploy --push ${{ steps.extract_branch.outputs.branch }} diff --git a/.github/workflows/create-preview-env-on-pr.yaml b/.github/workflows/create-preview-env-on-pr.yaml new file mode 100644 index 0000000000..445e6ffbca --- /dev/null +++ b/.github/workflows/create-preview-env-on-pr.yaml @@ -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 diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 4fadb8dbfe..feacb391d5 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -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: |