Skip to content

Commit

Permalink
make: statoshi statoshi-depends - act config
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyMcMillan committed Jul 7, 2023
1 parent 54c3ffd commit 8d599e1
Show file tree
Hide file tree
Showing 9 changed files with 679 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!depends/sources/*
34 changes: 34 additions & 0 deletions .github/workflows/statoshi-depends.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: statoshi/build

on:
push:
branches: [ "master", "*" ]
pull_request:
branches: [ "master", "*" ]

jobs:
depends:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
submodules: 'true'
set-safe-directory: 'true'
- name: apt-get update/install
run: |
./autogen.sh
sudo apt-get update
sudo apt-get install -y nano wget
sudo apt-get install -y autoconf autotools-dev build-essential bsdmainutils git libboost-all-dev libssl-dev libtool pkg-config automake
- name: ./autogen.sh
run: |
make download -C depends
- name: ./configure
run: |
./autogen.sh
./configure
- name: make
run: |
make
35 changes: 35 additions & 0 deletions .github/workflows/statoshi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: statoshi

on:
push:
branches: [ "master", "*" ]
pull_request:
branches: [ "master", "*" ]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
submodules: 'true'
set-safe-directory: 'true'
- name: apt-get update/install
run: |
./autogen.sh
sudo apt-get update
sudo apt-get install -y nano wget
sudo apt-get install -y autoconf autotools-dev build-essential bsdmainutils git libboost-all-dev libssl-dev libtool pkg-config automake
- name: ./autogen.sh
run: |
./autogen.sh
#make -C depends
- name: ./configure
run: |
./autogen.sh
./configure
- name: make
run: |
make
283 changes: 283 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
SHELL := /bin/bash
PWD ?= pwd_unknown
TIME := $(shell date +%s)
export TIME

OS :=$(shell uname -s)
export OS
OS_VERSION :=$(shell uname -r)
export OS_VERSION
ARCH :=$(shell uname -m)
export ARCH
ifeq ($(ARCH),x86_64)
TRIPLET :=x86_64-linux-gnu
export TRIPLET
endif
ifeq ($(ARCH),arm64)
TRIPLET :=aarch64-linux-gnu
export TRIPLET
endif
ifeq ($(ARCH),arm64)
TRIPLET :=aarch64-linux-gnu
export TRIPLET
endif

HOMEBREW := $(shell type -P brew)
export HOMEBREW

PYTHON := $(shell which python || echo)
export PYTHON
#PYTHON2 := $(shell which python2 || echo)
#export PYTHON2
PYTHON3 := $(shell which python3 || echo)
ifeq ($(PYTHON3),)
PYTHON3 :=$(shell which python || echo)
endif
export PYTHON3

PIP := $(notdir $(shell which pip || echo))
export PIP
PIP2 := $(notdir $(shell which pip2 || echo))
export PIP2
PIP3 := $(notdir $(shell which pip3 || echo))
export PIP3

ifeq ($(PYTHON3),/usr/local/bin/python3)
PIP := pip
PIP3 := pip
export PIP
export PIP3
endif

#detect python
PYTHON_ENV = $(shell python -c "import sys; sys.stdout.write('1') if hasattr(sys, 'base_prefix') else sys.stdout.write('0')" 2>/dev/null)
#detect python3
PYTHON3_ENV = $(shell python3 -c "import sys; sys.stdout.write('1') if hasattr(sys, 'base_prefix') else sys.stdout.write('0')")
export PYTHON_ENV
export PYTHON3_ENV

ifeq ($(PYTHON_ENV),1)
#likely in virtualenv
PYTHON_VENV := $(shell python -c "import sys; sys.stdout.write('1') if sys.prefix != sys.base_prefix else sys.stdout.write('0')" 2>/dev/null)
endif
export PYTHON_VENV

ifeq ($(PYTHON_VENV),1)
PYTHON3_VENV := $(shell python3 -c "import sys; sys.stdout.write('1') if sys.prefix != sys.base_prefix else sys.stdout.write('0')")
else
PYTHON_VENV :=$(PYTHON_ENV)
PYTHON3_VENV :=$(PYTHON3_ENV)
endif
export PYTHON3_VENV

ifeq ($(PYTHON_VENV),0)
USER_FLAG :=--user
else
USER_FLAG :=
endif

ifeq ($(project),)
PROJECT_NAME := $(notdir $(PWD))
else
PROJECT_NAME := $(project)
endif
export PROJECT_NAME

GIT_USER_NAME := $(shell git config user.name || echo $(PROJECT_NAME))
export GIT_USER_NAME
GH_USER_NAME := $(shell git config user.name || echo $(PROJECT_NAME))
ifneq ($(ghuser),)
GH_USER_NAME := $(ghuser)
endif
export GIT_USER_NAME

GIT_USER_EMAIL := $(shell git config user.email || echo $(PROJECT_NAME))
export GIT_USER_EMAIL
GIT_SERVER := https://github.com
export GIT_SERVER
GIT_SSH_SERVER := git@github.com
export GIT_SSH_SERVER
GIT_PROFILE := $(shell git config user.name || echo $(PROJECT_NAME))
export GIT_PROFILE
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo $(PROJECT_NAME))
export GIT_BRANCH
GIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo $(PROJECT_NAME))
export GIT_HASH
GIT_PREVIOUS_HASH := $(shell git rev-parse --short master@{1} 2>/dev/null || echo $(PROJECT_NAME))
export GIT_PREVIOUS_HASH
GIT_REPO_ORIGIN := $(shell git remote get-url origin 2>/dev/null || echo $(PROJECT_NAME))
export GIT_REPO_ORIGIN
GIT_REPO_NAME := $(PROJECT_NAME)
export GIT_REPO_NAME
GIT_REPO_PATH := $(HOME)/$(GIT_REPO_NAME)
export GIT_REPO_PATH

NODE_VERSION :=v14.21.3
export NODE_VERSION
NODE_ALIAS :=v14.21.0
export NODE_ALIAS
NVM_DIR :=$(HOME)/.nvm
export NVM_DIR
PACKAGE_MANAGER :=yarn
export PACKAGE_MANAGER
PACKAGE_INSTALL :=add
export PACKAGE_INSTALL

-:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
## help

.PHONY: init
.ONESHELL:
init:initialize venv## initialize venv
## init
@echo $(PYTHON)
@echo $(PYTHON2)
@echo $(PYTHON3)
@echo $(PIP)
@echo $(PIP2)
@echo $(PIP3)
@echo PATH=$(PATH):/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/bin
@echo PATH=$(PATH):$(HOME)/Library/Python/3.10/bin
test -d .venv || $(PYTHON3) -m virtualenv .venv
( \
source .venv/bin/activate; pip install -q -r requirements.txt; \
$(PYTHON3) -m pip install $(USER_FLAG) --upgrade pip; \
$(PYTHON3) -m pip install $(USER_FLAG) -r requirements.txt; \
$(PYTHON3) -m pip install -q omegaconf \
pip install -q --upgrade pip; \
);
( \
while ! docker system info > /dev/null 2>&1; do\
echo 'Waiting for docker to start...';\
if [[ '$(OS)' == 'Linux' ]]; then\
type -P systemctl && systemctl restart docker.service || type -P apk && apk add openrc docker && rc-service docker restart;\
fi;\
if [[ '$(OS)' == 'Darwin' ]]; then\
open --background -a /./Applications/Docker.app/Contents/MacOS/Docker;\
fi;\
sleep 1;\
done\
)
@bash -c ". .venv/bin/activate &"

help:## verbose help
@sed -n 's/^## //p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'


.PHONY: report
report:## report
## report
@echo ''
@echo '[ENV VARIABLES] '
@echo ''
@echo 'TIME=${TIME}'
@echo 'BASENAME=${BASENAME}'
@echo 'PROJECT_NAME=${PROJECT_NAME}'
@echo ''
@echo 'PYTHON_ENV=${PYTHON_ENV}'
@echo 'PYTHON3_ENV=${PYTHON3_ENV}'
@echo ''
@echo 'PYTHON_VENV=${PYTHON_VENV}'
@echo 'PYTHON3_VENV=${PYTHON3_VENV}'
@echo ''
@echo 'PYTHON=${PYTHON}'
@echo 'PIP=${PIP}'
@echo 'PYTHON2=${PYTHON2}'
@echo 'PIP2=${PIP2}'
@echo 'PYTHON3=${PYTHON3}'
@echo 'PIP3=${PIP3}'
@echo ''



@echo 'HOMEBREW=${HOMEBREW}'
@echo ''
@echo 'GIT_USER_NAME=${GIT_USER_NAME}'
@echo 'GH_USER_REPO=${GH_USER_REPO}'
@echo 'GH_USER_SPECIAL_REPO=${GH_USER_SPECIAL_REPO}'
@echo 'GIT_USER_EMAIL=${GIT_USER_EMAIL}'
@echo 'GIT_SERVER=${GIT_SERVER}'
@echo 'GIT_PROFILE=${GIT_PROFILE}'
@echo 'GIT_BRANCH=${GIT_BRANCH}'
@echo 'GIT_HASH=${GIT_HASH}'
@echo 'GIT_PREVIOUS_HASH=${GIT_PREVIOUS_HASH}'
@echo 'GIT_REPO_ORIGIN=${GIT_REPO_ORIGIN}'
@echo 'GIT_REPO_NAME=${GIT_REPO_NAME}'
@echo 'GIT_REPO_PATH=${GIT_REPO_PATH}'

.PHONY: super
.ONESHELL:
super:
ifneq ($(shell id -u),0)
@echo switch to superuser
@echo cd $(TARGET_DIR)
sudo -s
endif

checkbrew:##
## checkbrew
ifeq ($(HOMEBREW),)
@/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && $(MAKE) success || $(MAKE) failure
else
@type -P brew && $(MAKE) success || $(MAKE) failure
endif

submodules:## submodules
## submodules
git submodule update --init --recursive
git submodule foreach --recursive "git submodule update --init; git fetch --all --tags"

.ONESHELL:
docker-start:
## docker-start
@touch requirements.txt && $(PYTHON3) -m pip install -q -r requirements.txt
@test -d .venv || $(PYTHON3) -m virtualenv .venv
@( \
source .venv/bin/activate; $(PYTHON3) -m pip install -q -r requirements.txt; \
$(PYTHON3) -m pip install -q --upgrade pip; \
);
( \
while ! docker system info > /dev/null 2>&1; do\
echo 'Waiting for docker to start...';\
if [[ '$(OS)' == 'Linux' ]]; then\
type -P apt && apt install docker*;\
type -P systemctl && systemctl restart docker.service || type -P service && service docker.service restart || type -P apk && apk add openrc docker && rc-service docker restart || echo "try installing docker manually...";\
fi;\
if [[ '$(OS)' == 'Darwin' ]]; then\
open --background -a /./Applications/Docker.app/Contents/MacOS/Docker;\
fi;\
sleep 1;\
done\
)

initialize:## initialize
## initialize
@[[ '$(shell uname -m)' == 'x86_64' ]] && [[ '$(shell uname -s)' == 'Darwin' ]] && echo "is_Darwin/x86_64" || echo "not_Darwin/x86_64"
@[[ '$(shell uname -m)' == 'x86_64' ]] && [[ '$(shell uname -s)' == 'Linux' ]] && echo "is_Linux/x86_64" || echo "not_Linux/x86_64"

failure:
@-/usr/bin/false && ([ $$? -eq 0 ] && echo "success!") || echo "failure!"
success:
@-/usr/bin/true && ([ $$? -eq 0 ] && echo "success!") || echo "failure!"

venv:submodules## python3.10 virtualenv
$(MAKE) -f $(PWD)/venv.mk venv-3-10
venv-test:submodules## venv-3-10-test
$(MAKE) -f $(PWD)/venv.mk venv-3-10-test

tag:## tag
@git tag $(OS)-$(OS_VERSION)-$(ARCH)-$(shell date +%s)
@git push -f --tags || echo "unable to push tags..."

clean:## clean
@git clean -xfd && git submodule foreach --recursive git clean -xfd && git reset --hard && git submodule foreach --recursive git reset --hard && git submodule update --init --recursive
@if [[ -d $(PWD)/stm32/built ]]; then \
rm -rf $(PWD)/stm32/built/**.bin; fi;

-include Makefile
-include venv.mk
-include act.mk

# vim: set noexpandtab:
# vim: set setfiletype make
13 changes: 13 additions & 0 deletions act.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
statoshi:docker-start## statoshi
## statoshi act sequence
## additional help example
@touch ~/GH_TOKEN.txt
@export $(cat ~/GH_TOKEN.txt) && act -C $(PWD) -vb -W $(PWD)/.github/workflows/$@.yml
statoshi-depends:docker-start## statoshi/depends
## statoshi act sequence
## additional help example
@touch ~/GH_TOKEN.txt
@export $(cat ~/GH_TOKEN.txt) && act -C $(PWD) -vb -W $(PWD)/.github/workflows/$@.yml

# vim: set noexpandtab:
# vim: set setfiletype make
Loading

0 comments on commit 8d599e1

Please sign in to comment.