Skip to content

Commit

Permalink
Refactor CI to use Nix (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri authored Aug 1, 2023
1 parent 6a4165b commit aac2228
Show file tree
Hide file tree
Showing 9 changed files with 5,026 additions and 31 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
result
41 changes: 41 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: docker-deploy
on:
push:
branches:
- main
tags:
- '**'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set ENV variables
run: |
echo "REGISTRY=ghcr.io" >> $GITHUB_ENV
echo "REPO_OWNER=$(echo ${GITHUB_REPOSITORY%/*})" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY#*/})" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
echo "DOCKER_TAG=$(echo ${GITHUB_REPOSITORY#*/}):$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/[email protected]
with:
install: true
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ${{env.REGISTRY}}
username: ${{env.REPO_OWNER}}
password: ${{secrets.CR_PAT}}
- name: Build and push
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: true
tags: ${{env.REGISTRY}}/${{env.REPO_OWNER}}/${{env.DOCKER_TAG}}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Execute tests
run: docker run -t --entrypoint="npm" ${REGISTRY}/${REPO_OWNER}/${DOCKER_TAG} run test
36 changes: 7 additions & 29 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
name: docker-based-ci
name: nix-based-ci
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set ENV variables
run: |
echo "REGISTRY=ghcr.io" >> $GITHUB_ENV
echo "REPO_OWNER=$(echo ${GITHUB_REPOSITORY%/*})" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY#*/})" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
echo "DOCKER_TAG=$(echo ${GITHUB_REPOSITORY#*/}):$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/[email protected]
with:
install: true
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ${{env.REGISTRY}}
username: ${{env.REPO_OWNER}}
password: ${{secrets.CR_PAT}}
- name: Build and push
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: true
tags: ${{env.REGISTRY}}/${{env.REPO_OWNER}}/${{env.DOCKER_TAG}}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Execute tests
run: docker run -t --entrypoint="npm" ${REGISTRY}/${REPO_OWNER}/${DOCKER_TAG} run test
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Run npm install & build
run: nix develop --command npm install && npm run build
- name: Run tests
run: nix develop --command npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
result
tmp
test-output.log
deno-bridge.js
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TODO
test
result
dist
docs
tmp
Expand Down
64 changes: 64 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
description = "A flake for qunitx npm package";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.napalm.url = "github:nix-community/napalm";

# NOTE: This is optional, but is how to configure napalm's env
inputs.napalm.inputs.nixpkgs.follows = "nixpkgs";

outputs = { self, nixpkgs, napalm }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages."${system}";
in {
packages."${system}".default = napalm.legacyPackages."${system}".buildPackage ./. {
nodejs = pkgs.nodejs_20;
PUPPETEER_SKIP_DOWNLOAD=1;
};

devShells."${system}".default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
deno
nodejs_20
];
};
};
}
Loading

0 comments on commit aac2228

Please sign in to comment.