Skip to content

Commit

Permalink
feat(ci): add git publish
Browse files Browse the repository at this point in the history
  • Loading branch information
lerenn committed Jul 21, 2024
1 parent e1555da commit 44d0331
Show file tree
Hide file tree
Showing 19 changed files with 2,183 additions and 1,400 deletions.
123 changes: 72 additions & 51 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,87 @@ on:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go.mod
cache: true
- name: Run tests
uses: dagger/dagger-for-github@v5
with:
verb: call
args: tests --dir .
version: "0.11.0"
examples:
name: Examples
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go.mod
cache: true
- name: Run examples
uses: dagger/dagger-for-github@v5
with:
verb: call
args: examples --dir .
version: "0.11.0"
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go.mod
cache: true
- name: Lint
uses: dagger/dagger-for-github@v5
with:
verb: call
args: lint --dir .
version: "0.11.0"
# tests:
# name: Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/[email protected]
# - uses: actions/[email protected]
# with:
# go-version-file: go.mod
# cache: true
# - name: Run tests
# uses: dagger/dagger-for-github@v5
# with:
# verb: call
# args: tests --dir .
# version: "0.11.0"

# examples:
# name: Examples
# runs-on: ubuntu-latest
# steps:
# - uses: actions/[email protected]
# - uses: actions/[email protected]
# with:
# go-version-file: go.mod
# cache: true
# - name: Run examples
# uses: dagger/dagger-for-github@v5
# with:
# verb: call
# args: examples --dir .
# version: "0.11.0"

# lint:
# name: Lint
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - uses: actions/[email protected]
# - uses: actions/[email protected]
# with:
# go-version-file: go.mod
# cache: true
# - name: Lint
# uses: dagger/dagger-for-github@v5
# with:
# verb: call
# args: lint --dir .
# version: "0.11.0"

# check-generation:
# name: Check generation
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - uses: actions/[email protected]
# - uses: actions/[email protected]
# with:
# go-version-file: go.mod
# cache: true
# - name: Lint
# uses: dagger/dagger-for-github@v5
# with:
# verb: call
# args: check-generation --dir .
# version: "0.11.0"

