Skip to content

Commit

Permalink
Self hosted Go APP
Browse files Browse the repository at this point in the history
Frontend for landing page with embed
Tests using mysql as driver
  • Loading branch information
kevincobain2000 committed Jan 20, 2024
1 parent 3e5b3ac commit a2e8daf
Show file tree
Hide file tree
Showing 79 changed files with 11,861 additions and 10 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
push:
paths:
- '**/*.go'
- '**/*.mod'
- '**/*.sum'
- '**/*.yml'
name: CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build:
strategy:
matrix:
go-version: [mod]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: kevincobain2000/action-gobrew@v2
with:
version: ${{ matrix.go-version }}
- name: Setup Node.js ${{ matrix.node-versions }}
uses: actions/setup-node@v2
with:
node-version: 20

- name: Build Dist for Embed
working-directory: app/frontend
run: |
npm install
npm run build
- name: Build
working-directory: app
run: go build main.go

- name: Install Tools
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
- name: Lint
working-directory: app
run: |
gosec ./...
go vet -all .
130 changes: 130 additions & 0 deletions .github/workflows/coveritup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
on:
pull_request:
paths:
- '**/*.go'
- '**/*.mod'
- '**/*.sum'
- '**/*.yml'
push:
paths:
- '**/*.go'
- '**/*.mod'
- '**/*.sum'
- '**/*.yml'

name: "Cover It Up"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
coveritup:
strategy:
matrix:
go-version: [mod]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: kevincobain2000/action-gobrew@v2
with:
version: ${{ matrix.go-version }}
- name: Setup Node.js ${{ matrix.node-versions }}
uses: actions/setup-node@v2
with:
node-version: 20

- name: Install Tools
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install github.com/axw/gocov/gocov@latest
go install github.com/AlekSi/gocov-xml@latest
- name: Setup Node.js ${{ matrix.node-versions }}
uses: actions/setup-node@v2
with:
node-version: 20
- uses: mirromutth/[email protected]
with:
mysql version: '8.0'
mysql database: 'coverituptest'
- name: test
run: |
go test ./... -count=1
# - name: NPM Install
# working-directory: app/frontend
# run: |
# START=$SECONDS
# npm install
# echo SCORE=$(($SECONDS-START)) >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: npm-install-time

# - name: NPM Build
# working-directory: app/frontend
# run: |
# START=$SECONDS
# npm run build
# echo SCORE=$(($SECONDS-START)) >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: npm-build-time

# - name: Go Build
# working-directory: app
# run: |
# START=$SECONDS
# go build -ldflags '-s -w' -o main main.go
# echo SCORE=$(($SECONDS-START)) >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: go-build-time

# - name: Test
# working-directory: app
# run: |
# START=$SECONDS
# go test -race -v ./... -count=1 -coverprofile=coverage.out
# echo SCORE=$(($SECONDS-START)) >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: unit-test-run-time

# - name: Coverage
# working-directory: app
# run: |
# go tool cover -html=coverage.out -o coverage.html
# gocov convert coverage.out | gocov-xml > coverage.xml
# - name: Coveritup
# run: |
# curl -sLk https://raw.githubusercontent.com/kevincobain2000/cover-totalizer/master/install.sh | sh
# echo SCORE=`./cover-totalizer coverage.xml` >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: coverage

# - name: Go Binary Size
# working-directory: app
# run: |
# echo SCORE=`du -sk main | awk '{print $1}'` >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: go-binary-size

# - name: Number of dependencies
# working-directory: app
# run: echo SCORE=`go list -m all|wc -l|awk '{$1=$1};1'` >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: go-mod-dependencies

# - name: Number of GO Sec issues
# working-directory: app
# run: echo SCORE=`gosec -no-fail --quiet ./...|grep Issues | tail -1 |awk '{print $3}'` >> "$GITHUB_ENV"
# - uses: kevincobain2000/action-coveritup@v1
# with:
# type: go-sec-issues

# - uses: kevincobain2000/action-coveritup@v1
# with:
# pr_comment: true
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: kevincobain2000/action-gobrew@v2
with:
version: 'mod'
- name: Setup Node.js ${{ matrix.node-versions }}
uses: actions/setup-node@v2
with:
node-version: 20

- name: Build Dist for Embed
working-directory: app/frontend
run: |
npm install
npm run build
echo "You are running MIT License version" > dist/index.html
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --clean --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# diskcache directory
# diskcache directory
cache/*
vendor/*

Expand All @@ -17,4 +17,5 @@ tmp/
.env
*.pid
dist/
bin/
bin/
main
41 changes: 41 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
before:
hooks:
- go mod tidy
builds:
-
main: ./app/main.go
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
# - windows
- freebsd
goarch:
- amd64
- arm64
- arm
ignore:
- goos: windows
goarch: arm64
- goos: freebsd
goarch: arm64
- goos: windows
goarch: arm
- goos: freebsd
goarch: arm
- goos: darwin
goarch: arm
archives:
-
format: binary
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^bin'
13 changes: 5 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "action-coveritup"
author: "kevincobain2000"
description: "All in one action to publish code coverage, build and other metrics, comment on pull requests"
description: "All in one code coverage solution, build times and custom metrics, comment on pull requests"
branding:
icon: 'activity'
color: 'red'
Expand Down Expand Up @@ -95,11 +95,10 @@ runs:
"score": "${{ env.SCORE }}",
"user": "${{ github.actor }}",
"branch": "${{ steps.branch-name.outputs.current_branch }}",
"base_branch": "${{ steps.branch-name.outputs.base_ref_branch }}",
"pr": "${{ steps.find-pull-request.outputs.number }}",
"branches": "${{ env.CIU_ACTIVE_BRANCHES }}"
}' \
"${{inputs.host}}/api/upload"
"${{inputs.host}}/upload"
# Prepare comment on PR if it is a pull req
- name: Prepare comment on PR if it is a pull req
Expand Down Expand Up @@ -133,17 +132,15 @@ runs:
shell: bash
run: |
curl -sLk \
-X PUT \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: ${{ github.token }}' \
-d '{
"org": "${{github.repository_owner}}",
"repo": "${{ github.event.repository.name }}",
"commit": "${{ github.sha }}",
"type": "${{ inputs.type }}",
"branches": ""
"type": "${{ inputs.type }}"
}' \
"${{inputs.host}}/api/upload"
"${{inputs.host}}/destroy"
### End ###
### Compliance ###
44 changes: 44 additions & 0 deletions app/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# .air.conf
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go mod tidy && go build -o ./tmp/main main.go"
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "PP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "env", "conf"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "dist", "node_modules", "public", "frontend"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true
Loading

0 comments on commit a2e8daf

Please sign in to comment.