From e61b2bff176fda9164f41b2239fb4c5ef1e387d8 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 7 Oct 2023 01:30:42 +0100 Subject: [PATCH] build: replace justfile with run --- .github/workflows/ci.yml | 8 +--- build.yaml | 1 - flake.nix | 1 - justfile | 18 --------- run | 76 +++++++++++++++++++++++++++++++++++ tools/scripts/create-daily.sh | 42 ------------------- 6 files changed, 78 insertions(+), 68 deletions(-) delete mode 100644 justfile create mode 100755 run delete mode 100755 tools/scripts/create-daily.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ded64d8..b0841d05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,15 +15,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 - - uses: extractions/setup-just@95b912dc5d3ed106a72907f2f9b91e76d60bdb76 # 1.5.0 - uses: cachix/install-nix-action@6ed004b9ccb68dbc28e7c85bee15fa93dbd214ac # v22 with: nix_path: nixpkgs=channel:nixos-unstable - run: | - nix develop --command yarn - nix develop --command yarn build + ./run ci:build - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: @@ -37,8 +35,6 @@ jobs: steps: - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 - - uses: extractions/setup-just@95b912dc5d3ed106a72907f2f9b91e76d60bdb76 # 1.5.0 - - name: Add the deployment SSH key uses: shimataro/ssh-key-action@3c9b0fc6f2d223b8450b02a0445f526350fc73e0 # 2.3.1 with: @@ -52,6 +48,6 @@ jobs: path: dist - run: | - just deploy ${{ github.sha }} + ./run ci:deploy ${{ github.sha }} # vim: sw=2 ts=2 diff --git a/build.yaml b/build.yaml index bed59937..5e11dd55 100644 --- a/build.yaml +++ b/build.yaml @@ -6,6 +6,5 @@ flake: devshell: packages: - awscli - - just - nodejs_20 - yarn diff --git a/flake.nix b/flake.nix index e495e50d..044a46a9 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,6 @@ devshells.default = { packages = with pkgs; [ "awscli" - "just" "nodejs_20" "yarn" ]; diff --git a/justfile b/justfile deleted file mode 100644 index 0166f878..00000000 --- a/justfile +++ /dev/null @@ -1,18 +0,0 @@ -# https://github.com/casey/just - -default: - just --list - -start: - nix develop --command yarn astro dev --open - -create-daily date title: - #!/usr/bin/env bash - nvim $(./tools/scripts/create-daily.sh {{ date }} "{{ title }}") - -deploy sha: - rsync -r -avhP --delete dist/* opdavies@104.248.165.137:/srv/oliverdavies.uk - -format: - yarn prettier --write src/**/*.{astro,mdx} - yarn rustywind src diff --git a/run b/run new file mode 100755 index 00000000..50462a40 --- /dev/null +++ b/run @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +set -eu + +TTY="${TTY:-}" +if [[ ! -t 1 ]]; then + TTY="-T" +fi + +# Build the website within the continuous integration (CI) pipeline. +function ci:build { + nix develop --command yarn + nix develop --command yarn build +} + +# Deploy the website within the continuous integration (CI) pipeline. +function ci:deploy { + rsync -r -avhP --delete dist/* opdavies@104.248.165.137:/srv/oliverdavies.uk +} + +# Create a new daily email. +function create-daily { + local date="${1}" + local title="${2}" + + if [ "${date}" == "next" ]; then + next_date=$(ls -1 src/content/daily-email | tail -n 1 | tr -d '.md' | xargs -I {} date +%Y-%m-%d -d '{} +1 day') + else + next_date="${date}" + fi + + filepath="src/content/daily-email/${next_date}.md" + + shift 1 + + # Generate the title and slug. + title="${*}" + slug=$(echo "${title}" | \ + tr '[:upper:]' '[:lower:]' | \ + sed 's/[^a-z0-9]/-/g' | \ + sed 's/\-\-+/-/g' | \ + sed 's/^\-//;s/\-$//') + + # Create the file. + cp -f --no-clobber stub.md "${filepath}" + + date=$(date -d "${next_date}" +%Y-%m-%d) + day=$(date -d "${next_date}" +%d) + month=$(date -d "${next_date}" +%m) + year=$(date -d "${next_date}" +%Y) + + # Replace the placeholders. + sed -i "s/{{ date }}/${date}/" "${filepath}" + sed -i "s/{{ title }}/${title}/" "${filepath}" + sed -i "s#{{ permalink }}#archive/${year}/${month}/${day}/${slug}#" "${filepath}" + + # Create a commit with the appropriate date in the message + git add "${filepath}" + git commit --quiet -m "daily-email: add ${date} + + ${title}" + + echo "${filepath}" +} + +# Display a list of all available commands. +function help { + printf "%s args\n\nTasks:\n" "${0}" + + compgen -A function | grep -v "^_" | cat -n + + printf "\nExtended help:\n Each task has comments for general usage\n" +} + +TIMEFORMAT=$'\nTask completed in %3lR' +time "${@:-help}" diff --git a/tools/scripts/create-daily.sh b/tools/scripts/create-daily.sh deleted file mode 100755 index 59442615..00000000 --- a/tools/scripts/create-daily.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -if [ "${1}" == "next" ]; then - next_date=$(ls -1 src/content/daily-email | tail -n 1 | tr -d '.md' | xargs -I {} date +%Y-%m-%d -d '{} +1 day') -else - next_date="${1}" -fi - -filepath="src/content/daily-email/${next_date}.md" - -shift 1 - -# Generate the title and slug. -title="${*}" -slug=$(echo "${title}" | \ - tr '[:upper:]' '[:lower:]' | \ - sed 's/[^a-z0-9]/-/g' | \ - sed 's/\-\-+/-/g' | \ - sed 's/^\-//;s/\-$//') - -# Create the file. -cp -f --no-clobber stub.md "${filepath}" - -date=$(date -d "${next_date}" +%Y-%m-%d) -day=$(date -d "${next_date}" +%d) -month=$(date -d "${next_date}" +%m) -year=$(date -d "${next_date}" +%Y) - -# Replace the placeholders. -sed -i "s/{{ date }}/${date}/" "${filepath}" -sed -i "s/{{ title }}/${title}/" "${filepath}" -sed -i "s#{{ permalink }}#archive/${year}/${month}/${day}/${slug}#" "${filepath}" - -# Create a commit with the appropriate date in the message -git add "${filepath}" -git commit --quiet -m "daily-email: add ${date} - -${title}" - -echo "${filepath}"