diff --git a/.gitignore b/.gitignore index dfc38dc..02580d4 100644 --- a/.gitignore +++ b/.gitignore @@ -177,7 +177,6 @@ fabric.properties .idea */local_testing.toml .direnv/ -etc/ var/ docker-image.tar.gz .guix-root diff --git a/channels-lock.scm b/channels-lock.scm index d536362..520f730 100644 --- a/channels-lock.scm +++ b/channels-lock.scm @@ -5,7 +5,7 @@ (name 'guix) (url "https://git.savannah.gnu.org/git/guix.git") (commit - "07f55a361e23152b48f34425f116a725cce39e48") + "72abf9b9b82d2f5f34b7d22b7aae6f2398336a93") (introduction (make-channel-introduction "afb9f2752315f131e4ddd44eba02eed403365085" diff --git a/docker/mobilizon-reshare.scm b/docker/mobilizon-reshare.scm index c03bb5f..aae1eb8 100644 --- a/docker/mobilizon-reshare.scm +++ b/docker/mobilizon-reshare.scm @@ -246,28 +246,31 @@ simplify testing of asynchronous tornado applications.") #:select? (git-predicate %source-dir))) (build-system python-build-system) (arguments - `(#:phases - (modify-phases %standard-phases - (add-after 'unpack 'generate-setup.py - (lambda* (#:key inputs outputs #:allow-other-keys) - ;; This is a hack needed to get poetry's - ;; setup.py. - (setenv "POETRY_VIRTUALENVS_CREATE" "false") - (invoke "poetry" "build" "-f" "sdist") - (invoke "bash" "-c" - "tar --wildcards -xvf dist/*-`poetry version -s`.tar.gz -O '*/setup.py' > setup.py"))) - (replace 'check - (lambda* (#:key tests? inputs outputs #:allow-other-keys) - (when tests? - (setenv "POETRY_VIRTUALENVS_CREATE" "false") - (invoke "./scripts/run_pipeline_tests.sh")))) - (add-before 'sanity-check 'set-dummy-config - (lambda _ - ;; This is needed to prevent the tool from - ;; crashing at startup during the sanity check. - (setenv "SECRETS_FOR_DYNACONF" - (string-append (getcwd) - "/mobilizon_reshare/.secrets.toml"))))))) + (list #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'generate-setup.py + (lambda _ + ;; This is a hack needed to get poetry's + ;; setup.py. + (setenv "POETRY_VIRTUALENVS_CREATE" "false") + (invoke "poetry" "build" "-f" "sdist") + (invoke "bash" "-c" + "tar --wildcards -xvf dist/*-`poetry version -s`.tar.gz -O '*/setup.py' > setup.py"))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (setenv "POETRY_VIRTUALENVS_CREATE" "false") + (invoke "./scripts/run_pipeline_tests.sh")))) + (add-after 'install 'install-completion-scripts + (lambda _ + (copy-recursively "etc" (string-append #$output "/etc")))) + (add-before 'sanity-check 'set-dummy-config + (lambda _ + ;; This is needed to prevent the tool from + ;; crashing at startup during the sanity check. + (setenv "SECRETS_FOR_DYNACONF" + (string-append (getcwd) + "/mobilizon_reshare/.secrets.toml"))))))) (native-inputs (list python-iniconfig poetry diff --git a/etc/bash_completion.d/mobilizon-reshare-completion.bash b/etc/bash_completion.d/mobilizon-reshare-completion.bash new file mode 100644 index 0000000..b3f3b5f --- /dev/null +++ b/etc/bash_completion.d/mobilizon-reshare-completion.bash @@ -0,0 +1,29 @@ +_mobilizon_reshare_completion() { + local IFS=$'\n' + local response + + response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _MOBILIZON_RESHARE_COMPLETE=bash_complete $1) + + for completion in $response; do + IFS=',' read type value <<< "$completion" + + if [[ $type == 'dir' ]]; then + COMPREPLY=() + compopt -o dirnames + elif [[ $type == 'file' ]]; then + COMPREPLY=() + compopt -o default + elif [[ $type == 'plain' ]]; then + COMPREPLY+=($value) + fi + done + + return 0 +} + +_mobilizon_reshare_completion_setup() { + complete -o nosort -F _mobilizon_reshare_completion mobilizon-reshare +} + +_mobilizon_reshare_completion_setup; + diff --git a/etc/fish/completions/mobilizon-reshare.fish b/etc/fish/completions/mobilizon-reshare.fish new file mode 100644 index 0000000..aeac93f --- /dev/null +++ b/etc/fish/completions/mobilizon-reshare.fish @@ -0,0 +1,22 @@ +function _mobilizon_reshare_completion; + set -l response; + + for value in (env _MOBILIZON_RESHARE_COMPLETE=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) mobilizon-reshare); + set response $response $value; + end; + + for completion in $response; + set -l metadata (string split "," $completion); + + if test $metadata[1] = "dir"; + __fish_complete_directories $metadata[2]; + else if test $metadata[1] = "file"; + __fish_complete_path $metadata[2]; + else if test $metadata[1] = "plain"; + echo $metadata[2]; + end; + end; +end; + +complete --no-files --command mobilizon-reshare --arguments "(_mobilizon_reshare_completion)"; + diff --git a/etc/zsh/mobilizon-reshare-completion.zsh b/etc/zsh/mobilizon-reshare-completion.zsh new file mode 100644 index 0000000..fe9d6ab --- /dev/null +++ b/etc/zsh/mobilizon-reshare-completion.zsh @@ -0,0 +1,35 @@ +#compdef mobilizon-reshare + +_mobilizon_reshare_completion() { + local -a completions + local -a completions_with_descriptions + local -a response + (( ! $+commands[mobilizon-reshare] )) && return 1 + + response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _MOBILIZON_RESHARE_COMPLETE=zsh_complete mobilizon-reshare)}") + + for type key descr in ${response}; do + if [[ "$type" == "plain" ]]; then + if [[ "$descr" == "_" ]]; then + completions+=("$key") + else + completions_with_descriptions+=("$key":"$descr") + fi + elif [[ "$type" == "dir" ]]; then + _path_files -/ + elif [[ "$type" == "file" ]]; then + _path_files -f + fi + done + + if [ -n "$completions_with_descriptions" ]; then + _describe -V unsorted completions_with_descriptions -U + fi + + if [ -n "$completions" ]; then + compadd -U -V unsorted -a completions + fi +} + +compdef _mobilizon_reshare_completion mobilizon-reshare; + diff --git a/manifest.scm b/manifest.scm index d6fb027..5349477 100644 --- a/manifest.scm +++ b/manifest.scm @@ -1,14 +1,34 @@ (define-module (manifest) #:use-module (docker mobilizon-reshare) #:use-module (gnu packages) + #:use-module (guix channels) + #:use-module (guix inferior) #:use-module (guix packages) - #:use-module (guix profiles)) + #:use-module (guix profiles) + #:use-module (srfi srfi-1)) +(define channels + ;; This is the old revision from which we want to + ;; extract docker-compose. + (list (channel + (name 'guix) + (url "https://git.savannah.gnu.org/git/guix.git") + (commit + "07f55a361e23152b48f34425f116a725cce39e48")))) + +(define inferior + ;; An inferior representing the above revision. + (inferior-for-channels channels)) + +;; Now create a manifest with the current packages +;; and the old "docker-compose" package. (packages->manifest (append + ;; docker-compose fails to build on current master, hence this hack. + (list (first (lookup-inferior-packages inferior "docker-compose"))) (map cadr (package-direct-inputs mobilizon-reshare.git)) (map specification->package+output '("git-cal" "man-db" "texinfo" "python-pre-commit" "cloc" "ripgrep" "python-semver" - "fd" "docker-compose")))) + "fd")))) diff --git a/scripts/generate_completion_scripts.sh b/scripts/generate_completion_scripts.sh new file mode 100755 index 0000000..272753e --- /dev/null +++ b/scripts/generate_completion_scripts.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -eu + +export _MOBILIZON_RESHARE_COMPLETE=bash_source +scripts/mobilizon-reshare.sh > etc/bash_completion.d/mobilizon-reshare-completion.bash + +export _MOBILIZON_RESHARE_COMPLETE=fish_source +scripts/mobilizon-reshare.sh > etc/fish/completions/mobilizon-reshare.fish + +export _MOBILIZON_RESHARE_COMPLETE=zsh_source +scripts/mobilizon-reshare.sh > etc/zsh/mobilizon-reshare-completion.zsh diff --git a/scripts/release.sh b/scripts/release.sh index 26be1cc..2c46fce 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -6,6 +6,7 @@ myself="$(basename "$0")" version_file="$(pwd)/mobilizon_reshare/VERSION" pyproject_toml="$(pwd)/pyproject.toml" docker_compose_yml="$(pwd)/docker-compose.yml" +completion_dir="$(pwd)/etc" current_branch="$(git rev-parse --abbrev-ref HEAD)" current_commit="$(git log -1 --format='%H')" dryrun=0 @@ -74,19 +75,26 @@ current-version() { release-new-version() { current="$(current-version)" next="$(pysemver bump "$1" "$current")" - echo -e "\nRELEASING VERSION: ${next}" + echo "RELEASING VERSION: ${next}" - [ "$verbose" = "1" ] && echo "Updating $version_file" + [ "$verbose" = "1" ] && echo "Updating ${version_file}..." [ "$dryrun" = "0" ] && printf "%s" "$next" >"$version_file" - [ "$verbose" = "1" ] && echo "Updating $pyproject_toml" + [ "$verbose" = "1" ] && echo "Updating ${pyproject_toml}..." [ "$dryrun" = "0" ] && sed -i -E "s/version.*=.*\"${current}\"$/version = \"${next}\"/" "$pyproject_toml" - [ "$verbose" = "1" ] && echo "Updating $docker_compose_yml" + [ "$verbose" = "1" ] && echo "Updating ${docker_compose_yml}..." [ "$dryrun" = "0" ] && sed -i "s/${current}/${next}/" "$docker_compose_yml" - [ "$verbose" = "1" ] && echo "Committing ${pyproject_toml}, ${docker_compose_yml} and ${version_file}" - [ "$dryrun" = "0" ] && git add "$docker_compose_yml" "${pyproject_toml}" "${version_file}" && git commit -m "Release v${next}." + [ "$verbose" = "1" ] && echo "Generating completion scripts in ${completion_dir}..." + [ "$dryrun" = "0" ] && scripts/generate_completion_scripts.sh + + [ "$verbose" = "1" ] && echo "Committing ${pyproject_toml}, ${completion_dir}, ${docker_compose_yml} and ${version_file}" + [ "$dryrun" = "0" ] && git add "$docker_compose_yml" \ + "${pyproject_toml}" \ + "${completion_dir}" + "${version_file}" && \ + git commit -m "Release v${next}." [ "$verbose" = "1" ] && echo "Tagging Git HEAD with v${next}" [ "$dryrun" = "0" ] && git tag "v${next}"