Skip to content

Commit

Permalink
chore(ci): directly build and push to cloudflare pages
Browse files Browse the repository at this point in the history
Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww committed Apr 25, 2024
1 parent 85cb759 commit 505053a
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
paths-ignore:
- 'docs/pages/**'
branches:
- main
pull_request:
paths-ignore:
- 'docs/pages/**'
branches:
- main

env:
STORE_PATH: ''

jobs:
build-test:
name: Build Test
runs-on: 'ubuntu-latest'

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: "^1.22.0"
cache: true

- name: Setup Go Cache PATH
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- name: Test Build
run: make build
94 changes: 94 additions & 0 deletions .github/workflows/pr-docs-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Build PR Previewing Docs

on:
pull_request:
branches:
- main
paths:
- 'docs/**'

env:
STORE_PATH: ''

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]

name: Build - ${{ matrix.os }}

runs-on: ${{ matrix.os }}
steps:
# This is quite weird.
# Eventhough this is the *intended* solution introduces in official blog post here
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/.
# But still, as https://github.com/orgs/community/discussions/25220#discussioncomment-7856118 stated,
# this is vulnerable since there is no source of truth about which PR in the triggered workflow.
- name: Presist PR number
run: |
echo "${{ github.event.number }}" > pr_num
- name: Presist branch name
run: |
echo "${{ github.head_ref }}" > branch_name
- name: Upload PR artifact
uses: actions/upload-artifact@v2
with:
name: pr-num
path: ./pr_num

- name: Upload PR artifact
uses: actions/upload-artifact@v2
with:
name: branch-name
path: ./branch_name

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
working-directory: docs
run: pnpm install --frozen-lockfile

- name: Build docs
working-directory: docs
run: pnpm docs:build
env:
# As suggested in Verbose Build option to be able to track down errors https://github.com/vuejs/vitepress/issues/422
# vitepress build command does not have --debug option, so we need to set it manually where the debug package is used.
# DEBUG: 'vitepress:*'
VUE_PROD_HYDRATION_MISMATCH_DETAILS_FLAG: '1'

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: docs-${{ matrix.os }}-build
path: docs/.vitepress/dist
139 changes: 139 additions & 0 deletions .github/workflows/pr-docs-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Push PR Previewing Docs to Cloudflare Pages

on:
workflow_run:
workflows:
- Build PR Previewing Docs
types:
- completed

env:
PR_NUM: 0
BRANCH_NAME: main
STORE_PATH: ''

jobs:
on-success:
name: Deploy to Cloudflare Pages
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download artifact - PR
uses: dawidd6/action-download-artifact@v3
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: pr-num
path: pr-num
allow_forks: true

- name: Download artifact - PR
uses: dawidd6/action-download-artifact@v3
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: branch-name
path: branch-name
allow_forks: true

- name: Obtain PR number
id: pr-num
run: |
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV
- name: Obtain branch name
id: branch-name
run: |
echo "BRANCH_NAME=$(cat branch-name/branch_name)" >> $GITHUB_ENV
- name: Download artifact - Ubuntu
uses: dawidd6/action-download-artifact@v3
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: docs-ubuntu-latest-build
path: docs-ubuntu-latest-build
allow_forks: true

- name: Publish to Cloudflare Pages
id: deploy
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }}
directory: .vitepress/dist
# Optional: Switch what branch you are publishing to.
# By default this will be the branch which triggered this workflow
branch: ${{ env.BRANCH_NAME }}
# Optional: Change the working directory
workingDirectory: docs
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
wranglerVersion: '3'

- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ env.PR_NUM }}
comment-author: 'github-actions[bot]'
body-includes: to Cloudflare Pages

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ env.PR_NUM }}
body: |
## ✅ Successfully deployed to Cloudflare Pages
| Status | URL |
|:------------|:-----------------------------------|
| Success | ${{ steps.deploy.outputs.url }} |
edit-mode: replace

on-failure:
name: Failed to build previewing docs
runs-on: ubuntu-latest
permissions:
pull-requests: write

if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Download artifact - PR
uses: dawidd6/action-download-artifact@v3
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: pr-num
path: pr-num
allow_forks: true

- name: Obtain PR number
id: pr-num
run: |
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ env.PR_NUM }}
comment-author: 'github-actions[bot]'
body-includes: to Cloudflare Pages

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ env.PR_NUM }}
body: |
## ❌ Failed to deploy to Cloudflare Pages
| Platform | Status | URL |
|:---------|:------------|:------------------------------------------------------|
| Ubuntu | Failed | Please check the status and logs of the workflow run. |
| Windows | Failed | Please check the status and logs of the workflow run. |
edit-mode: replace
74 changes: 74 additions & 0 deletions .github/workflows/production-docs-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build Docs to Cloudflare Pages

on:
push:
branches:
- 'main'

env:
STORE_PATH: ''

jobs:
build:
name: Build
runs-on: ubuntu-22.04
environment:
name: Production Docs
url: https://ollama-operator.ayaka.io
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build docs
run: |
pnpm docs:build
env:
# As suggested in Verbose Build option to be able to track down errors https://github.com/vuejs/vitepress/issues/422
# vitepress build command does not have --debug option, so we need to set it manually where the debug package is used.
# DEBUG: 'vitepress:*'
VUE_PROD_HYDRATION_MISMATCH_DETAILS_FLAG: '1'

- name: Publish to Cloudflare Pages
id: deploy
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }}
directory: .vitepress/dist
# Optional: Switch what branch you are publishing to.
# By default this will be the branch which triggered this workflow
branch: main
# Optional: Change the working directory
workingDirectory: docs
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
wranglerVersion: '3'
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/ollama-operator/main.go
go build -o bin/kollama cmd/kollama/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down

0 comments on commit 505053a

Please sign in to comment.