Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(dagger): fix dagger module #247

Merged
merged 19 commits into from
Jul 22, 2024
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
46 changes: 36 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- main

jobs:
test:
name: Test
tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand All @@ -22,10 +22,11 @@ jobs:
uses: dagger/dagger-for-github@v5
with:
verb: call
args: tests --dir .
args: tests --src-dir .
version: "0.11.0"

examples:
name: Examples
name: Run examples
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand All @@ -37,10 +38,11 @@ jobs:
uses: dagger/dagger-for-github@v5
with:
verb: call
args: examples --dir .
args: examples --src-dir .
version: "0.11.0"

lint:
name: Lint
name: Run linter
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -53,11 +55,11 @@ jobs:
uses: dagger/dagger-for-github@v5
with:
verb: call
args: lint --dir .
args: lint --src-dir .
version: "0.11.0"

check-generation:
name: Check generation
name: Check generation has been run
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -70,5 +72,29 @@ jobs:
uses: dagger/dagger-for-github@v5
with:
verb: call
args: check-generation --dir .
version: "0.11.0"
args: check-generation --src-dir .
version: "0.11.0"

publish:
name: Publish a new version
permissions:
contents: write
needs: ["tests", "examples", "lint", "check-generation"]
runs-on: ubuntu-latest
timeout-minutes: 5
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: actions/[email protected]
with:
go-version-file: go.mod
cache: true
- name: Publish on git
uses: dagger/dagger-for-github@v5
with:
verb: call
args: publish --src-dir .
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
43 changes: 24 additions & 19 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,12 +163,17 @@ func (ci *AsyncapiCodegenCi) Tests(
// git tag.
func (ci *AsyncapiCodegenCi) Publish(
ctx context.Context,
dir *Directory,
tag string,
srcDir *dagger.Directory,
// +optional
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
}

return nil
// Publish docker image
return publishDocker(ctx, srcDir, gi)
}
Loading