Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Angak0k committed Jan 23, 2024
0 parents commit c23e859
Show file tree
Hide file tree
Showing 43 changed files with 12,285 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DB_HOST=localhost
DB_USER=pmp_user
DB_PASSWORD=pmp1234
DB_NAME=pmp_db
DB_PORT=5432
STAGE=DEV
API_SECRET=myawsomeapisecret
TOKEN_HOUR_LIFESPAN=1
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "docker" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on:
pull_request:

jobs:
build:
name: test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_USER: pmp_user
POSTGRES_PASSWORD: pmp1234
POSTGRES_DB: pmp_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
id: go

# Verify that go.mod and go.sum is synchronized
- name: Check Go modules
run: |
if [[ ! -z $(go mod tidy && git diff --exit-code) ]]; then
echo "Please run "go mod tidy" to sync Go modules"
exit 1
fi
- name: Test
env:
DB_HOST: localhost
DB_USER: pmp_user
DB_PASSWORD: pmp1234
DB_NAME: pmp_db
DB_PORT: 5432
API_SECRET: myawsomeapisecret
TOKEN_HOUR_LIFESPAN: 1
run: make test

linter:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
cache-dependency-path: go.sum
id: go

- name: staticcheck
uses: dominikh/staticcheck-action@v1.3.0

- name: lint
uses: golangci/golangci-lint-action@v3.7.0
with:
version: v1.52.2
args: --timeout=5m --out-format=colored-line-number
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
31 changes: 31 additions & 0 deletions .github/workflows/doc-generation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Generate Swagger Documentation

on:
workflow_dispatch:

jobs:
generate-and-commit-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GHPUSH_PAT }}


- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Install Swaggo
run: go install github.com/swaggo/swag/cmd/swag@latest

- name: Generate Swagger Documentation
run: |
$(go env GOPATH)/bin/swag init
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add docs/
git commit -m "Update Swagger documentation" || echo "No changes to commit"
git push
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: release

on:
push:
# run only against tags
tags:
- "*"

permissions:
contents: write

jobs:
Releaser:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_USER: pmp_user
POSTGRES_PASSWORD: pmp1234
POSTGRES_DB: pmp_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GHPUSH_PAT }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Check Go modules
run: |
if [[ ! -z $(go mod tidy && git diff --exit-code) ]]; then
echo "Please run "go mod tidy" to sync Go modules"
exit 1
fi
- name: Test
env:
DB_HOST: localhost
DB_USER: pmp_user
DB_PASSWORD: pmp1234
DB_NAME: pmp_db
DB_PORT: 5432
API_SECRET: myawsomeapisecret
TOKEN_HOUR_LIFESPAN: 1
run: make test

- name: Install Swaggo
run: go install github.com/swaggo/swag/cmd/swag@latest
- name: Generate Swagger Documentation
run: |
# Generate Swagger documentation
$(go env GOPATH)/bin/swag init
# Configure Git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Create a new branch for the Swagger doc update
git checkout -b swagger-doc-update
# Commit and push if there are changes
git add docs/
git commit -m "Update Swagger documentation" -a || echo "No changes to commit"
git push origin swagger-doc-update
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# main binary
pimpmypack

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# Environment file
.env

# MacOS files
.DS_Store

dist/
46 changes: 46 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
run:
timeout: 5m

linters:
enable:
- bodyclose
- musttag
- gocritic
- unparam
- errorlint
- gci
- rowserrcheck
- revive

linters-settings:
revive:
rules:
- name: datarace
disabled: false
- name: deep-exit
disabled: false
- name: defer
disabled: false
- name: errorf
disabled: false
- name: function-length
disabled: false
arguments: [120, 0] # we have to decrease this value
- name: if-return
disabled: false
- name: superfluous-else
disabled: false
- name: unhandled-error
disabled: false
- name: unnecessary-stmt
disabled: false
- name: unreachable-code
disabled: false
- name: unused-parameter
disabled: false
- name: unused-receiver
disabled: false
- name: useless-break
disabled: false
- name: var-naming
disabled: true
40 changes: 40 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 1

before:
hooks:
- go mod tidy
- go generate ./...

builds:
- id: pimpmypack
env:
- CGO_ENABLED=0
goos:
- linux
- darwin

archives:
- format: tar.gz
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
dockers:
- image_templates:
- "ghcr.io/angak0k/pimpmypack:{{ .Tag }}"
- "ghcr.io/angak0k/pimpmypack:latest"
goos: linux
goarch: amd64
ids:
- pimpmypack
dockerfile: Dockerfile

changelog:
sort: asc
filters:
exclude:
- "^test:"
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:3.19.0

LABEL maintainer="romain@alki.earth"

RUN apk update && \
apk upgrade --no-cache

COPY pimpmypack /bin/pimpmypack

ENTRYPOINT ["/bin/pimpmypack"]
Loading

0 comments on commit c23e859

Please sign in to comment.