Skip to content

Commit

Permalink
SRE-410 FEAT bootstrap gha-file-sync (#1)
Browse files Browse the repository at this point in the history
* base for git-file-sync

* add action.yml

* make GITHUB_TOKEN required for the gha

* print debug for REPOSITORIES env check

* bind action.yaml input to Docker container env

* some first steps

* dont forget to commit the root

* udpate go.mod

* add go.sum consideration in Dockerfile

* first main step

* commit go modules files

* install glibc compatibility packages for the alpine image

* bind FILE_SYNC_BRANCH_REGEXP

* add Makefile for easy local testing

* split config into a dedicated package, add debug

* add debug for commit message

* avoid print of clone progress on stdout

* replaced PickBranchToCompare to SetHeadBranch, improve HasChanged, started UpdateHeadBranch

* implement UpdateRemote

* disable dry-run to test

* improve logging, add debug

* increase max commit size to 120, improve debug around pickbasebranch

* improve format of branch names, avoid creation of branch in updateremote

* improve format of branch names

* fix Dockerfile debug, add hardcoded commit author

* add PR_TITLE option, create PR mode

* try to revert dynamical create mode

* did not work

* ignore local testing files

* git plumb correctly, upgrade go to 1.20

* quick refacto/chore

* cap pr title max size to 100, small reverts on checkout and push options

* add CODEOWNERS file, improve default pr title and commit message

* enable CGO in Dockerfile

* add author retrieval and use it in commit

* make GetCurrentUsernameAndEmail more resilient

* re-enable pr comments

* improve desc on pr updates

* fix broken pointer assignment for existing PR number

* fix: instantiate existingPrNumber pointer before assignement

* refactorize code in a more modular way

* refactorize code in main.go

* improve logging of config

* fix: invert isNewBranch computation

* improve semantic of GetBranchNameByPRNumbers

* fix: invert IsSetup check

* comment Dryrun for testing purpose

* stop using os.Chdir

* handle both master and main as base default branch

* rename git-file-sync to github-file-sync considering the coupling

* improve README

* docs about pr page size

* uncomment dryrun condition

* fix typo in PickSyncBranch coms

* improve readability of the getbasebranchname

* improve the readme

* Update internal/github/helpers.go

* Update README.md

Co-authored-by: sven <[email protected]>

* Update internal/sync/manager.go

Co-authored-by: sven <[email protected]>

* Update internal/cfg/config.go

Co-authored-by: sven <[email protected]>

* chore: name more explicitly the task variable

* lint: rename mygit package to git

* Update internal/sync/task.go

Co-authored-by: sven <[email protected]>

* Update internal/sync/task.go

Co-authored-by: sven <[email protected]>

* improve overall by using linter rules

* remove unused golangci-lint comment

* add lint in Makefile

* change LICENSE to CC by 4.0

* add lint workflows

* fix dereference of a nil pointer in config

* set golang in .tool-versions

* remove misleading skeleton for local testing

* delete license temporarly

* add info about removal of files in README

* rewrite comment

---------

Co-authored-by: sven <[email protected]>
  • Loading branch information
SlevinWasAlreadyTaken and svenjr authored Apr 25, 2023
1 parent 69b73c9 commit d51d2d1
Show file tree
Hide file tree
Showing 20 changed files with 1,333 additions and 675 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @FATMAP/sre
32 changes: 32 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: lint

on:
push:
branches:
- '**'

jobs:
make:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install asdf
uses: asdf-vm/actions/setup@v1

- name: asdf cache
id: asdf-cache
uses: actions/cache@v2
with:
path: ~/.asdf/
key: ${{ runner.os }}-${{ hashFiles('**/.tool-versions') }}

- name: Install CD tools from .tool-versions
if: steps.asdf-cache.outputs.cache-hit != 'true'
uses: asdf-vm/actions/install@v1

- name: Run make lint
run: |
make lint
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
github-file-sync

# Test binary, built with `go test -c`
*.test
Expand All @@ -13,3 +14,9 @@

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

# env files
.env

# testing file
sync-testing/
82 changes: 82 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/FATMAP/gha-file-sync
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/FATMAP/avalanche
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument,case,condition,return]
govet:
check-shadowing: true
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- prealloc
- staticcheck
- stylecheck
- testpackage
- typecheck
- unconvert
- unparam
- unused
- whitespace
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
golang 1.20
golangci-lint 1.52.2
make 4.2.1
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
## build stage
FROM golang:1.20 as builder

LABEL maintainer="github.com/SlevinWasAlreadyTaken"

WORKDIR /app

# modules
ARG CGO_ENABLED=0
COPY go.mod ./
COPY go.sum ./
RUN go mod download

# copy sources
COPY . .

# compile
RUN go build -o /bin/github-file-sync

#
## run stage - minimalist final image
FROM alpine:3.17

# ensure glibc binaries is runnable by install glibc compatibility packages
RUN apk add libc6-compat

# get binary from build image
COPY --from=builder /bin/github-file-sync /bin/github-file-sync

ENTRYPOINT ["/bin/github-file-sync"]
Loading

0 comments on commit d51d2d1

Please sign in to comment.