Skip to content

Build & Test

Build & Test #338

name: build-and-test
run-name: Build & Test
on:
workflow_dispatch:
inputs:
ubuntu:
description: 'Build & Test on Ubuntu latest ?'
default: true
required: true
type: boolean
macos:
description: 'Build & Test on macOS latest ?'
default: false
required: true
type: boolean
push:
branches:
- 'master'
paths:
- 'bin/**'
- 'dotfiles/**'
- 'tests/**'
- '**/*.bash'
fork:
branches:
- '**'
pull_request:
branches:
- '**'
paths:
- 'bin/**'
- 'dotfiles/**'
- 'tests/**'
- '**/*.bash'
permissions:
contents: write
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:
needs: set-os-matrix
strategy:
matrix:
os: ${{ fromJson(needs.set-os-matrix.outputs.matrix-os) }}
runs-on: ${{ matrix.os }}
env:
PREFIX: "${{ github.workspace }}"
HHS_LOG_DIR: "${{ matrix.os == 'macos-latest' && '/Users/runner/.config/hhs/log' || '/home/runner/.config/hhs/log' }}"
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Update PIP
run: pip install --upgrade pip
- name: Install HomeSetup with Prefix
run: |
if ./install.bash -r -p "${PREFIX}"; then
echo "${PREFIX}" > "${HOME}/.hhs-prefix"
echo ''
echo -e "${YELLOW}Installation information:"
echo -e " SHELL: ${SHELL}"
echo -e "PREFIX: ${PREFIX}"
echo -e " HOME: ${HOME}"
echo -e " USER: ${USER}"
echo -e " LOGS: ${HHS_LOG_DIR}"
echo ''
echo -en "${BLUE}Loading bash profile... "
if source "${HOME}/.bashrc"; then
echo -e "${GREEN}OK${NC}"
__hhs tests && exit 0
else
echo -e "${GREEN}FAILED${NC}"
fi
else
echo "HHS_LOG_DIR=$(echo ${HOME}/install.log)" >> $GITHUB_ENV
fi
exit 1
- name: Upload installation logs (success)
if: ${{ success() }}
uses: actions/upload-artifact@v3
with:
name: "success-install-logs"
path: "${{ env.HHS_LOG_DIR }}"
- name: Upload installation logs (failure)
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: "failure-install-logs"
path: "${{ env.HHS_LOG_DIR }}"