Skip to content

Commit

Permalink
ci: tidy up quoting of JSON args in workflow commands
Browse files Browse the repository at this point in the history
Spotted during the migration; using strconv.Quote is a more robust way
of ensuring the string argument to curl is quoted properly.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Idc2eaf2771a2244d8668584e95563ecd991900df
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/520759
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
myitcv committed Jul 15, 2021
1 parent 5f28bb4 commit 59079b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 39 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/test.yml
Expand Up @@ -27,9 +27,10 @@ jobs:
- if: ${{ startsWith(github.ref, 'refs/heads/ci/') }}
name: Update Gerrit CL message with starting message
run: 'curl -f -s -n -H "Content-Type: application/json" --request POST --data
''{"tag":"trybot","message":"Started the build... see progress at ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}"}'' https://review.gerrithub.io/a/changes/$(basename
$(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
"{\"tag\":\"trybot\",\"message\":\"Started the build... see progress at ${{
github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\"}"
https://review.gerrithub.io/a/changes/$(basename $(dirname $GITHUB_REF))/revisions/$(basename
$GITHUB_REF)/review'
test:
needs: start
strategy:
Expand Down Expand Up @@ -81,9 +82,9 @@ jobs:
- if: ${{ startsWith(github.ref, 'refs/heads/ci/') && failure() }}
name: Post any failures for this matrix entry
run: 'curl -f -s -n -H "Content-Type: application/json" --request POST --data
''{"tag":"trybot","message":"Build failed for ${{ runner.os }}-${{ matrix.go-version
"{\"tag\":\"trybot\",\"message\":\"Build failed for ${{ runner.os }}-${{ matrix.go-version
}}; see ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id
}} for more details","labels":{"TryBot-Result":-1}}'' https://review.gerrithub.io/a/changes/$(basename
}} for more details\",\"labels\":{\"TryBot-Result\":-1}}" https://review.gerrithub.io/a/changes/$(basename
$(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
mark_ci_success:
runs-on: ubuntu-18.04
Expand All @@ -103,9 +104,10 @@ jobs:
chmod 600 ~/.netrc
- name: Update Gerrit CL message with success message
run: 'curl -f -s -n -H "Content-Type: application/json" --request POST --data
''{"tag":"trybot","message":"Build succeeded for ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}","labels":{"TryBot-Result":1}}'' https://review.gerrithub.io/a/changes/$(basename
$(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
"{\"tag\":\"trybot\",\"message\":\"Build succeeded for ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}\",\"labels\":{\"TryBot-Result\":1}}"
https://review.gerrithub.io/a/changes/$(basename $(dirname $GITHUB_REF))/revisions/$(basename
$GITHUB_REF)/review'
delete_build_branch:
runs-on: ubuntu-18.04
if: ${{ startsWith(github.ref, 'refs/heads/ci/') && always() }}
Expand Down
21 changes: 12 additions & 9 deletions cmd/cue/cmd/testdata/script/cmd_github.txt
Expand Up @@ -198,9 +198,10 @@ jobs:
- if: ${{ startsWith(github.ref, 'refs/heads/ci/') }}
name: Update Gerrit CL message with starting message
run: 'curl -f -s -n -H "Content-Type: application/json" --request POST --data
''{"tag":"trybot","message":"Started the build... see progress at ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}"}'' https://review.gerrithub.io/a/changes/$(basename
$(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
"{\"tag\":\"trybot\",\"message\":\"Started the build... see progress at ${{
github.event.repository.html_url }}/actions/runs/${{ github.run_id }}\"}"
https://review.gerrithub.io/a/changes/$(basename $(dirname $GITHUB_REF))/revisions/$(basename
$GITHUB_REF)/review'
test:
needs: start
strategy:
Expand Down Expand Up @@ -252,9 +253,9 @@ jobs:
- if: ${{ startsWith(github.ref, 'refs/heads/ci/') && failure() }}
name: Post any failures for this matrix entry
run: 'curl -f -s -n -H "Content-Type: application/json" --request POST --data
''{"tag":"trybot","message":"Build failed for ${{ runner.os }}-${{ matrix.go-version
"{\"tag\":\"trybot\",\"message\":\"Build failed for ${{ runner.os }}-${{ matrix.go-version
}}; see ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id
}} for more details","labels":{"TryBot-Result":-1}}'' https://review.gerrithub.io/a/changes/$(basename
}} for more details\",\"labels\":{\"TryBot-Result\":-1}}" https://review.gerrithub.io/a/changes/$(basename
$(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
mark_ci_success:
runs-on: ubuntu-18.04
Expand All @@ -274,9 +275,10 @@ jobs:
chmod 600 ~/.netrc
- name: Update Gerrit CL message with success message
run: 'curl -f -s -n -H "Content-Type: application/json" --request POST --data
''{"tag":"trybot","message":"Build succeeded for ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}","labels":{"TryBot-Result":1}}'' https://review.gerrithub.io/a/changes/$(basename
$(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
"{\"tag\":\"trybot\",\"message\":\"Build succeeded for ${{ github.event.repository.html_url
}}/actions/runs/${{ github.run_id }}\",\"labels\":{\"TryBot-Result\":1}}"
https://review.gerrithub.io/a/changes/$(basename $(dirname $GITHUB_REF))/revisions/$(basename
$GITHUB_REF)/review'
delete_build_branch:
runs-on: ubuntu-18.04
if: ${{ startsWith(github.ref, 'refs/heads/ci/') && always() }}
Expand Down Expand Up @@ -1127,6 +1129,7 @@ package ci

import (
"github.com/SchemaStore/schemastore/src/schemas/json"
"strconv"
encjson "encoding/json"
)

Expand Down Expand Up @@ -1249,7 +1252,7 @@ test: _#bashWorkflow & {
message: string
labels?: "TryBot-Result": int
}
res: "\(_#curl) -n -H \"Content-Type: application/json\" --request POST --data '\(encjson.Marshal(#args))' https://review.gerrithub.io/a/changes/$(basename $(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review"
res: "\(_#curl) -n -H \"Content-Type: application/json\" --request POST --data \(strconv.Quote(encjson.Marshal(#args))) https://review.gerrithub.io/a/changes/$(basename $(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review"
}
}
}
Expand Down

0 comments on commit 59079b1

Please sign in to comment.