-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Rework setup script #27
base: main
Are you sure you want to change the base?
Conversation
I’m going to heavily annotate the changes I made to explain why. It makes a lot of changes that may or may not work with your ultimate goals, but inasmuch as I can test it locally (when I have everything except PostgreSQL installed), it seems to work once I added a $ mkdir z && touch z/{.bashrc,.zshrc}
$ DRY_RUN=1 HOME=z priv/scirpt.sh |
@@ -2,441 +2,490 @@ | |||
|
|||
set -eu | |||
|
|||
elixir_version=1.17.3-otp-27 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these to the top of the script because they are the things most likely to be updated frequently. I have also updated them to the latest versions for Elixir and OTP.
e76cd1b
to
09316ee
Compare
phoenix_version=1.7.14 | ||
postgres_version=15.1 | ||
|
||
OS="$(uname -s)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been partially moved upwards to improve $HOME
resolution. See below.
;; | ||
esac | ||
|
||
has() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simplifies reading some tests. I also modified a couple of cases where mise which
was used to match the versions installed. This can be simplified if you just want to use any installed version of Elixir and/or OTP.
if [ "$os_type" = Linux ]; then | ||
HOME="$(getent passwd "$USER" 2>/dev/null | cut -d: -f6)" | ||
elif [ "$os_type" = macOS ]; then | ||
HOME="$(dscl . -read /Users/"$USER" NFSHomeDirectory)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how you read the home directory on macOS. It means that the fallback on line 53 is less necessary in general.
phx_tools_path="$HOME"/.config/phx_tools | ||
phx_tools_sh_path="$phx_tools_path"/phx_tools.sh | ||
phx_tools_fish_path="$phx_tools_path"/phx_tools.fish | ||
homebrew_path= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These simplify processing later.
priv/script.sh
Outdated
|
||
# Disable colour output if NO_COLOR is set to any value at all. | ||
# https://no-color.org | ||
if [ -n "${NO_COLOR:-}" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$NO_COLOR
should be respected, and tput
should be preferred over explicit ANSI escapes.
printf "Invalid name argument on checking: %s\n" "$1" | ||
exit 1 | ||
;; | ||
install_deps() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
install_deps()
was added because it simplifies the reading and reasoning about the various steps.
dnf) sudo dnf install -y unzip ;; | ||
pacman) sudo pacman -Sy --noconfirm unzip ;; | ||
apk) sudo apk add --no-cache unzip ;; | ||
esac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If set -e
requires case "completeness" to prevent an error halt, then add *) : ;;
to the end of the case
block and it will swallow unknown values.
printf "%s is already installed. Skipping...\n" "$1" | ||
else | ||
printf "Installing %s...\n" "$1" | ||
install_shell_scripts() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the real change here. Instead of modifying just ~/.bashrc
, ~/.zshrc
, or ~/.config/fish/config.fish
, we're creating ~/.config/phx_tools/phx_tools.{sh,fish}
with the appropriate configuration changes.
The sh
version is written to work with both Bash and zsh.
install "$1" | ||
sh_source_line="source '$phx_tools_sh_path'" | ||
|
||
if has bash && [ -f "$HOME"/.bashrc ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we update $HOME/.bashrc
to source ~/.config/phx_tools/phx_tools.sh
, but only if bash is installed and ~/.bashrc
exists.
|
||
sleep 3 | ||
printf "%s\n" "$bblue$banner" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the print statements have been condensed to reduce the whitespace. It was scrolling too much on my 56-line shell.
Wow, the best PR I've seen in my life! Most of the things you've changed I agree with. The rest I don't understand yet. I'm only worried about whether we'll still be able to run the GitHub Actions workflow with these changes. phx.tools/test/scripts/script.exp Lines 1 to 9 in a24a101
But they failed at line spawn ./../../priv/script.sh
tput: No value for $TERM and no -T specified |
Thanks for the kind words. I’ve been shell scripting for decades now, so this really wasn't too hard.
I didn't look at this from the perspective of testing, but from user experience. The test failures did point out a bug, and I should have tested for it, but it's sort of hard to test for on a machine. I’ve put a fixup commit that should resolve the test failures in the expect script. It makes a couple of changes to the expect script to make sure that a bit more is seen than was previously expected. |
spawn ./../../priv/script.sh
Unsupported shell: bash
expect: spawn id exp3 not open
while executing
"expect "phx.tools setup is complete!""
(file "script.exp" line 13) This time I think it's because of this line */bash | */fish | */zsh) : ;; phx.tools/.github/workflows/pr.yml Lines 289 to 292 in a24a101
https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defaultsrunshell Not sure if /bin/ prefix works for the shell option.
|
I'll look at that a bit later. Probably by pushing a debugging fix. |
4c0cf37
to
6b583d5
Compare
- Add dependency checking with dependabot. - Put more specific version locks for actions. - Upgrade actions which were using Node 16 actions.
bd54cb5
to
9319c8e
Compare
@@ -0,0 +1,11 @@ | |||
version: 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this because when I tested the workflows locally, I got warnings about Node 16 workflows. You can remove if you like.
uses: "superfly/flyctl-actions/setup-flyctl@master" | ||
uses: "superfly/flyctl-actions/[email protected]", | ||
with: [ | ||
version: "0.3.40" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup-flyctl
action recommends pinning the flyctl version for production releases, so I did so in addition to pinning the action version itself. This will need monitoring separately for upgrades.
@@ -227,7 +230,7 @@ defmodule GithubWorkflows do | |||
steps: [ | |||
[ | |||
name: "Restore PLT cache", | |||
uses: "actions/cache@v3", | |||
uses: "actions/cache@v4.1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v3 uses node 16, v4 uses node 20.
@@ -455,7 +458,7 @@ defmodule GithubWorkflows do | |||
[ | |||
name: "Check HTTP status code", | |||
if: "steps.result_cache.outputs.cache-hit != 'true'", | |||
uses: "nick-fields/retry@v2", | |||
uses: "nick-fields/retry@v3.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2 uses node 16; v3 uses node 20.
Addresses #20 (comment).