blob: e6fbbda99f2d56f06fea294908aa719f5c44faec [file] [log] [blame]
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2026 The Linux Foundation
name: Gerrit Comment Handler
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
inputs:
GERRIT_BRANCH:
description: "Branch that change is against"
required: true
type: string
GERRIT_CHANGE_ID:
description: "The ID for the change"
required: true
type: string
GERRIT_CHANGE_NUMBER:
description: "The Gerrit number"
required: true
type: string
GERRIT_CHANGE_URL:
description: "URL to the change"
required: true
type: string
GERRIT_EVENT_TYPE:
description: "Gerrit event type"
required: true
type: string
GERRIT_PATCHSET_NUMBER:
description: "The patch number for the change"
required: true
type: string
GERRIT_PATCHSET_REVISION:
description: "The revision sha"
required: true
type: string
GERRIT_PROJECT:
description: "Project in Gerrit"
required: true
type: string
GERRIT_REFSPEC:
description: "Gerrit refspec of change"
required: true
type: string
GERRIT_COMMENT:
description: "The full gha-run command line from the Gerrit comment"
required: true
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.GERRIT_CHANGE_ID || github.run_id }}
cancel-in-progress: true
jobs:
# ==========================================================================
# JOB 1: parse-command
# ==========================================================================
# Parse GERRIT_COMMENT into a job name and parameters.
# ==========================================================================
parse-command:
runs-on: ubuntu-latest
outputs:
job-name: ${{ steps.parse.outputs.job-name }}
params: ${{ steps.parse.outputs.params }}
steps:
- name: Parse gha-run command
id: parse
env:
GERRIT_COMMENT: ${{ inputs.GERRIT_COMMENT }}
run: |
# Strip the leading "gha-run" verb.
command="${GERRIT_COMMENT#gha-run }"
# The first remaining token is the job name.
job_name="${command%% *}"
# Everything after the job name is the parameter string.
params="${command#"${job_name}"}"
params="${params# }"
echo "job-name=${job_name}" >> "${GITHUB_OUTPUT}"
echo "params=${params}" >> "${GITHUB_OUTPUT}"
echo "Parsed job name: ${job_name}"
echo "Parsed parameters: ${params}"
# ==========================================================================
# JOB 2: run-job (Route and Execute)
# ==========================================================================
# Use the parsed job name to decide what to do. A case statement keeps the
# routing explicit and rejects unknown job names.
# ==========================================================================
run-job:
needs: parse-command
if: ${{ needs.parse-command.outputs.job-name == 'sanity-test' }}
uses: opencord/shared-workflows/.github/workflows/sanity-test.yaml@main
secrets: inherit
with:
GERRIT_URL: ${{ inputs.GERRIT_URL }}
GERRIT_REFSPEC: ${{ inputs.GERRIT_REFSPEC }}
GERRIT_PROJECT: ${{ inputs.GERRIT_PROJECT }}
EXTRA_HELM_FLAGS: "--set global.image_tag=master --set onos-classic.image.tag=master"
# ==========================================================================
# JOB 3: report-status (Comment-Only Result Notification)
# ==========================================================================
# Report the outcome back to the Gerrit change as a comment. Use comment-only
# mode so the handler never casts a Verified vote on demand.
# ==========================================================================
report-status:
if: ${{ always() }}
needs: [parse-command, run-job]
runs-on: ubuntu-latest
steps:
- name: Get workflow conclusion
# yamllint disable-line rule:line-length
uses: im-open/workflow-conclusion@fce18569e28a9f2ed1feca1e6d4251e6a7365fdc # v2.2.4
- name: Report workflow conclusion
# yamllint disable-line rule:line-length
uses: lfreleng-actions/gerrit-review-action@c9df844dc6efe28b85b297c1c6d40390bfa4a378 # v1.0.0
with:
host: ${{ vars.GERRIT_SERVER }}
username: ${{ vars.GERRIT_SSH_USER }}
key: ${{ secrets.GERRIT_SSH_PRIVKEY }}
known_hosts: ${{ vars.GERRIT_KNOWN_HOSTS }}
gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
vote-type: ${{ env.WORKFLOW_CONCLUSION }}
comment-only: "true"