nikoksr/notify

Expanding testing suite

gedw99 opened this issue · 1 comments

gedw99 commented

These are the bones of a testing system that runs locally and in CI. It needs work as there are side issues too.

It's all based on reusing the make files for local and CI testing.

all-ci tests everything, making sure all deps are installed.

Your basically making github bend to your will, by directly installing and running golang code at runtime bypassing docker, etc
This allows you to run your testing infrastructure anywhere.

bin-install will install he golang thing your testing.
caddy gives you the https you need often locally. YOu need ot run a server somewhere with it and use NATS to drive it, where you infect the binary and caddy servers it and Git hub actions call it.
This is all because github wont give you a Server locally, so you just run on one fly with caddy and then your binary behind caddy.

github runs on linux, mac and window. So testing there is easy.

github can not run mobile OS's:Mobiles need to be local connected to a laptop over USB, and github actions then drives them over NATS. You tell the mobile to install the app and test it.
Its exactly the same as what we are doing on fly.
saucelabs can also be used: https://github.com/saucelabs/saucectl

For external services outside your control you can run go tests to capture their output.

root makefile of repo:



GIT_UPSTREAM_REPO_URL=https://github.com/foo/bar

.DEFAULT_GOAL := help

GIT_BRANCH_DEFAULT=main
GIT_VERSION_GITHASH=$(shell git rev-parse $(GIT_BRANCH_DEFAULT) | tr -d '\n')

## INCLUDES

MAKE_ASSETS_FSPATH=./assets/.sc-make/make
include $(MAKE_ASSETS_FSPATH)/help.mk
include $(MAKE_ASSETS_FSPATH)/caddy.mk
include ./bin.mk

## TOP level for local and CI ( always names with all-* )
all: all-test
all-build: dep bin-install
all-test: all-build test-all
all-ci: bin-build test-all bin-release-mock
all-release: all-build test-all bin-release



print:
	
	@echo ""
	@echo "GIT_UPSTREAM_REPO_URL:     $(GIT_UPSTREAM_REPO_URL)"
	@echo "GIT_BRANCH_DEFAULT:        $(GIT_BRANCH_DEFAULT)"
	@echo "GIT_VERSION_GITHASH:       $(GIT_VERSION_GITHASH)"
	@echo "GO_LDFLAGS:                $(GO_LDFLAGS)"
	
	@echo ""
	@echo --- SC-MAKE ---
	$(MAKE) bin-print
	
dep:
	# get everything needed to build.



### MOD 

mod-tidy:
	go mod tidy

mod-upgrade:
	$(MAKE) mod-tidy
	go install github.com/oligot/go-mod-upgrade@latest
	go-mod-upgrade
	$(MAKE) mod-tidy


### TEST

TEST_CMD_TEMPLATE=cd ./test-cmd-harness && $(MAKE)
TEST_MAKE_TEMPLATE=cd ./test-make-harness && $(MAKE)

test-all:
	$(TEST_CMD_TEMPLATE) test-print
	$(TEST_CMD_TEMPLATE) test-all

	$(TEST_MAKE_TEMPLATE) test-print
	$(TEST_MAKE_TEMPLATE) test-all

	
### RELEASE

release-all:

caddy.mk

# CADDY
# github.com/caddyserver/caddy

# XCADDY
# https://github.com/caddyserver/xcaddy

# MKCERT
# https://github.com/FiloSottile/mkcert

CADDY_BIN_NAME=caddy
# https://github.com/caddyserver/caddy/releases/tag/v2.6.4
CADDY_BIN_VERSION=v2.6.4

CADDY_XCADDY_BIN_NAME=xcaddy
# https://github.com/caddyserver/xcaddy/releases/tag/v0.3.2
CADDY_XCADDY_BIN_VERSION=v0.3.2

CADDY_MKCERT_BIN_NAME=mkcert
# https://github.com/FiloSottile/mkcert/releases/tag/v1.4.4
CADDY_MKCERT_BIN_VERSION=v1.4.4


# Override variables
# where to put the standard templates
CADDY_SRC_TEMPLATES_FSPATH=$(PWD)/.templates/caddy
# where to look for CaddyFile to use at runtime 
CADDY_SRC_FSPATH=$(PWD)/


# Computed variables
# PERFECT :) https://www.systutorials.com/how-to-get-a-makefiles-directory-for-including-other-makefiles/
_CADDY_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
_CADDY_TEMPLATES_SOURCE=$(_CADDY_SELF_DIR)/templates/caddy
_CADDY_TEMPLATES_TARGET=$(CADDY_SRC_TEMPLATES_FSPATH)



