Skip to content

Commit

Permalink
Improve GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Aug 22, 2024
1 parent b6ed500 commit ed3f6ef
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
50 changes: 40 additions & 10 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ on:
type: boolean
push:
branches:
- '**'
- 'master'
paths:
- 'bin/**'
- 'dotfiles/**'
- 'tests/**'
- '*.bash'
- '**/*.bash'
fork:
branches:
- '**'
Expand All @@ -32,7 +32,7 @@ on:
- 'bin/**'
- 'dotfiles/**'
- 'tests/**'
- '*.bash'
- '**/*.bash'

permissions:
contents: write
Expand All @@ -41,11 +41,40 @@ env:
JOB_NAME: "HomeSetup-Build"

jobs:
set-os-matrix:
runs-on: "ubuntu-latest"
outputs:
matrix-os: ${{ steps.set-matrix-items.outputs.matrix-os }}
steps:
- name: Show Selected Input
run: |
echo "Build on Ubuntu-Latest: ${{ inputs.ubuntu || false }}"
echo "Build on MacOS-Latest: ${{ inputs.macos || false }}"
- name: Set Inclusion Matrix
id: set-matrix-items
run: |
JSON=""
if [[ "${{ inputs.ubuntu }}" == "true" ]]; then
JSON="\"ubuntu-latest\""
fi
if [[ "${{ inputs.macos }}" == "true" ]]; then
[[ -n "$JSON" ]] && JSON="${JSON}, "
JSON="${JSON} \"macos-latest\""
fi
[[ -z "${JSON}" ]] && JSON="\"ubuntu-latest\""
JSON="[${JSON}]"
echo "JSON: ${JSON}"
echo "matrix-os=$( echo "${JSON}" )" >> $GITHUB_OUTPUT
build:
runs-on: 'ubuntu-latest'
needs: set-os-matrix
strategy:
matrix:
os: ${{ fromJson(needs.set-os-matrix.outputs.matrix-os) }}
runs-on: ${{ matrix.os }}
env:
HHS_LOG_DIR: '/Users/runner/.hhs/log'
HHS_PREFIX: "${{ github.workspace }}"
HHS_LOG_DIR: "${HOME}/.hhs/log"
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -58,12 +87,13 @@ jobs:
run: pip install --upgrade pip
- name: Install HomeSetup with Prefix
run: |
if ./install.bash -r -p "${{ github.workspace }}"; then
echo "${{ github.workspace }}" > "${HOME}/.hhs-prefix"
if ./install.bash -r -p "${HHS_PREFIX}"; then
echo "${HHS_PREFIX}" > "${HOME}/.hhs-prefix"
echo -e "\nInstallation information:"
echo -e "SHELL: ${SHELL}"
echo -e " HOME: ${HOME}"
echo -e " USER: ${USER}\n"
echo -e " SHELL: ${SHELL}"
echo -e "PREFIX: ${HHS_PREFIX}"
echo -e " HOME: ${HOME}"
echo -e " USER: ${USER}\n"
echo -en "Loading bash profile..."
if source "${HOME}"/.bashrc; then echo "OK"; else echo "FAILED"; fi
echo "HHS_LOG_DIR=$(echo ${HHS_LOG_DIR})" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion dotfiles/aliasdef
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if __hhs_has 'ifconfig'; then
__hhs_alias my-ip='__hhs_ip external'
__hhs_alias vpn-ip='__hhs_ip vpn'
__hhs_alias ip-info='__hhs_ip_info'
__hhs_alias ipi="__hhs_ip_info $(my-ip | awk '{print $3}') || echo \"${YELLOW}Not connected to the internet${NC}\""
__hhs_alias ipi="__hhs_ip_info $(__hhs_ip external | awk '{print $3}') || echo \"${YELLOW}Not connected to the internet${NC}\""
__hhs_alias ip-lookup='__hhs_ip_lookup'
__hhs_alias ip-resolve='__hhs_ip_resolve'
fi
Expand Down
44 changes: 26 additions & 18 deletions install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ Usage: $APP_NAME [OPTIONS] <args>
HOME="${HOME:-$(eval echo ~"${USER}")}"
fi

