diff --git a/.github/workflows/auto-gen-docs.yaml b/.github/workflows/auto-gen-docs.yaml index 4e7e58a72..c0d5234be 100644 --- a/.github/workflows/auto-gen-docs.yaml +++ b/.github/workflows/auto-gen-docs.yaml @@ -1,4 +1,4 @@ -name: auto-generate-docs +name: Website # Run this workflow every time a new commit pushed to your repository on: @@ -7,76 +7,30 @@ 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 @@ -84,3 +38,47 @@ jobs: 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 diff --git a/Makefile b/Makefile index 386b5197b..586469286 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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), ) diff --git a/flake.nix b/flake.nix index b8e995073..02f773d49 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; @@ -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; + }; + } ); } diff --git a/nix/website-build.nix b/nix/website-build.nix new file mode 100644 index 000000000..c40aa6d5f --- /dev/null +++ b/nix/website-build.nix @@ -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"; +} diff --git a/nix/website-shell.nix b/nix/website-shell.nix index 596bf36c9..cda6748cb 100644 --- a/nix/website-shell.nix +++ b/nix/website-shell.nix @@ -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}"; } diff --git a/website/.envrc b/website/.envrc index fe7e0253b..5a011bc5d 100644 --- a/website/.envrc +++ b/website/.envrc @@ -1 +1 @@ -has nix && use flake .#website +has nix && use flake ../.#website diff --git a/website/package-lock.json b/website/package-lock.json index a755bc50b..c69baffba 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -4,6 +4,7 @@ "requires": true, "packages": { "": { + "name": "website", "devDependencies": { "autoprefixer": "^10.4.18", "postcss": "^8.4.35", diff --git a/website/package.json b/website/package.json index 327e78689..81197d373 100644 --- a/website/package.json +++ b/website/package.json @@ -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"