From a2bc008f1f4fbe73966e124056e0106b919beb99 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 3 Jul 2024 10:22:54 +0200 Subject: [PATCH] ci: add preview deployments --- .github/workflows/ci.yaml | 88 ++++++++++++++++----------------------- derivation.nix | 4 +- flake.nix | 5 +++ package.json | 3 +- 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 253f536..5a09eca 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,76 +3,62 @@ name: CI on: push: branches: [ master ] - tags: [ 'v*' ] pull_request: +permissions: + deployments: write + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4.0.0 + - name: Checkout repository + uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'pnpm' + - name: Install Nix + uses: cachix/install-nix-action@V27 - - run: pnpm install --frozen-lockfile - - run: pnpm run build:ci + - name: Build + run: nix build -L - uses: actions/upload-artifact@v4 with: - name: presence - path: dist + name: website + path: result - - docker: - needs: [ build ] + deploy: runs-on: ubuntu-latest - - permissions: - packages: write + needs: build steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: - name: presence - path: dist + - name: Install Nix + uses: cachix/install-nix-action@V27 - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - ghcr.io/${{ github.repository }} - tags: | - type=edge - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - - - uses: docker/setup-qemu-action@v3 - - uses: docker/setup-buildx-action@v3 + - name: Build Static + run: nix build -L .#website-static - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - if: github.event_name != 'pull_request' + - uses: actions/upload-artifact@v4 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ github.token }} + name: website-static + path: result - - name: Build - uses: docker/build-push-action@v5 + - name: Patch + run: | + mv result result-old + mkdir result + cp -r result-old/* result + chmod +w -R result + echo "User-agent: *\nDisallow: /" > result/browser/robots.txt + + - name: Publish to Cloudflare Pages + uses: cloudflare/pages-action@v1 with: - file: Dockerfile.github-actions - context: . - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: 2a09613716e511a8fe8ca74abc084762 + projectName: dd-ix + directory: result/browser + gitHubToken: ${{ github.token }} diff --git a/derivation.nix b/derivation.nix index bee7313..4b0b94d 100644 --- a/derivation.nix +++ b/derivation.nix @@ -1,4 +1,4 @@ -{ domain, mkPnpmPackage }: +{ domain, mkPnpmPackage, static ? false }: mkPnpmPackage { src = ./.; @@ -10,7 +10,7 @@ mkPnpmPackage { --replace 'http://127.0.0.1:8080' 'https://content.${domain}' ''; - script = "build:ci"; + script = if static then "build:static" else "build:ci"; installPhase = '' mkdir -p $out diff --git a/flake.nix b/flake.nix index 9860a11..9d301f1 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,11 @@ domain = "dd-ix.net"; mkPnpmPackage = pnpm2nix.packages."${system}".mkPnpmPackage; }; + website-static = pkgs.callPackage ./derivation.nix { + domain = "dd-ix.net"; + static = true; + mkPnpmPackage = pnpm2nix.packages."${system}".mkPnpmPackage; + }; default = website; }; } diff --git a/package.json b/package.json index 94ee621..ee660cd 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "start": "ng serve", "build": "ng build --output-path ./dist", "build:ci": "ng build --output-path ./dist --localize && rollup -c rollup.config.mjs", + "build:static": "ng build --output-path ./dist --localize --ssr=false", "watch": "ng build --watch --configuration development", "test": "ng test", "test:ci": "ng test --no-watch --no-progress --browsers=ChromeHeadless", @@ -56,4 +57,4 @@ "rollup": "^4.17.2", "typescript": "~5.4.5" } -} \ No newline at end of file +}