Skip to content

Commit

Permalink
Merge pull request #71 from rocky-linux/07-29-switch_to_use_fastly_co…
Browse files Browse the repository at this point in the history
…mpute_actions

Update deployment workflow
  • Loading branch information
NeilHanlon authored Jul 30, 2024
2 parents 5af0cf0 + 4e94d31 commit 879176e
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 21 deletions.
62 changes: 62 additions & 0 deletions .github/actions/build-and-cache/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build site with mkdocs and cache / save
description: Builds and deploys docs.r.o with mkdocs and caches build output
outputs:
DOCS_SHA:
description: "DOCS_SHA"
value: ${{ steps.docs-sha.outputs.DOCS_SHA }}
runs:
using: "composite"
steps:
- name: Install deps
run: dnf -y install python3-pip npm git-core
shell: bash

- name: Checkout documentation repo
uses: actions/checkout@v4
with:
repository: rocky-linux/documentation
path: docs
fetch-depth: 0

- name: set docs-sha
id: docs-sha
working-directory: docs
run: echo "DOCS_SHA=$(git rev-parse --verify HEAD)" >> "$GITHUB_OUTPUT"
shell: bash

- uses: actions/cache/restore@v4
id: docs-cache
with:
path: build/site/minified
key: cache-docs-${{ steps.docs-sha.outputs.DOCS_SHA }}
lookup-only: true

- run: python3.9 -m pip install -r requirements.txt
if: steps.docs-cache.outputs.cache-hit != 'true'
shell: bash

- run: chown -R 1001:1001 .
if: steps.docs-cache.outputs.cache-hit != 'true'
shell: bash

- name: Build Site
if: steps.docs-cache.outputs.cache-hit != 'true'
run: npm run build
shell: bash

- name: Save built site
if: steps.docs-cache.outputs.cache-hit != 'true'
id: cache-build
uses: actions/cache/save@v4
with:
path: |
build/minified/site
key: cache-docs-${{ steps.docs-sha.outputs.DOCS_SHA }}

- name: Archive build artifacts
if: steps.docs-cache.outputs.cache-hit != 'true'
uses: actions/upload-artifact@v4
with:
name: build-minified
path: |
build/minified/site
65 changes: 51 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,63 @@ jobs:
runs-on: ubuntu-latest
container:
image: quay.io/rockylinux/rockylinux:9
options: --user root
outputs:
DOCS_SHA: ${{steps.build.outputs.DOCS_SHA}}
environment: production
steps:
- name: Install deps
run: dnf -y install python3-pip npm git-core
- uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Checkout mkdocs config
uses: actions/checkout@v4

- name: "Build Site"
uses: ./.github/actions/build-and-cache/

- name: set docs-sha
id: docs-sha
run: echo "$DOCS_SHA" >> "$GITHUB_OUTPUT"
deploy:
name: deploy
needs: build
runs-on: ubuntu-latest
environment: production
steps:

- uses: actions/cache/restore@v4
id: docs-cache
with:
repository: rocky-linux/documentation
path: docs
- run: python3.9 -m pip install -r requirements.txt
- name: Build Site
run: npm run build
- name: Archive build artifacts
uses: actions/upload-artifact@v4
path: build/site/minified
key: cache-docs-${{ needs.build.outputs.DOCS_SHA }}
fail-on-cache-miss: false
enableCrossOsArchive: true

- name: Retrieve build artifacts
if: steps.docs-cache.outputs.cache-hit != 'true'
uses: actions/download-artifact@v4
with:
name: build-minified
path: |
build/minified/site
- name: Deploy
- name: Set up Fastly CLI
uses: fastly/compute-actions/setup@v6
with:
cli_version: 'latest'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Dependencies
run: npm install
working-directory: ./compute-js

- name: Build Compute Package
uses: fastly/compute-actions/build@v6
with:
verbose: true
project_directory: compute-js

- name: Deploy Compute Package
uses: fastly/compute-actions/deploy@v6
with:
comment: 'Deployed via GitHub Actions'
project_directory: compute-js
env:
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
run: npm run deploy
64 changes: 64 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: Fastly Compute Branch Previews

concurrency:
group: ${{ github.head_ref || github.run_id }}-${{ github.workflow}}

on:
pull_request:
types: [opened, synchronize, reopened, closed]

jobs:
build:
name: build
runs-on: ubuntu-latest
container:
image: quay.io/rockylinux/rockylinux:9
options: --user root
environment: preview
outputs:
DOCS_SHA: ${{steps.build.outputs.DOCS_SHA}}
steps:

- name: Checkout mkdocs config
uses: actions/checkout@v4

- name: "Build Site"
id: build
uses: ./.github/actions/build-and-cache/

- name: set docs-sha
id: docs-sha
run: echo "$DOCS_SHA" >> "$GITHUB_OUTPUT"

preview:
name: preview
needs: build
runs-on: ubuntu-latest
environment: preview
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- run: ls -la
- uses: actions/cache/restore@v4
id: docs-cache
with:
path: build/site/minified
key: cache-docs-${{ needs.build.outputs.DOCS_SHA }}
fail-on-cache-miss: false
enableCrossOsArchive: true
- name: Retrieve build artifacts
if: steps.docs-cache.outputs.cache-hit != 'true'
uses: actions/download-artifact@v4
with:
name: build-minified
path: |
build/minified/site
- run: ls -la
- uses: neil-forks/compute-actions/preview@preview-with-subdir
with:
fastly-api-token: ${{ secrets.FASTLY_API_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
project_directory: ./compute-js
8 changes: 1 addition & 7 deletions setup-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ pip install -r requirements.txt
# pip install "git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git"
# fi

test -d compute-js/bin || mkdir compute-js/bin
test -x compute-js/bin/fastly || ( curl -L https://github.com/fastly/cli/releases/download/v10.12.3/fastly_v10.12.3_linux-amd64.tar.gz | tar -xzf /dev/stdin -C compute-js/bin/ )

# mkdocs optimize plugin requires pngquant
npm install pngquant

# minify for reducing deployment size
mkdir -p compute-js/bin
test -x compute-js/bin/minify || (curl -L https://github.com/tdewolff/minify/releases/download/v2.20.18/minify_linux_amd64.tar.gz | tar -C compute-js/bin/ -xz minify)

# jq (for yq)
test -x compute-js/bin/jq || curl -L https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64 -o compute-js/bin/jq
chmod +x compute-js/bin/jq

0 comments on commit 879176e

Please sign in to comment.