From 36475d9753ab959171daa7ef8fb51c66a8029b5d Mon Sep 17 00:00:00 2001 From: Maximilian Blatt Date: Thu, 8 Feb 2024 18:51:15 +0100 Subject: [PATCH] chore(ci): Add github workflow Signed-off-by: Maximilian Blatt --- .github/workflows/ci.yaml | 56 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 43 ++++++++++++++++++++++++++ .gitignore | 1 + .goreleaser.yaml | 49 +++++++++++++++++++++++++++++ internal/build/build.go | 29 ------------------ 5 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0136e2b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,56 @@ +name: ci + +on: + push: + branches: + - master + - release-* + tags: + - "*" + pull_request: {} + workflow_dispatch: {} + +permissions: + contents: write + # packages: write + # issues: write + +env: + GO_VERSION: '1.21.6' + GOLANGCI_VERSION: 'v1.55.2' + GORELEASER_VERSION: 'v1.23.0' + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: ${{ env.GORELEASER_VERSION }} + args: build --clean --snapshot + - name: Publish artifacts to Github + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist + lint: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - name: Lint + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3 + with: + version: ${{ env.GOLANGCI_VERSION }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b02ea9f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,43 @@ +name: release + +on: + push: + tags: + - "*" + +permissions: + contents: write + +env: + GO_VERSION: '1.21.6' + GOLANGCI_VERSION: 'v1.55.2' + GORELEASER_VERSION: 'v1.23.0' + +jobs: + goreleaser: + needs: + - build + - lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: ${{ env.GORELEASER_VERSION }} + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish artifacts to Github + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist diff --git a/.gitignore b/.gitignore index 598ae79..180ea8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.vscode +/dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..f7dfcfa --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,49 @@ +project_name: crossplanereleaser +builds: + - id: crossplanereleaser + env: + - CGO_ENABLED=0 + goos: + - linux + # - darwin + goarch: + - amd64 + # - arm64 + main: ./cmd/crossplanereleaser + +archives: + - id: crossplanereleaser + format: tar.gz + name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}' + builds: + - crossplanereleaser + wrap_in_directory: true + strip_parent_binary_folder: true + files: + - LICENSE.txt + - README.md + +checksum: + algorithm: sha256 + name_template: 'checksums.txt' + ids: + - crossplanereleaser + +release: + mode: keep-existing + github: + owner: mistermx + name: crossplanereleaser + +changelog: + use: git + groups: + - title: New Features + regexp: '^[\w\d]+\sfeat(\([\w-_\d]+\))?!?:.*$' + order: 0 + - title: Bug fixes + regexp: '^[\w\d]+\sfix(\([\w-_\d]+\))?!?:.*$' + order: 1 + - title: Others + regexp: '^[\w\d]+\s(build|chore|ci|docs|style|refactor|perf|test)(\([\w-_\d]+\))?!?:.*$' + order: 999 diff --git a/internal/build/build.go b/internal/build/build.go index b5a056a..b392ecc 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -2,9 +2,6 @@ package build import ( "context" - "path/filepath" - - v1 "github.com/mistermx/crossplanereleaser/config/v1" ) type PackageBuildConfig struct { @@ -16,29 +13,3 @@ type PackageBuildConfig struct { type BuilderBackend interface { BuildPackage(ctx context.Context, cfg *PackageBuildConfig) error } - -type Builder struct { - backend BuilderBackend -} - -func NewBuilder(backend BuilderBackend) *Builder { - return &Builder{ - backend: backend, - } -} - -func (b *Builder) BuildPackagesForConfig(ctx context.Context, cfg *v1.Config) error { - for _, pkgCfg := range cfg.XPackages { - buildCfg := &PackageBuildConfig{ - PackageDir: pkgCfg.Dir, - ExamplesDir: pkgCfg.Examples, - OutputPath: GetPackageOutputPath(cfg, &pkgCfg), - } - b.backend.BuildPackage(ctx, buildCfg) - } - return nil -} - -func GetPackageOutputPath(cfg *v1.Config, pkgCfg *v1.XPackageConfig) string { - return filepath.Join(cfg.Dist, pkgCfg.ID, pkgCfg.NameTemplate) -}