From dabfe758af0e74f1943ef10446bd6c4c28ef9f71 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 3 Jun 2024 10:25:21 +0000 Subject: [PATCH] Reapply "Build website with nix" This reverts commit 0066df8c548f6b800eeafdc9eec6c413291da120. --- .github/workflows/jekyll-master.yml | 19 ++------- .github/workflows/jekyll-preview.yml | 25 ++++-------- .gitignore | 5 ++- README.md | 7 ++++ _sass/_base.scss | 2 +- flake.lock | 61 ++++++++++++++++++++++++++++ flake.nix | 38 +++++++++++++++++ 7 files changed, 123 insertions(+), 34 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/jekyll-master.yml b/.github/workflows/jekyll-master.yml index f7681ff42..a0f30f4ae 100644 --- a/.github/workflows/jekyll-master.yml +++ b/.github/workflows/jekyll-master.yml @@ -12,24 +12,13 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install Bundler - run: sudo gem install bundler - - name: Cache bundle - uses: actions/cache@v3 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - - name: Install Jekyll - run: bundle install + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Build the site with Jekyll - run: | - bundle exec jekyll build --future - + run: nix build - name: Upload run: | mkdir -p "$HOME/.ssh" echo "${{ secrets.KEY }}" > "$HOME/.ssh/key" chmod 600 "$HOME/.ssh/key" - rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/_site/ "${{ secrets.USERNAME }}@delta.chat:/var/www/html/_site" + rsync -rLtvh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/result/ "${{ secrets.USERNAME }}@delta.chat:/var/www/html/_site" diff --git a/.github/workflows/jekyll-preview.yml b/.github/workflows/jekyll-preview.yml index 3a20bea04..acbd784cd 100644 --- a/.github/workflows/jekyll-preview.yml +++ b/.github/workflows/jekyll-preview.yml @@ -14,28 +14,19 @@ jobs: export PULLREQUEST_ID=$(echo "${{ github.ref }}" | cut -d "/" -f3) echo "prid=$PULLREQUEST_ID" >> $GITHUB_OUTPUT if [ $(expr length "${{ secrets.USERNAME }}") -gt "1" ]; then echo "uploadtoserver=true" >> $GITHUB_OUTPUT; fi - - name: Install Bundler - run: sudo gem install bundler - - name: Cache bundle - uses: actions/cache@v3 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - - name: Install Jekyll - run: bundle install + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - run: | + echo "baseurl: /${{ steps.prepare.outputs.prid }}" >> _config.yml - name: Build the site with Jekyll - run: | - bundle exec jekyll build --future --baseurl "/${{ steps.prepare.outputs.prid }}" - mkdir ${{ steps.prepare.outputs.prid }} + run: nix build - name: Upload preview run: | mkdir -p "$HOME/.ssh" echo "${{ secrets.KEY }}" > "$HOME/.ssh/key" chmod 600 "$HOME/.ssh/key" - rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/_site/ "${{ secrets.USERNAME }}@delta.chat:/var/www/html/staging/${{ steps.prepare.outputs.prid }}/" + rsync -rLtvh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/result/ "${{ secrets.USERNAME }}@delta.chat:/var/www/html/staging/${{ steps.prepare.outputs.prid }}/" - name: "Post links to details" id: details @@ -54,8 +45,8 @@ jobs: #check if comment already exists, if not post it export GITHUB_API_URL="https://api.github.com/repos/deltachat/deltachat-pages/issues/${{ steps.prepare.outputs.prid }}/comments" export RESPONSE=$(curl -L --header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" --url "$GITHUB_API_URL" --header "content-type: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28") - echo $RESPONSE > result - grep -v '"Check out the page preview at https://staging.delta.chat/' result && echo "comment=true" >> $GITHUB_OUTPUT || true + echo $RESPONSE > response + grep -v '"Check out the page preview at https://staging.delta.chat/' response && echo "comment=true" >> $GITHUB_OUTPUT || true - name: "Post link to comments" if: steps.details.outputs.comment uses: actions/github-script@v6 diff --git a/.gitignore b/.gitignore index 1e237dcd3..b482f00e5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,7 @@ build/ # for an optional virtual env folder venv/ -vendor/bundle \ No newline at end of file +vendor/bundle + +# Nix output. +result diff --git a/README.md b/README.md index 1e941cf65..6f0e204b3 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,13 @@ Testing changes the forked website will then be available at `https://.github.io/deltachat-pages/` +- If you have Nix installed, + you can build website preview in `result/` with `nix build` + or run `nix develop` and start `jekyll serve` in development shell + to have live preview at http://127.0.0.1:4000/en/ + If you don't have Nix installed, + you can install it with [The Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer). + - Alternatively, [install Jekyll](https://jekyllrb.com/docs/installation/) on your local machive, run `bundle install` in this directory, and execute `bundle exec jekyll serve`. diff --git a/_sass/_base.scss b/_sass/_base.scss index d6849a305..a6e4ac792 100644 --- a/_sass/_base.scss +++ b/_sass/_base.scss @@ -237,7 +237,7 @@ code { h1,h2,h3,h4,h5,h6 { &:hover { .anchor::before { - content: "🔗" + content: "\1F517" } } } diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..d7f08ad1c --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711231723, + "narHash": "sha256-dARJQ8AJOv6U+sdRePkbcVyVbXJTi1tReCrkkOeusiA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e1d501922fd7351da4200e1275dfcf5faaad1220", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..5adb5d739 --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + description = "Jekyll website template"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + formatter = pkgs.nixpkgs-fmt; + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.ruby + pkgs.jekyll + pkgs.rubyPackages.jekyll-sitemap + ]; + }; + + packages.default = pkgs.stdenv.mkDerivation { + name = "deltachat-pages"; + src = ./.; + buildInputs = [ + pkgs.ruby + pkgs.jekyll + pkgs.rubyPackages.jekyll-sitemap + ]; + buildPhase = '' + jekyll build + ''; + installPhase = ''cp -r _site $out''; + }; + }); +}