Skip to content

Commit

Permalink
ci: add -f (fail) flag to curl calls in GitHub Actions trigger
Browse files Browse the repository at this point in the history
If any of the curl callbacks to the Gerrit instance (e.g. notifying the
start of a runtrybot-triggered build, failure or success) themselves
fail we need to fail the build.

Therefore we use the -f (fail) flag to curl, so that if any of these
callbacks do fail, the curl command will fail, which will fail the build
(as expected).

Also fix the version of the JSON schema definition we are using for
GitHub workflows.

Regenerate to fix stale files.

Change-Id: I6ecee5c78b2f557adf4912c4bad2d394bc0b5931
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6040
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
myitcv committed May 19, 2020
1 parent c114dbb commit 4c7d062
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rebuild_tip_cuelang_org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Rebuild tip.cuelang.org
run: curl -X POST -d {} https://api.netlify.com/build_hooks/${{ secrets.CuelangOrgTipRebuildHook
run: curl -f -X POST -d {} https://api.netlify.com/build_hooks/${{ secrets.CuelangOrgTipRebuildHook
}}
6 changes: 3 additions & 3 deletions .github/workflows/test_dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: test -z "$(git status --porcelain)" || (git status; git diff; false)
- name: Post any failures for this matrix entry
if: ${{ failure() }}
run: 'curl -s -H "Content-Type: application/json" --request POST --data ''{"labels":
run: 'curl -f -s -H "Content-Type: application/json" --request POST --data ''{"labels":
{ "Code-Review": -1 }, "message":"Build failed for ${{ runner.os }}-${{ matrix.go-version
}}; see ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id
}} for more details"}'' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{
Expand All @@ -69,7 +69,7 @@ jobs:
- name: Write the gitcookies file
run: echo "$GERRIT_COOKIE" > ~/.gitcookies
- name: Update Gerrit CL message with starting message
run: 'curl -s -H "Content-Type: application/json" --request POST --data ''{"message":"Started
run: 'curl -f -s -H "Content-Type: application/json" --request POST --data ''{"message":"Started
the build... see progress at ${{ github.event.repository.html_url }}/actions/runs/${{
github.run_id }}"}'' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{
github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit
Expand All @@ -81,7 +81,7 @@ jobs:
- name: Write the gitcookies file
run: echo "$GERRIT_COOKIE" > ~/.gitcookies
- name: Update Gerrit CL message with success message
run: 'curl -s -H "Content-Type: application/json" --request POST --data ''{"labels":
run: 'curl -f -s -H "Content-Type: application/json" --request POST --data ''{"labels":
{ "Code-Review": 1 }, "message":"Build succeeded for ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}"}'' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{
github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Workflow :: {
// Each run keyword represents a new process and shell in the
// virtual environment. When you provide multi-line commands,
// each line runs in the same shell.
run?: string, shell?: #shell, "working-directory"?: #def["working-directory"]
run?: string, shell?: #shell, "working-directory"?: #["working-directory"]

// You can use the if conditional to prevent a step from running
// unless a condition is met. You can use any supported context
Expand Down Expand Up @@ -547,12 +547,12 @@ Workflow :: {

#defaults: run?: {
shell?: #shell
"working-directory"?: #def["working-directory"]
"working-directory"?: #["working-directory"]
}

#shell: string | ("bash" | "pwsh" | "python" | "sh" | "cmd" | "powershell")

#def: "working-directory": string
#: "working-directory": string

#event: "check_run" | "check_suite" | "create" | "delete" | "deployment" | "deployment_status" | "fork" | "gollum" | "issue_comment" | "issues" | "label" | "member" | "milestone" | "page_build" | "project" | "project_card" | "project_column" | "public" | "pull_request" | "pull_request_review" | "pull_request_review_comment" | "push" | "registry_package" | "release" | "status" | "watch" | "repository_dispatch"

Expand Down
4 changes: 2 additions & 2 deletions internal/ci/ci_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ command: genworkflows: task: {
command: vendorgithubschema: {
get: http.Get & {
request: body: ""
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json"
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/f7a0789ccb3bd74a720ddbd6691d60fd9e2d8b7a/src/schemas/json/github-workflow.json"
}
convert: exec.Run & {
stdin: get.response.body
cmd: "go run cuelang.org/go/cmd/cue import -f -p json -l Workflow:: jsonschema: - --outfile pkg/github.com/SchemaStore/schemastore/schemas/json/github-workflow.cue"
cmd: "go run cuelang.org/go/cmd/cue import -f -p json -l Workflow:: jsonschema: - --outfile pkg/github.com/SchemaStore/schemastore/schemas/json/github-workflow.cue"
}
}
8 changes: 4 additions & 4 deletions internal/ci/workflows.cue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test_dispatch: json.Workflow & {
}, {
name: "Update Gerrit CL message with starting message"
run: """
curl -s -H \"Content-Type: application/json\" --request POST --data '{\"message\":\"Started the build... see progress at ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\"}' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
curl -f -s -H \"Content-Type: application/json\" --request POST --data '{\"message\":\"Started the build... see progress at ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\"}' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
"""
}]
}
Expand Down Expand Up @@ -167,7 +167,7 @@ test_dispatch: json.Workflow & {
}, {
name: "Post any failures for this matrix entry"
run: """
curl -s -H \"Content-Type: application/json\" --request POST --data '{\"labels\": { \"Code-Review\": -1 }, \"message\":\"Build failed for ${{ runner.os }}-${{ matrix.go-version }}; see ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} for more details\"}' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
curl -f -s -H \"Content-Type: application/json\" --request POST --data '{\"labels\": { \"Code-Review\": -1 }, \"message\":\"Build failed for ${{ runner.os }}-${{ matrix.go-version }}; see ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} for more details\"}' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
"""
if: "${{ failure() }}"
}]
Expand All @@ -189,7 +189,7 @@ test_dispatch: json.Workflow & {
}, {
name: "Update Gerrit CL message with success message"
run: """
curl -s -H \"Content-Type: application/json\" --request POST --data '{\"labels\": { \"Code-Review\": 1 }, \"message\":\"Build succeeded for ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\"}' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
curl -f -s -H \"Content-Type: application/json\" --request POST --data '{\"labels\": { \"Code-Review\": 1 }, \"message\":\"Build succeeded for ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\"}' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
"""
}]
needs: "test"
Expand Down Expand Up @@ -260,7 +260,7 @@ rebuild_tip_cuelang_org: json.Workflow & {
"runs-on": "ubuntu-latest"
steps: [{
name: "Rebuild tip.cuelang.org"
run: "curl -X POST -d {} https://api.netlify.com/build_hooks/${{ secrets.CuelangOrgTipRebuildHook }}"
run: "curl -f -X POST -d {} https://api.netlify.com/build_hooks/${{ secrets.CuelangOrgTipRebuildHook }}"
}]
}
}

0 comments on commit 4c7d062

Please sign in to comment.