check-generation:
name: Check generation
publish:
name: Publish asyncapi-codegen new version
# needs: ["tests", "examples", "lint", "check-generation"]
runs-on: ubuntu-latest
timeout-minutes: 5
# if: github.ref == 'refs/heads/main'
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
go-version-file: go.mod
cache: true
- name: Lint
- name: Publish on git
uses: dagger/dagger-for-github@v5
with:
verb: call
args: check-generation --dir .
version: "0.11.0"
args: publish --src-dir . --ssh-dir=~/.ssh
version: "0.11.0"
1 change: 1 addition & 0 deletions build/ci/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dagger.gen.go linguist-generated
/internal/dagger/** linguist-generated
/internal/querybuilder/** linguist-generated
/internal/telemetry/** linguist-generated
4 changes: 4 additions & 0 deletions build/ci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dagger.gen.go
/internal/dagger
/internal/querybuilder
/internal/telemetry
39 changes: 21 additions & 18 deletions build/ci/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ func (ci *AsyncapiCodegenCi) cachedBrokers() map[string]*dagger.Service {
// Execute all check operations (generate, lint, examples, and tests)
func (ci *AsyncapiCodegenCi) Check(
ctx context.Context,
dir *Directory,
srcDir *dagger.Directory,
) (string, error) {
if _, err := ci.CheckGeneration(ctx, dir); err != nil {
if _, err := ci.CheckGeneration(ctx, srcDir); err != nil {
return "", err
}

if _, err := ci.Lint(ctx, dir); err != nil {
if _, err := ci.Lint(ctx, srcDir); err != nil {
return "", err
}

if _, err := ci.Examples(ctx, dir); err != nil {
if _, err := ci.Examples(ctx, srcDir); err != nil {
return "", err
}

if _, err := ci.Tests(ctx, dir); err != nil {
if _, err := ci.Tests(ctx, srcDir); err != nil {
return "", err
}

Expand All @@ -68,11 +68,11 @@ func (ci *AsyncapiCodegenCi) Check(
// source code and check that there is no change.
func (ci *AsyncapiCodegenCi) CheckGeneration(
ctx context.Context,
dir *Directory,
srcDir *dagger.Directory,
) (string, error) {
_, err := dag.Container().
From(golangImage).
With(sourceCodeAndGoCache(dir)).
With(sourceCodeAndGoCache(srcDir)).
WithExec([]string{"sh", "./scripts/check-generation.sh"}).
Stdout(ctx)

Expand All @@ -82,11 +82,11 @@ func (ci *AsyncapiCodegenCi) CheckGeneration(
// Lint AsyncAPI-Codegen source code.
func (ci *AsyncapiCodegenCi) Lint(
ctx context.Context,
dir *Directory,
srcDir *dagger.Directory,
) (string, error) {
return dag.Container().
From(linterImage).
With(sourceCodeAndGoCache(dir)).
With(sourceCodeAndGoCache(srcDir)).
WithMountedCache("/root/.cache/golangci-lint", dag.CacheVolume("golangci-lint")).
WithExec([]string{"golangci-lint", "run"}).
Stdout(ctx)
Expand All @@ -95,10 +95,10 @@ func (ci *AsyncapiCodegenCi) Lint(
// Run AsyncAPI-Codegen examples.
func (ci *AsyncapiCodegenCi) Examples(
ctx context.Context,
dir *Directory,
srcDir *dagger.Directory,
) (string, error) {
// Get examples subdirs
subdirs, err := directoriesAtSublevel(ctx, dir.Directory("examples"), 2, "./examples")
subdirs, err := directoriesAtSublevel(ctx, srcDir.Directory("examples"), 2, "./examples")
if err != nil {
return "", err
}
Expand All @@ -110,7 +110,7 @@ func (ci *AsyncapiCodegenCi) Examples(
app := dag.Container().
From(golangImage).
// Add source code as work directory
With(sourceCodeAndGoCache(dir)).
With(sourceCodeAndGoCache(srcDir)).
// Set broker as dependency
With(bindBrokers(ci.cachedBrokers())).
// Execute command
Expand All @@ -125,7 +125,7 @@ func (ci *AsyncapiCodegenCi) Examples(
// Add base image
From(golangImage).
// Add source code as work directory
With(sourceCodeAndGoCache(dir)).
With(sourceCodeAndGoCache(srcDir)).
// Set broker as dependency
With(bindBrokers(ci.cachedBrokers())).
// Add app as dependency of user
Expand All @@ -144,13 +144,13 @@ func (ci *AsyncapiCodegenCi) Examples(
// Run tests from AsyncAPICodegen
func (ci *AsyncapiCodegenCi) Tests(
ctx context.Context,
dir *Directory,
srcDir *dagger.Directory,
) (string, error) {
return dag.Container().
// Add base image
From(golangImage).
// Add source code as work directory
With(sourceCodeAndGoCache(dir)).
With(sourceCodeAndGoCache(srcDir)).
// Set brokers as dependencies of app and user
With(bindBrokers(ci.cachedBrokers())).
// Execute command
Expand All @@ -163,10 +163,13 @@ func (ci *AsyncapiCodegenCi) Tests(
// git tag.
func (ci *AsyncapiCodegenCi) Publish(
ctx context.Context,
dir *Directory,
tag string,
srcDir *dagger.Directory,
sshDir *dagger.Directory,
) error {
if err := publishDocker(ctx, dir, tag); err != nil {
gi := NewGit(srcDir, sshDir)

// Push new commit tag if needed
if err := gi.PushNewSemVerIfNeeded(ctx); err != nil {
return err
}

Expand Down
Loading

0 comments on commit 44d0331

Please sign in to comment.