Skip to content

Commit

Permalink
meta/add netlify deploy (#15)
Browse files Browse the repository at this point in the history
* Added a workflow to publish to netlify.

* Try making a derivation to build the site rather than doing all the build steps on netlify. Had to remove the social plugin for now because it is trying to fetch fonts from Google during build.

* Typos man.

* One more little fix. Don't need to reference site because we are building the whole site with a derivation.

* Use actions/checkout version 4.

* Added a MAINTAINERS file with helpful breadcrumbs for how the repo and site are managed.

* With nix buildings options and examples, we can ignore these directories and files and not commit them to the repo.
  • Loading branch information
djacu authored Feb 7, 2024
1 parent 5d326de commit 599fd3b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 20 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/netlify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# .github/workflows/netlify.yml
name: Build and Deploy to Netlify

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build Site
run: |
nix build .#site
mkdir ./dist
cp -R ./result/* ./dist/
chmod -R +w ./dist/
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v2.0
with:
publish-dir: './dist'
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy from GitHub Actions"
enable-pull-request-comment: true
enable-commit-comment: true
enable-commit-status: true
overwrites-pull-request-comment: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
### Any locally created PDF files ###
*.pdf

### Nix ###
result

### Site ###
site/.cache
# Examples are included during nix build except for the index file
!site/docs/examples/index.md
site/docs/examples/
# Options docs are included during nix build
site/docs/documentation/modules/
27 changes: 27 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Site

## Netlify setup

1. Go to Netlify create site page
1. Select GitHub and pick the template repo you created in the Getting Started step.
1. Finally click on the Deploy site button.

## Steps to integrate with nwtgck/actions-netlify

- Setup personal access token from netlify
1. Go [here](https://app.netlify.com/user/applications#personal-access-tokens)
1. Personal access token -> New access token
1. Go to repo -> Settings -> Security -> Secrets and variables -> Actions -> Repository secrets
1. Store the token as `NETLIFY_AUTH_TOKEN`
- Setup site ID from netlify
1. Go to netlify -> team page -> the site -> Site configuration -> Site information
1. There is a field `Site ID`; copy that token
1. Go to repo -> Settings -> Security -> Secrets and variables -> Actions -> Repository secrets
1. Store the token as `NETLIFY_SITE_ID`
- Let the action write comments on PRs
1. Go to repo -> Settings -> Code and automation -> Actions -> General -> Workflow permissions
1. Check 'Read and write permissions'
- Turn off Netlify's Deploy Previews
1. Go to [Site configuration -> Build & deploy -> Continuous Deployment -> Branches and deploy contexts](https://app.netlify.com/sites/nixcv/configuration/deploys#branches-and-deploy-contexts)
1. Select `Configure`
1. Under Deploy Previews, select `None`
37 changes: 18 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,23 @@
projectDir = self + /site;
python = pkgs.python311;
};
#
#mkdocs = pkgs.python311.withPackages (ps: [
# ps.mkdocs
# ps.mkdocs-material
#]);
#
#site = pkgs.stdenvNoCC.mkDerivation {
# name = "nixcv-site";
# src = self + "/site";
# nativeBuildInputs = [mkdocs];
#
# buildPhase = ''
# mkdocs build --site-dir dist
# '';
# installPhase = ''
# mkdir $out
# cp -R dist/* $out/
# '';
#};

site = pkgs.stdenvNoCC.mkDerivation {
name = "nixcv-site";
src = self + "/site";
nativeBuildInputs = [site-env];

buildPhase = ''
cp -r ${moduleMarkdownDocs}/* ./docs/documentation/
cp -r ${examplePdfDocs}/* ./docs/
ls -FhoAR
mkdocs build --site-dir dist
'';
installPhase = ''
mkdir $out
cp -R dist/* $out/
'';
};
in {
devShells = {
poetry = pkgs.mkShell {
Expand Down Expand Up @@ -130,6 +128,7 @@
inherit
moduleMarkdownDocs
examplePdfDocs
site
;
};

Expand Down
2 changes: 1 addition & 1 deletion site/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ theme:

plugins:
- blog
- social
#- social
- macros

extra:
Expand Down

1 comment on commit 599fd3b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://nixcv.netlify.app as production
🚀 Deployed on https://65c2f548c67b7d241a9868e7--nixcv.netlify.app

Please sign in to comment.