From a1f5393abe4181404bb70546e36f82443b2a17c5 Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Mon, 29 Jul 2024 11:33:44 -0400 Subject: [PATCH] switch to use fastly compute actions --- .github/actions/build-and-cache/action.yaml | 62 +++++++++++++++++++++ .github/workflows/deploy.yml | 51 ++++++++++++----- .github/workflows/preview.yml | 56 +++++++++++++++++++ setup-deps.sh | 8 +-- 4 files changed, 155 insertions(+), 22 deletions(-) create mode 100644 .github/actions/build-and-cache/action.yaml create mode 100644 .github/workflows/preview.yml diff --git a/.github/actions/build-and-cache/action.yaml b/.github/actions/build-and-cache/action.yaml new file mode 100644 index 0000000..082f8a6 --- /dev/null +++ b/.github/actions/build-and-cache/action.yaml @@ -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: . + 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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 074dbb3..104e352 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,26 +17,47 @@ jobs: runs-on: ubuntu-latest container: image: quay.io/rockylinux/rockylinux:9 + options: --user root environment: production steps: - - name: Install deps - run: dnf -y install python3-pip npm git-core - - uses: actions/checkout@v4 - - uses: actions/checkout@v4 - 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 + - name: Checkout mkdocs config + uses: actions/checkout@v4 + + - name: "Build Site" + uses: ./.github/actions/build-and-cache/ + deploy: + name: deploy + needs: build + runs-on: ubuntu-latest + environment: production + steps: + - name: fetch build artifacts + 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 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..53cc470 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,56 @@ +--- +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: + working-directory: ./compute-js + shell: bash + steps: + - uses: actions/checkout@v4 + - run: ls -la ../ + - uses: actions/cache/restore@v4 + id: docs-cache + with: + path: . + key: cache-docs-${{ needs.build.outputs.DOCS_SHA }} + - 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 diff --git a/setup-deps.sh b/setup-deps.sh index 8f2032e..28b7b94 100644 --- a/setup-deps.sh +++ b/setup-deps.sh @@ -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