Skip to content

Commit

Permalink
deploy docs preview from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Apr 25, 2024
1 parent b939160 commit 06bca33
Show file tree
Hide file tree
Showing 5 changed files with 6,360 additions and 151 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ jobs:
timeout-minutes: 25
run: earthly --no-output ./yarn-project/+test

docs-preview:
needs: setup
runs-on: ${{ inputs.username || github.actor }}-x86
steps:
- {
uses: actions/checkout@v4,
with: { ref: "${{ github.event.pull_request.head.sha }}" },
}
- uses: ./.github/ci-setup-action
with:
dockerhub_password: "${{ secrets.DOCKERHUB_PASSWORD }}"
concurrency_key: docs-preview-${{ inputs.username || github.actor }}-x86
- name: "Docs Preview"
timeout-minutes: 25
run: earthly --no-output ./docs/+deploy-preview --PR=${{ github.event.number }} --AZTEC_BOT_COMMENTER_GITHUB_TOKEN=${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} --NETLIFY_AUTH_TOKEN=${{ secrets.NETLIFY_AUTH_TOKEN }} --NETLIFY_SITE_ID=${{ secrets.NETLIFY_SITE_ID }}

# push benchmarking binaries to dockerhub registry
bb-bench-binaries:
needs: setup
Expand Down
14 changes: 12 additions & 2 deletions docs/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FROM node:18.19.0
WORKDIR /usr/src/docs

deps:
RUN apt update && apt install -y jq curl perl && rm -rf /var/lib/apt/lists/* && apt-get clean
COPY ./yarn.lock ./yarn.lock
COPY ./package.json ./package.json
RUN yarn install --frozen-lockfile
Expand All @@ -13,8 +14,6 @@ build:
BUILD ../+release-meta
FROM +deps

RUN apt update && apt install -y jq curl perl && rm -rf /var/lib/apt/lists/* && apt-get clean

COPY --dir ../yarn-project/+build-dev/usr/src /usr
COPY ../+release-meta/usr/src/.release-please-manifest.json /usr/src

Expand All @@ -32,6 +31,17 @@ serve:
COPY ./sidebars.js .
ENTRYPOINT ["yarn", "serve"]
EXPOSE 3000
SAVE ARTIFACT /usr/src/docs
SAVE IMAGE aztecprotocol/docs-server

deploy-preview:
ARG NETLIFY_AUTH_TOKEN
ARG NETLIFY_SITE_ID
ARG AZTEC_BOT_COMMENTER_GITHUB_TOKEN
ARG PR
FROM +serve
COPY --dir ../yarn-project/+build-dev/usr/src/yarn-project/scripts ../yarn-project/scripts
COPY ./netlify.toml .
COPY ./deploy_preview.sh .
RUN NETLIFY_AUTH_TOKEN=$NETLIFY_AUTH_TOKEN NETLIFY_SITE_ID=$NETLIFY_SITE_ID ./deploy_preview.sh $PR $AZTEC_BOT_COMMENTER_GITHUB_TOKEN

31 changes: 31 additions & 0 deletions docs/deploy_preview.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -eu

PR_URL="$1"
AZTEC_BOT_COMMENTER_GITHUB_TOKEN="$2"

API_URL="${PR_URL/github.com/api.github.com/repos}"
API_URL="${API_URL/pull/pulls}"
API_URL="${API_URL}/files"

echo "API URL: $API_URL"

DOCS_CHANGED=$(curl -L \
-H "Authorization: Bearer $AZTEC_BOT_COMMENTER_GITHUB_TOKEN" \
"${API_URL}" | \
jq '[.[] | select(.filename | startswith("docs/"))] | length > 0')

echo "Docs changed: $DOCS_CHANGED"

if [ "$DOCS_CHANGED" = "false" ]; then
echo "No docs changed, not deploying"
exit 0
fi

# Regular deploy if the argument is not "master" and docs changed
DEPLOY_OUTPUT=$(yarn netlify deploy --site aztec-docs-dev)
UNIQUE_DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -E "https://.*aztec-docs-dev.netlify.app" | awk '{print $4}')
echo "Unique deploy URL: $UNIQUE_DEPLOY_URL"

cd ../yarn-project/scripts
UNIQUE_DEPLOY_URL=$UNIQUE_DEPLOY_URL yarn docs-preview-comment
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"concurrently": "^8.0.1",
"docusaurus-plugin-typedoc": "^0.20.2",
"dotenv": "^16.3.1",
"netlify-cli": "^17.23.0",
"nodemon": "^3.0.1",
"typedoc": "^0.25.1",
"typedoc-plugin-markdown": "^3.16.0",
Expand Down
Loading

0 comments on commit 06bca33

Please sign in to comment.