Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add preview deployments #82

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 37 additions & 51 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
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"
}
}
}
Loading