-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/go-yaml
- Loading branch information
Showing
59 changed files
with
1,883 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# name of the action | ||
name: jsonschema | ||
|
||
# trigger on release events | ||
on: | ||
release: | ||
types: [created] | ||
|
||
# pipeline to execute | ||
jobs: | ||
schema: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: clone | ||
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 | ||
|
||
- name: install go | ||
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | ||
with: | ||
# use version from go.mod file | ||
go-version-file: "go.mod" | ||
cache: true | ||
check-latest: true | ||
|
||
- name: build | ||
run: | | ||
make jsonschema | ||
- name: upload | ||
uses: skx/github-action-publish-binaries@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
args: "schema.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,23 +12,29 @@ jobs: | |
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: clone | ||
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 | ||
|
||
- name: install go | ||
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | ||
with: | ||
# use version from go.mod file | ||
go-version-file: 'go.mod' | ||
cache: true | ||
check-latest: true | ||
|
||
- name: test | ||
run: | | ||
make test | ||
- name: coverage | ||
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: coverage.out | ||
- name: clone | ||
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 | ||
|
||
- name: install go | ||
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | ||
with: | ||
# use version from go.mod file | ||
go-version-file: "go.mod" | ||
cache: true | ||
check-latest: true | ||
|
||
- name: test | ||
run: | | ||
make test | ||
- name: test jsonschema | ||
run: | | ||
go install github.com/santhosh-tekuri/jsonschema/cmd/[email protected] | ||
make test-jsonschema | ||
- name: coverage | ||
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: coverage.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package deployment | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"gorm.io/gorm" | ||
|
||
"github.com/go-vela/server/compiler" | ||
"github.com/go-vela/server/database" | ||
"github.com/go-vela/server/router/middleware/repo" | ||
"github.com/go-vela/server/router/middleware/user" | ||
"github.com/go-vela/server/scm" | ||
"github.com/go-vela/server/util" | ||
) | ||
|
||
// swagger:operation GET /api/v1/deployments/{org}/{repo}/config deployments GetDeploymentConfig | ||
// | ||
// Get a deployment config | ||
// | ||
// --- | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - in: path | ||
// name: org | ||
// description: Name of the organization | ||
// required: true | ||
// type: string | ||
// - in: path | ||
// name: repo | ||
// description: Name of the repository | ||
// required: true | ||
// type: string | ||
// - in: query | ||
// name: ref | ||
// description: Ref to target for the deployment config | ||
// type: string | ||
// security: | ||
// - ApiKeyAuth: [] | ||
// responses: | ||
// '200': | ||
// description: Successfully retrieved the deployment config | ||
// schema: | ||
// "$ref": "#/definitions/Deployment" | ||
// '400': | ||
// description: Invalid request payload or path | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
// '401': | ||
// description: Unauthorized | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
// '404': | ||
// description: Not found | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
// '500': | ||
// description: Unexpected server error | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
|
||
// GetDeploymentConfig represents the API handler to get a deployment config at a given ref. | ||
func GetDeploymentConfig(c *gin.Context) { | ||
// capture middleware values | ||
l := c.MustGet("logger").(*logrus.Entry) | ||
r := repo.Retrieve(c) | ||
u := user.Retrieve(c) | ||
|
||
ctx := c.Request.Context() | ||
|
||
// capture ref from parameters - use default branch if not provided | ||
ref := util.QueryParameter(c, "ref", r.GetBranch()) | ||
|
||
entry := fmt.Sprintf("%s@%s", r.GetFullName(), ref) | ||
|
||
l.Debugf("reading deployment config %s", entry) | ||
|
||
var config []byte | ||
|
||
// check if the pipeline exists in the database | ||
p, err := database.FromContext(c).GetPipelineForRepo(ctx, ref, r) | ||
if err != nil { | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
l.Debugf("pipeline %s not found in database, fetching from scm", entry) | ||
|
||
config, err = scm.FromContext(c).ConfigBackoff(ctx, u, r, ref) | ||
if err != nil { | ||
retErr := fmt.Errorf("unable to get pipeline configuration for %s: %w", entry, err) | ||
|
||
util.HandleError(c, http.StatusNotFound, retErr) | ||
|
||
return | ||
} | ||
} else { | ||
// some other error | ||
retErr := fmt.Errorf("unable to get pipeline for %s: %w", entry, err) | ||
|
||
util.HandleError(c, http.StatusInternalServerError, retErr) | ||
|
||
return | ||
} | ||
} else { | ||
l.Debugf("pipeline %s found in database", entry) | ||
|
||
config = p.GetData() | ||
} | ||
|
||
// set up compiler | ||
compiler := compiler.FromContext(c).Duplicate().WithCommit(ref).WithRepo(r).WithUser(u) | ||
|
||
// compile the pipeline | ||
pipeline, _, err := compiler.CompileLite(ctx, config, nil, true) | ||
if err != nil { | ||
retErr := fmt.Errorf("unable to compile pipeline %s: %w", entry, err) | ||
|
||
util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, pipeline.Deployment) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/go-vela/server/schema" | ||
) | ||
|
||
func main() { | ||
js, err := schema.NewPipelineSchema() | ||
if err != nil { | ||
logrus.Fatal("schema generation failed:", err) | ||
} | ||
|
||
// output json | ||
j, err := json.MarshalIndent(js, "", " ") | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
|
||
fmt.Printf("%s\n", j) | ||
} |
Oops, something went wrong.