[[ -z "${USER}" || -z "${HOME}" ]] && quit 1 "Unable to determine USER/HOME -> ${USER}/${HOME}"

# Installation log file
INSTALL_LOG="${HOME}/install.log"
touch "${INSTALL_LOG}"
[[ -f "${INSTALL_LOG}" ]] || quit 1 "Unable initialize installation logs -> ${INSTALL_LOG}"
[[ -f "${INSTALL_LOG}" ]] && echo "Logs can be accessed here: ${BLUE}${INSTALL_LOG}${NC}"

# Functions to be unset after quit
UNSETS=(
quit usage has check_current_shell check_inst_method install_dotfiles clone_repository check_required_tools
Expand All @@ -44,6 +52,21 @@ Usage: $APP_NAME [OPTIONS] <args>
install_tools query_askai_install create_destination_dirs
)


# Awesome icons
STAR_ICN='\xef\x80\x85'
HAND_PEACE_ICN='\xef\x89\x9b'
POINTER_ICN='\xef\x90\xb2'

# VT-100 Terminal colors
ORANGE='\033[38;5;202m'
WHITE='\033[97m'
BLUE='\033[34m'
GREEN='\033[32m'
YELLOW='\033[93m'
RED='\033[31m'
NC='\033[m'

# HomeSetup GitHub repository URL
HHS_REPO_URL='https://github.com/yorevs/homesetup.git'

Expand Down Expand Up @@ -121,20 +144,6 @@ Usage: $APP_NAME [OPTIONS] <args>
GROUP=${GROUP:-${USER}}
fi

# Awesome icons
STAR_ICN='\xef\x80\x85'
HAND_PEACE_ICN='\xef\x89\x9b'
POINTER_ICN='\xef\x90\xb2'

# VT-100 Terminal colors
ORANGE='\033[38;5;202m'
WHITE='\033[97m'
BLUE='\033[34m'
GREEN='\033[32m'
YELLOW='\033[93m'
RED='\033[31m'
NC='\033[m'

# Purpose: Quit the program and exhibits an exit message if specified
# @param $1 [Req] : The exit return code. 0 = SUCCESS, 1 = FAILURE, * = ERROR ${RED}.
# @param $2 [Opt] : The exit message to be displayed.
Expand Down Expand Up @@ -194,7 +203,7 @@ Usage: $APP_NAME [OPTIONS] <args>
else
echo -en "${WHITE}Copying: ${BLUE} ${src_file} -> ${dest_file}... "
\rsync --archive "${src_file}" "${dest_file}"
\chown "${USER}":"${GROUP}" "${dest_file}"
\chown "${USER}":"${GROUP}" "${dest_file}" &>/dev/null
[[ -f "${dest_file}" ]] && echo -e "${GREEN}OK${NC}"
[[ -f "${dest_file}" ]] || echo -e "${RED}FAILED${NC}"
fi
Expand Down Expand Up @@ -308,9 +317,6 @@ Usage: $APP_NAME [OPTIONS] <args>
# Key-Bindings source location
BINDINGS_DIR="${HHS_HOME}/bin/key-bindings"

# Installation log file
INSTALL_LOG="${HOME}/install.log"

# Check if the user passed help or version options
[[ "$1" == '-h' || "$1" == '--help' ]] && quit 0 "${USAGE}"
[[ "$1" == '-v' || "$1" == '--version' ]] && quit 0 "HomeSetup v$(\grep . "${HHS_VERSION_FILE}")"
Expand Down Expand Up @@ -957,7 +963,9 @@ Usage: $APP_NAME [OPTIONS] <args>

# Check HomeSetup installation prefix
check_prefix() {
# Create the prefix file to be used
[[ -n "${HHS_PREFIX}" ]] && echo "${HHS_PREFIX}" >"${HHS_PREFIX_FILE}"
# Delete the useless prefix file
[[ -z "${HHS_PREFIX}" && -f "${HHS_PREFIX_FILE}" ]] && \rm -f "${HHS_PREFIX_FILE}"
}

Expand Down

0 comments on commit ed3f6ef

Please sign in to comment.