Skip to content

Commit

Permalink
chore(ci): Add github workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Blatt <[email protected]>
  • Loading branch information
MisterMX committed Feb 8, 2024
1 parent 00eb8a2 commit 36475d9
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 29 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
43 changes: 43 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.vscode
/dist
49 changes: 49 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package build

import (
"context"
"path/filepath"

v1 "github.com/mistermx/crossplanereleaser/config/v1"
)

type PackageBuildConfig struct {
Expand All @@ -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)
}

0 comments on commit 36475d9

Please sign in to comment.