Skip to content

Commit

Permalink
fix website build + use workflow + nixify it
Browse files Browse the repository at this point in the history
  • Loading branch information
brokenpip3 committed Mar 9, 2024
1 parent d35931a commit 8b76e28
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 69 deletions.
110 changes: 54 additions & 56 deletions .github/workflows/auto-gen-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: auto-generate-docs
name: Website

# Run this workflow every time a new commit pushed to your repository
on:
Expand All @@ -7,80 +7,78 @@ on:
- master
- main
paths:
- 'docs/**'
- 'website/**'
- 'assets/**'

jobs:
# Set the job key. The key is displayed as the job name
# when a job name is not provided
docs:
# Name the Job
name: auto-generate-docs
# Set the type of machine to run on
update-date:
name: Auto update dates
runs-on: ubuntu-latest

if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive # Fetch the Docsy theme
fetch-depth: 0

# Checks if the previous commit introduced any changes to website files
- name: Check for changes
run: |
IS_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -Ec "^website*" || :)
[[ $IS_CHANGED -gt 0 ]] && echo "IS_CHANGED=true" >> $GITHUB_ENV || echo "IS_CHANGED=false" >> $GITHUB_ENV
# Sets up the appropriate version of Hugo
- name: Setup Hugo
if: env.IS_CHANGED == 'true'
uses: peaceiris/actions-hugo@v2
- uses: DeterminateSystems/nix-installer-action@v9
with:
hugo-version: '0.113.0'
extended: true

# Sets up node - required by Hugo
- name: Setup Node
if: env.IS_CHANGED == 'true'
uses: actions/setup-node@v4
diagnostic-endpoint: ""
- uses: DeterminateSystems/magic-nix-cache-action@v3
with:
node-version: '12.x'

# Installs dependencies required by docsy theme
- name: Install docsy dependencies
if: env.IS_CHANGED == 'true'
run: |
cd website
npm install
npm build
sudo npm install -D --save autoprefixer
sudo npm install -D --save postcss-cli
cd ../
diagnostic-endpoint: ""
- name: Checkout code
uses: actions/checkout@v4

- name: Update last modified date in modified docs
if: env.IS_CHANGED == 'true'
run: |
git diff --name-only --diff-filter=d ${{ github.event.before }} ${{ github.sha }} | grep -E "^website*" \
| sed -e 's/\(.*\)/"\1"/' | xargs sed -i "/date:/c\date: $(date +'%Y-%m-%d')"
# Runs makefile goal - checks changes to /website folder and generates docs
- name: Run Makefile goal
if: env.IS_CHANGED == 'true'
env:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make generate-docs

# Creates pull request with generated docs
- name: Create Pull Request
if: env.IS_CHANGED == 'true'
uses: peter-evans/create-pull-request@v6
with:
commit-message: Auto-updated docs
branch: docs-generator
title: Auto-generated docs update
body: |
Auto generated docs from master commit ${{ github.sha }}
website-generate:
name: Auto generate website
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- uses: DeterminateSystems/nix-installer-action@v9
with:
diagnostic-endpoint: ""
- uses: DeterminateSystems/magic-nix-cache-action@v3
with:
diagnostic-endpoint: ""
- name: Checkout code
uses: actions/checkout@v4
- name: nix checks
run: nix flake check
- name: nix build
run: |
cd website
nix develop .#website
hugo --minify --baseURL "${BASE_URL}"
env:
HUGO_ENVIRONMENT: production
HUGO_ENV: production
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public

website-deploy:
name: Deploy website
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: website-build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ifeq ($(strip $(HAS_HELM)),)
rm -rf $(PROJECT_DIR)/bin/$(PLATFORM)-amd64
rm -rf $(PROJECT_DIR)/bin/helm.tar.gz
else
mkdir -p $(PROJECT_DIR)/bin
mkdir -p $(PROJECT_DIR)/bin
test -L $(PROJECT_DIR)/bin/helm || ln -sf $(shell command -v helm) $(PROJECT_DIR)/bin/helm
endif

Expand Down Expand Up @@ -451,7 +451,7 @@ endif

# Download and build hugo extended locally if necessary
HUGO_PATH = $(shell pwd)/bin/hugo
HUGO_VERSION = v0.113.0
HUGO_VERSION = v0.99.1
HAS_HUGO := $(shell $(HUGO_PATH)/hugo version 2>&- | grep $(HUGO_VERSION))
hugo:
ifeq ($(HAS_HUGO), )
Expand Down
12 changes: 8 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
flake-utils.url = "github:numtide/flake-utils";
go_15.url = "github:nixos/nixpkgs/4eccd6f731627ba5ad9915bcf600c9329a34ca78";
golangci.url = "github:nixos/nixpkgs/e912fb83d2155a393e7146da98cda0e455a80fb6";
hugo_099.url= "github:nixos/nixpkgs/d6df226c53d46821bd4773bd7ec3375f30238edb";
hugo_099.url = "github:nixos/nixpkgs/d6df226c53d46821bd4773bd7ec3375f30238edb";
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down Expand Up @@ -56,15 +56,19 @@
};

# nix shell .#website
devShells.website = pkgs.callPackage ./nix/website-shell.nix {
inherit pkgs system hugo_099_pkgs;
};
devShells.website = pkgs.callPackage ./nix/website-shell.nix {
inherit pkgs system hugo_099_pkgs;
};

# nix build with gomod2nix
packages.default = pkgs.callPackage ./nix {
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
};

packages.website = import ./nix/website-build.nix {
inherit pkgs system hugo_099_pkgs;
};

}
);
}
21 changes: 21 additions & 0 deletions nix/website-build.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ pkgs, system, hugo_099_pkgs }:

let
buildPackages = [
hugo_099_pkgs.hugo #hugo pre-v100
pkgs.nodejs_21 #Node 1.21
pkgs.nodePackages.autoprefixer
pkgs.nodePackages.postcss
pkgs.nodePackages.postcss-cli
];
baseUrl = ((builtins.fromTOML (builtins.readFile ../website/config.toml)).baseURL);
in
pkgs.buildNpmPackage {
name = "jenkins-kubernetes-operator-website";
src = ../website;
version = "0.0.1";
npmDepsHash = "sha256-NcspVYF+9dCrGxH/cGNhD+TxLZm6ZDX523mKm9smAAA=";
nativeBuildInputs = buildPackages;
buildPhase = "npm run build";
installPhase = "cp -r public $out";
}
9 changes: 4 additions & 5 deletions nix/website-shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

let
devShellPackages = [
pkgs.go
hugo_099_pkgs.hugo #hugo pre-v100
# docsy theme needs some node dep
pkgs.nodejs_21 #Node 1.21
pkgs.nodePackages.postcss
pkgs.nodePackages.postcss-cli
pkgs.nodePackages.postcss-cli
];
baseUrl = ((builtins.fromTOML (builtins.readFile ../website/config.toml)).baseURL);
in
pkgs.mkShell {
packages = devShellPackages;
shellHook = ''
npm install --save-dev
npm list
'';
BASE_URL = "${baseUrl}";
}
2 changes: 1 addition & 1 deletion website/.envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
has nix && use flake .#website
has nix && use flake ../.#website
1 change: 1 addition & 0 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "website",
"devDependencies": {
"scripts": {
"build": "hugo --minify"
},
"devDependencies": {
"autoprefixer": "^10.4.18",
"postcss": "^8.4.35",
"postcss-cli": "^11.0.0"
Expand Down

0 comments on commit 8b76e28

Please sign in to comment.