diff --git a/.github/workflows/direnv.yml b/.github/workflows/direnv.yml new file mode 100644 index 00000000..96c85f75 --- /dev/null +++ b/.github/workflows/direnv.yml @@ -0,0 +1,45 @@ +name: direnv +on: + push: + paths: + - programs/direnv/install.bash + - .github/workflows/direnv.yml + schedule: + # Not at the start of an hour or a day to decreate the chance of delay. + # See schedule documentation. + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule + - cron: "17 5 * * *" + + workflow_dispatch: + +jobs: + test_idempotent_installation: + + strategy: + matrix: + os: + - "ubuntu:20.04" + - "ubuntu:22.04" + + runs-on: ubuntu-latest + container: + image: "${{ matrix.os }}" + + steps: + + - name: Check out code + uses: actions/checkout@v3 + + - name: Prepare Docker + run: ./scripts/prepare_docker.bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install direnv + shell: su norm --command "bash --login {0}" + run: programs/direnv/install.bash + + - name: Install direnv again (test idempotency) + shell: su norm --command "bash --login {0}" + run: programs/direnv/install.bash + diff --git a/programs/direnv/install.bash b/programs/direnv/install.bash new file mode 100755 index 00000000..89a2dd73 --- /dev/null +++ b/programs/direnv/install.bash @@ -0,0 +1,35 @@ +#!/bin/bash + +# Name: direnv +# https://github.com/direnv/direnv + +set -euxo pipefail + +cd "$(mktemp --dir)" + +sudo apt-get update + +sudo apt-get --assume-yes install \ +curl \ +jq + +browser_download_url=$( + curl -Ss 'https://api.github.com/repos/direnv/direnv/releases/latest' | + jq -r '.assets[] | select(.name == "direnv.linux-amd64") | .browser_download_url' +) + +download_filename=$( + curl \ + --silent \ + --show-error \ + --url "$browser_download_url" \ + --location \ + --remote-name \ + --write-out '%{filename_effective}' +) + +chmod +x "${download_filename}" + +sudo mv "${download_filename}" /usr/local/bin/direnv + +direnv --version