## caddy print, outputs all variables needed to run caddy
caddy-print:
	@echo ""
	@echo "--- CADDY ---"

	@echo "Deps:"
	@echo "CADDY_BIN_NAME:              $(CADDY_BIN_NAME) installed at : $(shell which $(CADDY_BIN_NAME))"
	@echo "CADDY_BIN_VERSION:           $(CADDY_BIN_VERSION) installed as: $(shell $(CADDY_BIN_NAME) version)"

	@echo "CADDY_XCADDY_BIN_NAME:       $(CADDY_XCADDY_BIN_NAME) installed at : $(shell which $(CADDY_XCADDY_BIN_NAME))"
	@echo "CADDY_XCADDY_BIN_VERSION:    $(CADDY_XCADDY_BIN_VERSION) installed as: $(shell $(CADDY_XCADDY_BIN_NAME) version)"
	
	@echo "CADDY_MKCERT_BIN_NAME:       $(CADDY_MKCERT_BIN_NAME) installed at : $(shell which $(CADDY_MKCERT_BIN_NAME))"
	@echo "CADDY_MKCERT_BIN_VERSION:    $(CADDY_MKCERT_BIN_VERSION) installed as: $(shell $(CADDY_MKCERT_BIN_NAME) version)"

	@echo ""
	@echo "Override variables:"
	@echo "CADDY_SRC_FSPATH:            $(CADDY_SRC_FSPATH)"
	
	@echo ""
	@echo "Computed variables:"
	@echo "_CADDY_SELF_DIR:             $(_CADDY_SELF_DIR)"
	@echo "_CADDY_TEMPLATES_SOURCE:     $(_CADDY_TEMPLATES_SOURCE)"
	@echo "_CADDY_TEMPLATES_TARGET:     $(_CADDY_TEMPLATES_TARGET)"
	@echo ""

## prints the templates 
caddy-templates-print:
	@echo
	@echo listing templates ...
	cd $(_CADDY_TEMPLATES_SOURCE) && $(ENV_TREE_BIN) -a -C

## caddy dep installs the caddy and mkcert binary to the go bin
## cand copies the templates up into your templates working directory
# Useful where you want to grab them and customise.

## installs caddy
caddy-dep:
	@echo
	@echo installing caddy tool
	go install -ldflags="-X main.version=$(CADDY_BIN_VERSION)" github.com/caddyserver/caddy/v2/cmd/caddy@$(CADDY_BIN_VERSION)
	@echo installed $(CADDY_BIN_VERSION)   at : $(shell which $(CADDY_BIN_NAME))

	@echo
	@echo installing xcaddy tool
	go install -ldflags="-X main.version=$(CADDY_XCADDY_BIN_VERSION)" github.com/caddyserver/xcaddy/cmd/xcaddy@$(CADDY_XCADDY_BIN_VERSION)
	@echo installed $(CADDY_XCADDY_BIN_VERSION)   at : $(shell which $(CADDY_XCADDY_BIN_NAME))

	@echo
	@echo installing mkcert tool
	go install -ldflags="-X main.version=$(CADDY_MKCERT_BIN_VERSION)" filippo.io/mkcert@$(CADDY_MKCERT_BIN_VERSION)
	@echo installed mkcert [ $(CADDY_MKCERT_BIN_VERSION) ] at : $(shell which $(CADDY_MKCERT_BIN_NAME))

	$(MAKE) caddy-mkcert-run

	$(MAKE) caddy-templates-dep

## installs the caddy templates into your project
caddy-templates-dep:
	@echo
	@echo installing caddy templates to your project....
	mkdir -p $(_CADDY_TEMPLATES_TARGET)
	cp -r $(_CADDY_TEMPLATES_SOURCE)/* $(_CADDY_TEMPLATES_TARGET)/
	@echo installed caddy templates  at : $(_CADDY_TEMPLATES_TARGET)


## caddy mkcert installs the certs for browsers to run localhost
caddy-mkcert-run:
	@echo
	@echo installing mkcert certs
	cd $(CADDY_SRC_FSPATH) && $(CADDY_MKCERT_BIN_NAME) -install
	cd $(CADDY_SRC_FSPATH) && $(CADDY_MKCERT_BIN_NAME) localhost
	@echo installed mkcert certs at : $(CADDY_SRC_FSPATH)

## caddy run runs caddy using your Caddyfile
caddy-run:
	# cd $(CADDY_SRC_FSPATH) && $(CADDY_BIN_NAME) fmt -overwrite
	open https://localhost:8443
	#cd $(CADDY_SRC_FSPATH) && $(CADDY_BIN_NAME) run -watch
	cd $(CADDY_SRC_FSPATH) && $(CADDY_BIN_NAME) run


github action:

name: CI

on:
  pull_request:
    branches:
      - '*'

jobs:
  all:
    name: CI

    strategy:
      fail-fast: false # saves ci time, won't be worth it if it even runs other platform
      matrix:
        os: [ ubuntu-20.04, macos-latest, windows-latest ]
        go-version: [1.20.x]
        target: [ 'all-ci' ]

    runs-on: ${{ matrix.os }}

    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          stable: 'false'
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Setup Go binary path
        shell: bash
        run: |
          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH

      - name: Git line endings
        shell: bash
        run: |
          git config --global core.autocrlf false
          git config --global core.eol lf

      - name: Check out THIS code into the Go module directory
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}

      - name: make ${{ matrix.target }}
        shell: bash
        run: |
          make $target
        working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
        env:
          target: ${{ matrix.target }}
        timeout-minutes: 20
gedw99 commented

@nikoksr

See if you like it :)