#A lot of the cookbook seems to be using
1 messages · Page 1 of 1 (latest)
I want my github action to fail, but still output the results from a file in the container
the issue stopping me doing this is the container fails due to exit code and then getting the file doesnt work.
So i return a dagger.Container instead, and set a $? > /status_code; but then not sure how to fail the github action, it appears like "successful".
Are you looking at the old cookbook from the 0.9x branch of the docs? If so, this shows pre-module code. We are working on a port of the cookbook now.
Could you share the code you have so far for this?
yes, i was hacking aorund so much, and i could only get the Github Action failing or passing, but not how I wanted, nor displaying my results how I wanted.
but i ended up with this:
// validates the OpenAPI specifications by performing linting using the Spectral CLI.
func (m *DsgIcisOpenapiKiota) ValidateOpenapiSpecs(ctx context.Context) *dagger.Container {
energyapiyaml := dag.HTTP("https://developer.icis.com/portals/api/sites/icis-live-portal/liveportal/apis/energyapi/download_spec")
energyforesightapiyaml := dag.HTTP("https://developer.icis.com/portals/api/sites/icis-live-portal/liveportal/apis/energyforesightapi/download_spec")
lnganalyticsapiyaml := dag.HTTP("https://developer.icis.com/portals/api/sites/icis-live-portal/liveportal/apis/lnganalyticsapi/download_spec")
return dag.
Container().
From("node:16").
WithWorkdir("/specs").
// https://meta.stoplight.io/docs/spectral/83527ef2dd8c0-extending-rulesets
// https://meta.stoplight.io/docs/spectral/d3482ff0ccae9-rules
WithNewFile("/specs/.spectral.yaml", dagger.ContainerWithNewFileOpts{
// We need 3.0.X version of OAS3 but not v3.1.X
// https://meta.stoplight.io/docs/spectral/e5b9616d6d50c-rulesets#formats
Contents: spectralConfig,
}).
WithFile("/specs/energyapi.yaml", energyapiyaml).
WithFile("/specs/energyforesightapi.yaml", energyforesightapiyaml).
WithFile("/specs/lnganalyticsapi.yaml", lnganalyticsapiyaml).
// https://meta.stoplight.io/docs/spectral/9ffa04e052cc1-spectral-cli
WithExec([]string{
"npm",
"install",
"-g",
"@stoplight/spectral-cli",
}).
// // https://archive.docs.dagger.io/0.9/cookbook/#continue-using-container-after-command-execution-fails
// WithNewFile("/specs/run-lint", dagger.ContainerWithNewFileOpts{
// Contents: "spectral lint /specs/*.yaml -f github-actions -o results.github-actions",
// Permissions: 0o750,
// }).
WithExec([]string{
"sh", "-c", "spectral lint /specs/*.yaml -f github-actions",
})
}
before, iwas doing all kinds of "hacks" checkign exit codes, then trying to extract a report file (which spectral can do) and in the end I was like, let me just return the container (this still works... even tho the exit is bad)
jobs:
validate:
name: validate openapi specs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint OpenAPI Specifications
uses: dagger/dagger-for-github@v5.6.0
with:
version: "latest"
verb: call
args: validate-openapi-specs stdout
previously i was, always trying to return a "string" so i could see that result in the Github Actions output, but it was never sying the build passed or failed, and was quite hacky
maybe my "simpler but working solution" is still not how you guys might vision something like this, but it does work for me this way
Actually something still doesnt seem right looking back at this but previously I was doing this:
args: validate-openapi-specs contents