Skip to content
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

Improve env setup #35

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
# https://github.com/actions/runner-images#available-environments
# https://github.com/crystal-lang/crystal/issues/13846#issuecomment-2095027170
os: [ubuntu-latest, macos-13]
os: [ubuntu-latest, macos-14]
runs-on: ${{ matrix.os }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: lint
strategy:
matrix:
os: [ubuntu-latest, macos-13]
os: [ubuntu-latest, macos-14]
runs-on: ${{ matrix.os }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: test
strategy:
matrix:
os: [ubuntu-latest, macos-13]
os: [ubuntu-latest, macos-14]
runs-on: ${{ matrix.os }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://github.com/84codes/crystal-container-images
FROM 84codes/crystal:1.12.1-ubuntu-24.04 AS builder
FROM 84codes/crystal:1.13.2-ubuntu-24.04 AS builder

LABEL org.opencontainers.image.title="runway"
LABEL org.opencontainers.image.description="clearing code for take off"
Expand Down
2 changes: 1 addition & 1 deletion acceptance/logs/expected.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ INFO: 📖 loading runway configuration
DEBUG: attempting to load config from acceptance/config/config.yml
INFO: ✅ loaded configuration successfully
INFO: 🚚 2 projects loaded
INFO: 🛫 starting runway - version: v0.2.1
INFO: 🛫 starting runway - version: v0.2.3
INFO: 📦 starting project project-1
INFO: 🕐 scheduling event with interval 3s for project-1
INFO: 📦 starting project project-2
Expand Down
14 changes: 1 addition & 13 deletions script/acceptance
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#!/bin/bash

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

if [[ "$CI" == "true" ]]; then
source script/ci-env
fi
source script/setup-env $@

echo -e "${BLUE}🚗 starting acceptance test suite...${OFF}"

Expand Down
12 changes: 1 addition & 11 deletions script/all
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'

# runs all formatting scripts and tests at once

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
source script/setup-env $@

set -e

Expand Down
25 changes: 2 additions & 23 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,7 @@

set -e

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
YELLOW='\033[0;33m'

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
VENDOR_DIR="$DIR/vendor"
SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"

if [[ "$@" == *"--ci"* ]]; then
source script/ci-env
fi
source script/setup-env $@

crystal_path_var="$(crystal env CRYSTAL_PATH)"
# if the crystal_path_var does not contain 'vendor/shards/install' then we need to add it to the CRYSTAL_PATH
Expand Down Expand Up @@ -49,11 +33,6 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="mac"

if [[ "$CI" == "true" ]]; then
echo "setting custom macos CRYSTAL_OPTS for CI"
export CRYSTAL_OPTS="--link-flags=-Wl"
fi

# if CRYSTAL_OPTS is not set to `--link-flags=-Wl` then print a warning
if [[ -z "$CRYSTAL_OPTS" || "$CRYSTAL_OPTS" != "--link-flags=-Wl" ]]; then
compatability_warning="⚠️ ${YELLOW}Warning${OFF}: please consider exporting the following env vars in your terminal -> https://github.com/GrantBirki/dotfiles/blob/42526c0004cd7562883e5019db8e462e8f307e6a/dotfiles/.bashrc#L201"
Expand Down Expand Up @@ -104,7 +83,7 @@ if [[ "$@" == *"--ci"* ]]; then
fi

# install the shards
SHARDS_CACHE_PATH="$SHARDS_CACHE_PATH" SHARDS_INSTALL_PATH="$SHARDS_INSTALL_PATH" shards install --local --frozen $ci_flags $@
shards install --local --frozen $ci_flags $@

# shards install often wipes out our custom shards sha256 file so we need to recompute it if they are gone
script/compute-dep-shas
Expand Down
29 changes: 1 addition & 28 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,7 @@

set -e

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
VENDOR_DIR="$DIR/vendor"
SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"

if [[ "$CI" == "true" ]]; then
source script/ci-env
fi

if [[ "$OSTYPE" == "darwin"* && "$CI" == "true" ]]; then
echo "setting custom macos CRYSTAL_OPTS for CI"
export CRYSTAL_OPTS="--link-flags=-Wl"
fi

# if the --production flag is passed or the CRYSTAL_ENV environment variable is set to production,
# always ensure the CRYSTAL_PATH is set with vendored shards
if [[ "$@" == *"--production"* ]] || [[ "$CRYSTAL_ENV" == "production" ]]; then
echo "🔨 setting CRYSTAL_PATH to $VENDOR_DIR/shards/install:$(crystal env CRYSTAL_PATH)"
export CRYSTAL_PATH="vendor/shards/install:$(crystal env CRYSTAL_PATH)"
fi
source script/setup-env $@

echo -e "🔨 ${BLUE}building in ${PURPLE}release${BLUE} mode${OFF}"
SHARDS_CACHE_PATH="$SHARDS_CACHE_PATH" SHARDS_INSTALL_PATH="$SHARDS_INSTALL_PATH" shards build --production --release --progress --debug --error-trace -Dpreview_mt
Expand Down
5 changes: 0 additions & 5 deletions script/ci-env

This file was deleted.

15 changes: 3 additions & 12 deletions script/compute-dep-shas
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
#!/bin/bash

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
VENDOR_DIR="$DIR/vendor"
SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"
SHARDS_CACHED="$VENDOR_DIR/shards/cache"
source script/setup-env $@

SHARD_SHA_FILE=".shard.vendor.cache.sha256"

file="vendor/shards/install/.shards.info"

if [ -f "$VENDOR_DIR/shards/install/.shards.info" ]; then
if [ -f "$VENDOR_SHARDS_INFO_FILE" ]; then

# Use yq to parse the file and extract shard names and versions
shards=$(yq eval '.shards | to_entries | .[] | "\(.key)|\(.value.git)|\(.value.version)"' $file)
shards=$(yq eval '.shards | to_entries | .[] | "\(.key)|\(.value.git)|\(.value.version)"' $VENDOR_SHARDS_INFO_FILE)

# Loop over each shard
echo "$shards" | while IFS= read -r shard; do
Expand Down
14 changes: 1 addition & 13 deletions script/format
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@

set -e

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

if [[ "$CI" == "true" ]]; then
source script/ci-env
fi
source script/setup-env $@

echo -e "🧹 ${BLUE}formatting ${PURPLE}crystal${BLUE} files...${OFF}"

Expand Down
14 changes: 1 addition & 13 deletions script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@

set -e

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

if [[ "$CI" == "true" ]]; then
source script/ci-env
fi
source script/setup-env $@

echo -e "🖌️ ${BLUE}linting ${PURPLE}crystal${BLUE} files..."

Expand Down
13 changes: 1 addition & 12 deletions script/postinstall
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
#!/bin/bash

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
VENDOR_DIR="$DIR/vendor"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"

LINUX_VENDOR_DIR="$VENDOR_DIR/linux_x86_64/bin"
DARWIN_VENDOR_DIR_X64="$VENDOR_DIR/darwin_x86_64/bin"
DARWIN_VENDOR_DIR_ARM64="$VENDOR_DIR/darwin_arm64/bin"

if [[ "$CI" == "true" ]]; then
source script/ci-env
fi
source script/setup-env $@

mkdir -p "$DIR/bin"

Expand Down
3 changes: 1 addition & 2 deletions script/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

set -e

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
source script/setup-env $@

mkdir -p "$DIR/bin"
7 changes: 3 additions & 4 deletions script/server
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

set -e

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
source script/setup-env $@

# if the script was invoked with the --dev flag, run the development version
if [ "$1" == "--dev" ]; then
Expand All @@ -13,7 +12,7 @@ if [ "$1" == "--dev" ]; then
LOG_LEVEL="$3"
fi

SHARDS_CACHE_PATH="$DIR/.cache/shards" shards run --debug --error-trace -- -c config.yml --log-level $LOG_LEVEL
shards run --debug --error-trace -- -c config.yml --log-level $LOG_LEVEL
else
SHARDS_CACHE_PATH="$DIR/.cache/shards" shards run --release --debug --error-trace
shards run --release --debug --error-trace
fi
48 changes: 48 additions & 0 deletions script/setup-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -e

export OFF='\033[0m'
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export BLUE='\033[0;34m'
export PURPLE='\033[0;35m'

# set the working directory to the root of the project
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

# set common variables
export VENDOR_DIR="$DIR/vendor"
export SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
export SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"
export SHARDS_CACHED="$VENDOR_DIR/shards/cache"
export SHARD_SHA_FILE=".shard.vendor.cache.sha256"
export VENDOR_SHARDS_INFO_FILE="vendor/shards/install/.shards.info"

# common vendor dirs for binaries
export LINUX_VENDOR_DIR="$VENDOR_DIR/linux_x86_64/bin"
export DARWIN_VENDOR_DIR_X64="$VENDOR_DIR/darwin_x86_64/bin"
export DARWIN_VENDOR_DIR_ARM64="$VENDOR_DIR/darwin_arm64/bin"

# if --production was provided, always ensure CRYSTAL_ENV is set to production
if [[ "$@" == *"--production"* ]]; then
export CRYSTAL_ENV="production"
fi

if [[ "$@" == *"--production"* ]] || [[ "$CRYSTAL_ENV" == "production" ]] || [[ "$CI" == "true" ]]; then
crystal_path_var="$(crystal env CRYSTAL_PATH)"

# if the crystal_path_var does not contain 'vendor/shards/install' then we need to add it to the CRYSTAL_PATH
if [[ "$crystal_path_var" != *"vendor/shards/install"* ]]; then
echo "setting CRYSTAL_PATH to include vendored shards - reason: --production flag passed or CRYSTAL_ENV is set to production or CI is true"
export CRYSTAL_PATH="vendor/shards/install:$(crystal env CRYSTAL_PATH)"
fi
fi

if [[ "$OSTYPE" == "darwin"* && "$CI" == "true" ]]; then
# only set the CRYSTAL_OPTS if it is not set or if it does not contain "-Wl"
if [[ -z "$CRYSTAL_OPTS" || "$CRYSTAL_OPTS" != *"-Wl"* ]]; then
echo "setting custom macos CRYSTAL_OPTS for CI"
export CRYSTAL_OPTS="--link-flags=-Wl"
fi
fi
14 changes: 1 addition & 13 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

set -e

# COLORS
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

echo -e "🧪 ${BLUE}running unit tests...${OFF}"

if [[ "$CI" == "true" ]]; then
source script/ci-env
fi
source script/setup-env $@

os="unknown"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
Expand Down
16 changes: 3 additions & 13 deletions script/unzipper
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#!/bin/bash

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
VENDOR_DIR="$DIR/vendor"
SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"
SHARDS_CACHED="$VENDOR_DIR/shards/cache"

SHARD_SHA_FILE=".shard.vendor.cache.sha256"
source script/setup-env $@

TRASHDIR=$(mktemp -d /tmp/bootstrap.XXXXXXXXXXXXXXXXX)
cleanup() {
Expand All @@ -19,7 +12,7 @@ mkdir -p "$SHARDS_INSTALL_PATH"
mkdir -p "$SHARDS_CACHE_PATH/github.com"

# check if the .shards.info file exists, if it doesn't this is a fresh bootstrapping
if [ ! -f "$VENDOR_DIR/shards/install/.shards.info" ]; then
if [ ! -f "$VENDOR_SHARDS_INFO_FILE" ]; then
# if no .shards.info file found, this must be a fresh bootstrapping

# iterate over all the cached shards in the vendor/shards/cache directory
Expand Down Expand Up @@ -50,11 +43,8 @@ if [ ! -f "$VENDOR_DIR/shards/install/.shards.info" ]; then

else
# if found .shards.info file, this must be a bootstrap re-run - we will check if the shards have changed by comparing the sha256 of the cached shard and the sha256 of the current shard

file="vendor/shards/install/.shards.info"

# Use yq to parse the file and extract shard names and versions
shards=$(yq eval '.shards | to_entries | .[] | "\(.key)|\(.value.git)|\(.value.version)"' $file)
shards=$(yq eval '.shards | to_entries | .[] | "\(.key)|\(.value.git)|\(.value.version)"' $VENDOR_SHARDS_INFO_FILE)

# Loop over each shard
echo "$shards" | while IFS= read -r shard; do
Expand Down
Loading
Loading