From 810af895460b0b84291bbc4dda38569b9c1bf71a Mon Sep 17 00:00:00 2001 From: Lova Andriarimalala <43842786+Xpirix@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:02:19 +0300 Subject: [PATCH] Add flake and related GH workflows --- .github/workflows/cachix-build.yml | 25 ++++++++++++ .github/workflows/flake-update.yml | 37 +++++++++++++++++ .github/workflows/github-pages.yml | 2 +- .github/workflows/playwright-e2e.yml | 2 +- .github/workflows/update-feeds.yml | 5 ++- flake.nix | 59 ++++++++++++++++++++++++++++ package.nix | 32 +++++++++++++++ 7 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/cachix-build.yml create mode 100644 .github/workflows/flake-update.yml create mode 100644 flake.nix create mode 100644 package.nix diff --git a/.github/workflows/cachix-build.yml b/.github/workflows/cachix-build.yml new file mode 100644 index 000000000..e83ee5d92 --- /dev/null +++ b/.github/workflows/cachix-build.yml @@ -0,0 +1,25 @@ +# Workflow to build and push the static hugo files to Cachix +name: 🛫 Build and push to Cachix + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v25 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: cachix/cachix-action@v14 + with: + name: qgis-org + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix build .#qgis-website + - run: nix flake check \ No newline at end of file diff --git a/.github/workflows/flake-update.yml b/.github/workflows/flake-update.yml new file mode 100644 index 000000000..58436207c --- /dev/null +++ b/.github/workflows/flake-update.yml @@ -0,0 +1,37 @@ +name: Update Nix Flake inputs + +on: + schedule: + - cron: '0 1 * * *' + workflow_dispatch: + +jobs: + test: + name: Update flakes and commit changes + runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + # This will allow us to trigger other workflows (cachix-build, etc.) + # when we commit changes using the git-auto-commit-action + token: ${{ secrets.PAT }} + + - name: Install Nix + uses: cachix/install-nix-action@v25 + + - name: Run nix flake update + run: > + nix flake update + + - name: '✉️ Commit' + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'Flakes updated and committed via a GitHub Action.' + diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 69914bc56..87e4e3a1d 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -37,7 +37,7 @@ jobs: wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Setup Pages diff --git a/.github/workflows/playwright-e2e.yml b/.github/workflows/playwright-e2e.yml index aaa0f5dde..f323ceefa 100644 --- a/.github/workflows/playwright-e2e.yml +++ b/.github/workflows/playwright-e2e.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 🛒 Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: 🛠️ Setup Hugo uses: peaceiris/actions-hugo@v3 diff --git a/.github/workflows/update-feeds.yml b/.github/workflows/update-feeds.yml index 1a023fed9..441cde64a 100644 --- a/.github/workflows/update-feeds.yml +++ b/.github/workflows/update-feeds.yml @@ -13,10 +13,13 @@ jobs: if: github.repository_owner == 'qgis' steps: - name: '🛒 Checkout QGIS Website' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: main path: ./qgis-website + # This will allow us to trigger other workflows (cachix-build, etc.) + # when we commit changes using the git-auto-commit-action + token: ${{ secrets.PAT }} - name: '🐍 Setup Python' uses: actions/setup-python@v3 diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..a546e5103 --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + description = "Development environment and build process for a Hugo app with Python requirements"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + + # Importing packages from nixpkgs + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; # Allow unfree packages like VSCode if needed + }; + + + mkDevShell = pkgs.mkShell { + packages = with pkgs; [ + hugo # Hugo for building the website + vscode # VSCode for development + python312Packages.icalendar # Python packages + python312Packages.requests # Python packages + gnumake # GNU Make for build automation + ]; + + shellHook = '' + export DIRENV_LOG_FORMAT= + echo "-----------------------" + echo "🌈 Your Hugo Dev Environment is ready." + echo "It provides hugo and vscode for use with the QGIS Website Project" + echo "" + echo "🪛 VSCode:" + echo "--------------------------------" + echo "Start vscode like this:" + echo "" + echo "./vscode.sh" + echo "" + echo "🪛 Hugo:" + echo "--------------------------------" + echo "Start Hugo like this:" + echo "" + echo "hugo server" + echo "-----------------------" + ''; + }; + + in + { + devShells.x86_64-linux.default = mkDevShell; + + packages = { + x86_64-linux = { + qgis-website = pkgs.callPackage ./package.nix {}; + }; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 000000000..cd412a0c8 --- /dev/null +++ b/package.nix @@ -0,0 +1,32 @@ +{ lib, stdenv, hugo, gnumake }: + +stdenv.mkDerivation { + name = "qgis-website"; + src = lib.cleanSourceWith { + src = ./.; + filter = ( + path: type: (builtins.all (x: x != baseNameOf path) [ + ".git" + ".github" + "flake.nix" + "package.nix" + ]) + ); + }; + buildInputs = [ hugo gnumake ]; + + buildPhase = '' + make deploy + ''; + + installPhase = '' + mkdir -p $out + cp -r public_www public_prod $out/ + ''; + + meta = with lib; { + description = "A built QGIS website"; + license = licenses.mit; + }; +} +