Skip to content

Commit

Permalink
refactor: CI and nix (hmemcpy#306)
Browse files Browse the repository at this point in the history
* fix: remove custom fonts

Since they are available in Nix, there is no need to keep them in the project anymore

* chore: remove old obsolete files

* refactor: rewrite Nix files

- Switch from `numtide/flake-utils` to `flake-parts`
- Add custom font derivation for LaTeX
- Add `formatter`
- Switch to `python311`

* ci: update Github workflows

* feat: add `Makefile` for local development

Very useful when used in combination with `nix develop`

* feat: add `.envrc` file for loading development environment with `nix-direnv`

* feat: add `.editorconfig` and `.prettierrc`

* style: reformat files using `prettier`

Run `nix run nixpkgs#nodePackages.prettier -- --write .`

* fix: add workaround to prevent bug with `minted` package

see gpoore/minted#353 for context

* fix: add `version.tex` in the repo

* chore: rewrite `README`

* chore: ignore LaTeX temporary files while building locally

* feat: add `latexindent.pl` configuration file

* style: lint LaTeX files
  • Loading branch information
drupol authored Feb 2, 2023
1 parent 98b71ac commit de79993
Show file tree
Hide file tree
Showing 124 changed files with 2,432 additions and 2,296 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
indent_size = 4
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab

[*.{tex,cls,lua,nix}]
indent_style = space
indent_size = 2
max_line_length = 80

[*.md]
trim_trailing_whitespace = false
indent_size = 2
max_line_length = 80
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use flake .
use flake github:loophp/nix-prettier
51 changes: 51 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# https://github.com/probot/settings

branches:
- name: master
protection:
enforce_admins: false
required_pull_request_reviews:
dismiss_stale_reviews: true
require_code_owner_reviews: true
required_approving_review_count: 1
restrictions: null
required_linear_history: true
required_status_checks:
strict: true

labels:
- name: typo
color: ee0701

- name: dependencies
color: 0366d6

- name: enhancement
color: 0e8a16

- name: question
color: cc317c

- name: security
color: ee0701

- name: stale
color: eeeeee

repository:
allow_merge_commit: true
allow_rebase_merge: true
allow_squash_merge: true
default_branch: master
description:
"Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and
LaTeX sources"
homepage: https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
topics: pdf,haskell,scala,latex,cpp,functional-programming,ocaml,category-theory
has_downloads: true
has_issues: true
has_pages: false
has_projects: false
has_wiki: false
name: milewski-ctfp-pdf
private: false
117 changes: 0 additions & 117 deletions .github/workflows/build.yaml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/nix-flake-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Check and build

on:
pull_request:
push:
branches:
- master
jobs:
dependencies:
name: Build dependencies
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- name: Set up Git repository
uses: actions/checkout@v3

- name: Create global variables
id: version
run:
echo "version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

determine-matrix:
name: Figure out the packages we need to build
runs-on: ubuntu-latest
needs: [dependencies]

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
- name: Set up Git repository
uses: actions/checkout@v3

- name: Install the Nix package manager
uses: cachix/install-nix-action@v18

- id: set-matrix
run: |
echo "matrix=$(
nix eval --json .#packages.x86_64-linux --apply builtins.attrNames
)" >> $GITHUB_OUTPUT
build:
name: Build
needs: determine-matrix
runs-on: ubuntu-latest
strategy:
matrix:
packages: ${{fromJson(needs.determine-matrix.outputs.matrix)}}

steps:
- name: Set up Git repository
uses: actions/checkout@v3

- name: Install Nix
uses: cachix/install-nix-action@v18

- name: Nix flake check
run: nix flake check

- name: Build ${{ matrix.packages }}.pdf
run: nix build .#${{ matrix.packages }}
17 changes: 17 additions & 0 deletions .github/workflows/nix-fmt-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Nix formatter checks

on:
pull_request:

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Nix
uses: cachix/install-nix-action@v18

- name: Run nix formatter tool
run: nix fmt . -- --check
18 changes: 18 additions & 0 deletions .github/workflows/prettier-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Prettier checks

on:
pull_request:

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install the Nix package manager
uses: cachix/install-nix-action@v18

- name: Checks
run: nix run nixpkgs#nodePackages.prettier -- --check .
99 changes: 99 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release PDFs

on:
push:
tags:
- "**"

jobs:
determine-matrix:
name: Figure out the assets we need to build
runs-on: ubuntu-latest

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
- name: Set up Git repository
uses: actions/checkout@v3

- name: Install the Nix package manager
uses: cachix/install-nix-action@v18

- id: set-matrix
run: |
echo "matrix=$(
nix eval --json --impure \
--expr 'builtins.filter (x: (null == builtins.match "(.*)-nts" x)) (builtins.attrNames (import ./.).packages.x86_64-linux)'
)" >> $GITHUB_OUTPUT
build:
name: Build documents
needs: determine-matrix
runs-on: ubuntu-latest
strategy:
matrix:
packages: ${{fromJson(needs.determine-matrix.outputs.matrix)}}

steps:
- name: Set up Git repository
uses: actions/checkout@v3

- name: Install Nix
uses: cachix/install-nix-action@v18

- name: Build ${{ matrix.packages }}.pdf
run: |
nix build .#${{ matrix.packages }}
mkdir -p out
cp -ar ./result/* out/
- name: Upload build assets (${{ matrix.packages }}.pdf)
uses: actions/upload-artifact@v2
with:
name: ctfp
path: out/*

release:
name: "Create Github pre-release"
runs-on: ubuntu-latest
needs: [build]
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Github pre-release (${{ github.ref }})
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: true

assets:
name: Upload release assets
runs-on: ubuntu-latest
needs: [determine-matrix, release]
strategy:
matrix:
packages: ${{fromJson(needs.determine-matrix.outputs.matrix)}}

steps:
- name: Download build assets (${{ matrix.packages }}.pdf)
uses: actions/download-artifact@v2
with:
name: ctfp
path: ctfp

- name:
Upload release assets (${{ matrix.packages }}--${{ github.ref
}}.pdf)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ctfp/${{ matrix.packages }}.pdf
asset_name: ${{ matrix.packages }}--${{ github.ref }}.pdf
asset_content_type: application/pdf
Loading

0 comments on commit de79993

Please sign in to comment.