Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
21 changes: 5 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ on:
push:
branches:
- main
tags:
- v*

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
Expand All @@ -42,15 +42,4 @@ jobs:
run: mage -v test

- name: Build
if: "!startsWith(github.ref, 'refs/tags')"
run: mage -v build

- name: Release
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "$DOCKER_TOKEN" | docker login --username "$DOCKER_USERNAME" --password-stdin docker.io
mage -v release
env:
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
55 changes: 55 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: Version
required: true

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Install tools
run: |
./setup.sh
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"

- name: Tag
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
tag='${{ github.event.inputs.version }}'
git tag --annotate --message "Tag for release $tag" "$tag"
git push origin "refs/tags/$tag"

- name: Test
run: |
mage -v test

- name: Release
run: |
echo "$DOCKER_TOKEN" | docker login --username "$DOCKER_USERNAME" --password-stdin docker.io
mage -v release
env:
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
25 changes: 25 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
run:
timeout: 2m
allow-parallel-runners: true

linter-settings:
misspell:
locale: US

linters:
disable-all: true
enable:
- deadcode
- errcheck
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
75 changes: 69 additions & 6 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ limitations under the License.
package main

import (
"bufio"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
Expand All @@ -27,23 +35,78 @@ func Lint() error {
if err := sh.RunV("bash", "-c", "shopt -s globstar; shellcheck **/*.sh"); err != nil {
return err
}
if err := sh.RunV("golangci-lint", "run", "--timeout", "2m"); err != nil {
if err := sh.RunV("golangci-lint", "run"); err != nil {
return err
}
if err := sh.RunV("go", "vet", "-v", "./..."); err != nil {
if err := sh.RunV("go", "mod", "tidy"); err != nil {
return err
}
if err := sh.RunV("goimports", "-w", "-l", "."); err != nil {
return sh.RunV("git", "diff", "--exit-code")
}

func Format() error {
if err := sh.RunV("gofmt", "-s", "-w", "."); err != nil {
return err
}
if err := sh.RunV("go", "mod", "tidy"); err != nil {
if err := sh.RunV("goimports", "-w", "."); err != nil {
return err
}
return sh.RunV("git", "diff", "--exit-code")
return nil
}

func CheckLicenseHeaders() error {
return sh.RunV("./check_license_headers.sh")
var checkFailed bool

if err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
ext := filepath.Ext(path)
if ext == ".sh" || ext == ".go" {
fmt.Print("Checking ", path, " ")

f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()

var hasCopyright bool
var hasLicense bool

scanner := bufio.NewScanner(f)
// only check first 20 lines
for i := 0; i < 20 && scanner.Scan(); i++ {
line := scanner.Text()
if !hasCopyright && strings.Contains(line, "Copyright The SOPS Operator Authors") {
hasCopyright = true
}
if !hasLicense && strings.Contains(line, "https://www.apache.org/licenses/LICENSE-2.0") {
hasLicense = true
}
}

if !(hasCopyright && hasLicense) {
fmt.Println("❌")
checkFailed = true
} else {
fmt.Println("☑️")
}

return nil
}
return nil
}); err != nil {
return err
}

if checkFailed {
return errors.New("file(s) without license header found")
}
return nil
}

func ControllerGen() error {
Expand Down