Skip to content

Commit

Permalink
ci: add preview deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Jul 3, 2024
1 parent 4f77115 commit f1f8be8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 55 deletions.
84 changes: 32 additions & 52 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,56 @@ 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
uses: 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}}
- name: Build Static
uses: nix build -L .#website-static

- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Patch
run: |
mv result result-old
mkdir result
cp result-old/* result
echo "User-agent: *\nDisallow: /" > result/browser/robots.txt
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build
uses: docker/build-push-action@v5
- 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 }}
4 changes: 2 additions & 2 deletions derivation.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ domain, mkPnpmPackage }:
{ domain, mkPnpmPackage, static ? false }:

mkPnpmPackage {
src = ./.;
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -56,4 +57,4 @@
"rollup": "^4.17.2",
"typescript": "~5.4.5"
}
}
}

0 comments on commit f1f8be8

Please sign in to comment.