Skip to content

Commit

Permalink
docs/ci: add step to comment preview builts PR (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtulio authored Jun 10, 2023
1 parent 29c1341 commit fa08e89
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 50 deletions.
67 changes: 65 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ jobs:
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' }}
runs-on: ubuntu-latest
needs: [build]
env:
VERSION: "0.0.0-dev.${{ github.run_number }}-${{ github.run_id }}"
IMAGE: quay.io/mrbraga/okd-installer
VERCEL_VERSION: 28.20.0
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -138,8 +144,6 @@ jobs:

- name: Build container image
env:
VERSION: "0.0.0-dev.${{ github.run_number }}-${{ github.run_id }}"
IMAGE: quay.io/mrbraga/okd-installer
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_PASS: ${{ secrets.QUAY_PASS }}
run: |
Expand All @@ -159,6 +163,65 @@ jobs:
echo "> Publish container image: ${IMAGE}:${VERSION}"
podman push ${IMAGE}:${VERSION}
# Building docs preview
- name: Set step vars
id: vars
run: |
echo "cache-key-pip=pip-docs-${{ hashFiles('**/docs/requirements.txt') }}" >> $GITHUB_OUTPUT
echo "cache-dir-pip=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Set pip cache
uses: actions/cache@v3
with:
path: ${{ steps.vars.outputs.cache-dir-pip }}
key: ${{ steps.vars.outputs.cache-key-pip }}
- name: Set npm cache
uses: actions/cache@v3
with:
path: "${HOME}/.npm"
key: "npm-vercel-${VERCEL_VERSION}"
- name: Build and Deploy Preview Docs
id: verceldeploy
run: |
npm install --global vercel@${VERCEL_VERSION}
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
vercel build --token=${{ secrets.VERCEL_TOKEN }}
PREVIEW_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
echo "Discovered Preview URL: ${PREVIEW_URL}"
echo "url=$PREVIEW_URL" >> $GITHUB_OUTPUT
# Commenting in PR
- name: Find comment
uses: peter-evans/find-comment@v2
id: fbc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- id-build-comment -->'
- name: Create comment
if: steps.fbc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- id-build-comment -->
Artifacts built by CI:
- Container: ${{ env.IMAGE }}:${{ env.VERSION }}
- Docs Preview: ${{ steps.verceldeploy.outputs.url }}
reactions: rocket

- name: Update comment
if: steps.fbc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fbc.outputs.comment-id }}
body: |
<!-- id-build-comment -->
Artifacts built by CI:
- Container: ${{ env.IMAGE }}:${{ env.VERSION }}
- Docs Preview: ${{ steps.verceldeploy.outputs.url }}
reactions: hooray
edit-mode: replace

# Build a container image on main branch, publishing the 'latest' to repository.
publish-container-latest:
name: release container(latest/ci)
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/site-preview.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/site-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:

- name: Build Pages
run: |
make docs-ci-install INSTALL_CMD='sudo apt update; sudo apt'
make docs-build
./hack/docs.sh install
./hack/docs.sh build
- name: Setup Pages
uses: actions/configure-pages@v3
Expand Down
27 changes: 9 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ VENV_REQ ?= docs/requirements.txt
MKDOCS_ARGS ?= -f ./mkdocs.yaml
INSTALL_CMD ?= yum

.PHONY: venv
venv:
test -d $(VENV_DOCS) || python3 -m venv $(VENV_DOCS)
.PHONY: docs-install
docs-install:
hack/docs.sh install

.PHONY: requirements
requirements: venv
$(VENV_DOCS)/bin/pip3 install --upgrade pip
$(VENV_DOCS)/bin/pip3 install -r $(VENV_REQ)

# Vercel
.PHONY: ci-dependencies
ci-dependencies:
cat /etc/os-release
$(INSTALL_CMD) install -y python3-pip graphviz
.PHONY: docs-build
docs-build:
hack/docs.sh build

.PHONY: ci-install
docs-ci-install: ci-dependencies requirements
docs-build:
hack/docs.sh build

docs-serve:
$(VENV_DOCS)/bin/mkdocs serve $(MKDOCS_ARGS)
hack/docs.sh serve

docs-build:
$(VENV_DOCS)/bin/mkdocs build $(MKDOCS_ARGS)
39 changes: 39 additions & 0 deletions hack/docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail

OPT=$1; shift
MKDOCS_ARGS="-f ./mkdocs.yaml"
VENV_DOCS="/tmp/venv-docs"

setup() {
python3.9 -m venv ${VENV_DOCS}
}

install() {
if [[ -x "$(which yum)" ]]; then
yum install -y python3-pip graphviz
else
sudo apt update
sudo apt install -y python3-pip graphviz
fi
pip3 install --upgrade pip
pip3 install -r docs/requirements.txt
}

build() {
mkdocs build ${MKDOCS_ARGS}
}

serve() {
mkdocs serve ${MKDOCS_ARGS}
}

case $OPT in
"setup") setup ;;
"install") install ;;
"build") build ;;
"serve") serve ;;
esac
4 changes: 2 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"installCommand": "make docs-ci-install INSTALL_CMD='sudo apt update; sudo apt'",
"buildCommand": "make docs-build",
"installCommand": "./hack/docs.sh install",
"buildCommand": "./hack/docs.sh build",
"outputDirectory": "site/",
"github": {
"enabled": false,
Expand Down

0 comments on commit fa08e89

Please sign in to comment.