qodana: use workflow dispatch (#1069)
This commit is contained in:
@@ -86,8 +86,8 @@ jobs:
|
|||||||
|
|
||||||
echo "reports_markdown=$REPORTS_MARKDOWN" >> $GITHUB_OUTPUT
|
echo "reports_markdown=$REPORTS_MARKDOWN" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Setup initial notification client payload
|
- name: Setup initial notification inputs
|
||||||
id: client_payload
|
id: inputs
|
||||||
if: >-
|
if: >-
|
||||||
startsWith(github.event_name, 'pull_request') &&
|
startsWith(github.event_name, 'pull_request') &&
|
||||||
steps.prepare.outputs.files != ''
|
steps.prepare.outputs.files != ''
|
||||||
@@ -106,26 +106,44 @@ jobs:
|
|||||||
# escape json control characters
|
# escape json control characters
|
||||||
message=$(jq -n --arg message "$message" '$message' | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
message=$(jq -n --arg message "$message" '$message' | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||||
|
|
||||||
client_payload=$(echo '{
|
secondary_inputs=$(echo '{
|
||||||
"issue_message": "'"${message}"'",
|
"issue_message": "'"${message}"'",
|
||||||
"issue_message_id": "'"qodana"'",
|
"issue_message_id": "'"qodana"'",
|
||||||
"issue_number": "'"${{ github.event.number }}"'"
|
"issue_number": "'"${{ github.event.number }}"'",
|
||||||
|
"issue_repo_owner": "'"${{ github.repository_owner }}"'",
|
||||||
|
"issue_repo_name": "'"${{ github.event.repository.name }}"'"
|
||||||
|
}' | jq -r .)
|
||||||
|
|
||||||
|
#escape json control characters
|
||||||
|
secondary_inputs=$(jq -n --arg secondary_inputs "$secondary_inputs" '$secondary_inputs' \
|
||||||
|
| sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||||
|
|
||||||
|
echo $secondary_inputs
|
||||||
|
|
||||||
|
# secondary input as string, not JSON
|
||||||
|
# todo - change dispatch_ref to master instead of nightly
|
||||||
|
primary_inputs=$(echo '{
|
||||||
|
"dispatch_repository": "'"${{ github.repository_owner }}/.github"'",
|
||||||
|
"dispatch_workflow": "'"dispatch-issue-comment.yml"'",
|
||||||
|
"dispatch_ref": "'"nightly"'",
|
||||||
|
"dispatch_inputs": "'"${secondary_inputs}"'"
|
||||||
}' | jq -c .)
|
}' | jq -c .)
|
||||||
|
|
||||||
echo $client_payload
|
echo $primary_inputs
|
||||||
echo $client_payload | jq .
|
echo $primary_inputs | jq .
|
||||||
echo "client_payload=$client_payload" >> $GITHUB_OUTPUT
|
echo "primary_inputs=$primary_inputs" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Repository Dispatch
|
- name: Workflow Dispatch
|
||||||
if: >-
|
if: >-
|
||||||
startsWith(github.event_name, 'pull_request') &&
|
startsWith(github.event_name, 'pull_request') &&
|
||||||
steps.prepare.outputs.files != ''
|
steps.prepare.outputs.files != ''
|
||||||
uses: peter-evans/repository-dispatch@v2.1.1
|
uses: benc-uk/workflow-dispatch@v1.2.2
|
||||||
|
continue-on-error: true # this might error if the workflow is not found, but we still want to run the next job
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_BOT_TOKEN }}
|
ref: ${{ github.base_ref || github.ref_name }} # base ref for PR and branch name for push
|
||||||
repository: ${{ github.repository_owner }}/.github
|
workflow: dispatcher.yml
|
||||||
event-type: issue-pr-comment
|
inputs: ${{ steps.inputs.outputs.primary_inputs }}
|
||||||
client-payload: ${{ steps.client_payload.outputs.client_payload }}
|
token: ${{ github.token }}
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
destination: ${{ steps.prepare.outputs.destination }}
|
destination: ${{ steps.prepare.outputs.destination }}
|
||||||
@@ -219,8 +237,8 @@ jobs:
|
|||||||
name: Dispatch Qodana
|
name: Dispatch Qodana
|
||||||
if: ${{ needs.qodana_initial_check.outputs.files != '' }}
|
if: ${{ needs.qodana_initial_check.outputs.files != '' }}
|
||||||
steps:
|
steps:
|
||||||
- name: Setup client payload
|
- name: Setup qodana publish inputs
|
||||||
id: client_payload
|
id: inputs
|
||||||
run: |
|
run: |
|
||||||
# get the artifacts
|
# get the artifacts
|
||||||
artifacts=${{ toJson(steps.artifacts.outputs.result) }}
|
artifacts=${{ toJson(steps.artifacts.outputs.result) }}
|
||||||
@@ -233,7 +251,7 @@ jobs:
|
|||||||
destination=${{ needs.qodana_initial_check.outputs.destination }}
|
destination=${{ needs.qodana_initial_check.outputs.destination }}
|
||||||
|
|
||||||
# client payload
|
# client payload
|
||||||
client_payload=$(echo '{
|
secondary_inputs=$(echo '{
|
||||||
"destination": "'"${destination}"'",
|
"destination": "'"${destination}"'",
|
||||||
"ref": "'"${{ github.ref }}"'",
|
"ref": "'"${{ github.ref }}"'",
|
||||||
"repo": "'"${{ github.repository }}"'",
|
"repo": "'"${{ github.repository }}"'",
|
||||||
@@ -241,16 +259,30 @@ jobs:
|
|||||||
"run_id": "'"${{ github.run_id }}"'",
|
"run_id": "'"${{ github.run_id }}"'",
|
||||||
"reports_markdown": "'"${{ needs.qodana_initial_check.outputs.reports_markdown }}"'",
|
"reports_markdown": "'"${{ needs.qodana_initial_check.outputs.reports_markdown }}"'",
|
||||||
"status": "'"${{ needs.qodana.outputs.qodana_status }}"'"
|
"status": "'"${{ needs.qodana.outputs.qodana_status }}"'"
|
||||||
|
}' | jq -r .)
|
||||||
|
|
||||||
|
#escape json control characters
|
||||||
|
secondary_inputs=$(jq -n --arg secondary_inputs "$secondary_inputs" '$secondary_inputs' \
|
||||||
|
| sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||||
|
|
||||||
|
echo $secondary_inputs
|
||||||
|
|
||||||
|
primary_inputs=$(echo '{
|
||||||
|
"dispatch_repository": "'"${{ github.repository_owner }}/qodana-reports"'",
|
||||||
|
"dispatch_workflow": "'"dispatch-qodana.yml"'",
|
||||||
|
"dispatch_ref": "'"master"'",
|
||||||
|
"dispatch_inputs": "'"$secondary_inputs"'"
|
||||||
}' | jq -c .)
|
}' | jq -c .)
|
||||||
|
|
||||||
echo $client_payload
|
echo $primary_inputs
|
||||||
echo $client_payload | jq .
|
echo $primary_inputs | jq .
|
||||||
echo "client_payload=$client_payload" >> $GITHUB_OUTPUT
|
echo "primary_inputs=$primary_inputs" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Repository Dispatch
|
- name: Workflow Dispatch
|
||||||
uses: peter-evans/repository-dispatch@v2.1.1
|
uses: benc-uk/workflow-dispatch@v1.2.2
|
||||||
|
continue-on-error: true # this might error if the workflow is not found, but we don't want to fail the workflow
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_BOT_TOKEN }}
|
ref: ${{ github.base_ref || github.ref_name }} # base ref for PR and branch name for push
|
||||||
repository: ${{ github.repository_owner }}/qodana-reports
|
workflow: dispatcher.yml
|
||||||
event-type: qodana-publish
|
inputs: ${{ steps.inputs.outputs.primary_inputs }}
|
||||||
client-payload: ${{ steps.client_payload.outputs.client_payload }}
|
token: ${{ github.token }}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
---
|
||||||
|
# This action is centrally managed in https://github.com/<organization>/.github/
|
||||||
|
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
|
||||||
|
# the above-mentioned repo.
|
||||||
|
|
||||||
|
# This action receives a dispatch event and passes it through to another repo. This is a workaround to avoid issues
|
||||||
|
# where fork PRs do not have access to secrets.
|
||||||
|
|
||||||
|
name: Dispatcher
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
dispatch_repository:
|
||||||
|
description: 'Repository to dispatch to'
|
||||||
|
required: true
|
||||||
|
dispatch_workflow:
|
||||||
|
description: 'Workflow to dispatch to'
|
||||||
|
required: true
|
||||||
|
dispatch_ref:
|
||||||
|
description: 'Ref/branch to dispatch to'
|
||||||
|
required: true
|
||||||
|
dispatch_inputs:
|
||||||
|
description: 'Inputs to send'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dispatcher:
|
||||||
|
name: Repository Dispatch
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Unescape JSON control characters
|
||||||
|
id: inputs
|
||||||
|
run: |
|
||||||
|
# get the inputs
|
||||||
|
dispatch_inputs=${{ github.event.inputs.dispatch_inputs }}
|
||||||
|
echo "$dispatch_inputs"
|
||||||
|
|
||||||
|
# temporarily replace newlines with a placeholder
|
||||||
|
dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/\\\\n/_!new_line!_/g')
|
||||||
|
|
||||||
|
# remove newline characters
|
||||||
|
dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/\\n//g')
|
||||||
|
|
||||||
|
# replace placeholder with newline
|
||||||
|
dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/_!new_line!_/\\n/g')
|
||||||
|
|
||||||
|
# replace escaped quotes with unescaped quotes
|
||||||
|
dispatch_inputs=$(echo ${dispatch_inputs} | sed 's/\\"//g')
|
||||||
|
|
||||||
|
# debug echo
|
||||||
|
echo "$dispatch_inputs"
|
||||||
|
|
||||||
|
# parse as JSON
|
||||||
|
dispatch_inputs=$(echo "$dispatch_inputs" | jq -c .)
|
||||||
|
|
||||||
|
# debug echo
|
||||||
|
echo "$dispatch_inputs"
|
||||||
|
|
||||||
|
echo "dispatch_inputs=$dispatch_inputs" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Workflow Dispatch
|
||||||
|
uses: benc-uk/workflow-dispatch@v1.2.2
|
||||||
|
with:
|
||||||
|
repo: ${{ github.event.inputs.dispatch_repository }}
|
||||||
|
ref: ${{ github.event.inputs.dispatch_ref || 'master' }} # default to master if not specified
|
||||||
|
workflow: ${{ github.event.inputs.dispatch_workflow }}
|
||||||
|
inputs: ${{ steps.inputs.outputs.dispatch_inputs }}
|
||||||
|
token: ${{ secrets.GH_BOT_TOKEN || github.token }} # fallback to default token if not specified
|
||||||
Reference in New Issue
Block a user