Files
asterisk/.github/workflows/OnPRStateChanged.yml
George Joseph 478fbbb828 .github: OnPRCherryPickTest,OnPRStateChanged,OnPRRecheck: Add job summaries.
...and refactor environment variables.
2025-02-10 13:20:13 -07:00

124 lines
5.2 KiB
YAML

#
# Workflows, like this one, that are triggered by PRs submitted
# from forked repositories are severly limited in what they can do
# for security reasons. For instance, they can't add or remove
# labels or comments even on the PR that triggered them. Since
# we need to both of those things, GitHub recommends creating a
# separate workflow that does those tasks that's triggered when
# this PR workflow starts or finishes. Since that workflow isn't
# being run in the context of a forked repo, it has all the
# privileges needed to add and remove labels and comments. The
# accompanying OnPRStateChangedPriv workflow does just that.
name: PRChanged
# WARNING! The run name MUST start with "PR <pr_number>".
# The accompanying privleged workflow parses this to find
# the PR number. It's the only reliable way it can get it.
run-name: "PR ${{ github.event.number }} ${{ github.event.action }} by ${{ github.actor }}"
on:
pull_request:
types: [opened, reopened, synchronize]
concurrency:
group: check-${{ github.event.number }}
cancel-in-progress: true
env:
REPO: ${{ github.repository }}
REPO_DIR: ${{ github.workspace }}/${{ github.event.repository.name }}
REPO_ORG: ${{ github.event.repository.owner.login }}
PR_NUMBER: ${{ github.event.number }}
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
WORKFLOW_NAME: ${{ github.workflow }}
WORKFLOW_RUN_ID: ${{ github.run_id }}
SCRIPT_DIR: ${{ github.workspace }}/asterisk-ci-actions/scripts
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOG_DIR: ${{ github.workspace }}/logs
ACTIONS_OWNER: asterisk
ACTIONS_REPO: asterisk-ci-actions
ACTIONS_BRANCH: main
jobs:
#
# Pull requests created from forked respositories don't have access
# to the "Action Variables" ('vars' context) so we need to retrieve
# control data from an action that's located in asterisk-ci-actions.
#
Setup:
runs-on: ubuntu-latest
outputs:
vars: ${{ steps.setvars.outputs.control_data }}
testsuite_test_pr: ${{ steps.setup.outputs.TESTSUITE_TEST_PR }}
normalized_branch: ${{ steps.setup.outputs.NORMALIZED_BRANCH }}
steps:
- id: setvars
uses: asterisk/asterisk-ci-actions/GetRepoControlData@main
with:
repo: ${{ github.event.repository.name }}
- id: setup
env:
PR_STATE_CHANGE_DELAY_SEC: ${{ fromJSON(steps.setvars.outputs.control_data).PR_STATE_CHANGE_DELAY_SEC || 120 }}
TESTSUITE_TEST_PR_REGEX: ${{ fromJSON(steps.setvars.outputs.control_data).TESTSUITE_TEST_PR_REGEX }}
run: |
# Wait then get testsuite PR
echo "Waiting for ${PR_STATE_CHANGE_DELAY_SEC} seconds to give user a chance to add PR comments"
sleep ${PR_STATE_CHANGE_DELAY_SEC}
NORMALIZED_BRANCH="${BASE_BRANCH/\//-}"
echo "NORMALIZED_BRANCH=${NORMALIZED_BRANCH}" >> ${GITHUB_ENV}
echo "NORMALIZED_BRANCH=${NORMALIZED_BRANCH}" >> ${GITHUB_OUTPUT}
wget -qO asterisk-ci-actions.tar.gz \
https://github.com/${ACTIONS_OWNER}/${ACTIONS_REPO}/archive/refs/heads/${ACTIONS_BRANCH}.tar.gz
tar -xf asterisk-ci-actions.tar.gz --transform="s/^${ACTIONS_REPO}-${ACTIONS_BRANCH}/asterisk-ci-actions/g"
# Testsuite PR will be placed in TESTSUITE_TEST_PR in both
# GITHUB_ENV and GITHUB_OUTPUT by the script.
${SCRIPT_DIR}/getTestsuitePRfromAsteriskPR.sh \
--repo=${REPO} \
--pr-number=${PR_NUMBER} \
--testsuite-pr-regex="${TESTSUITE_TEST_PR_REGEX}"
Check:
name: Check
needs: Setup
uses: asterisk/asterisk-ci-actions/.github/workflows/AsteriskUnitGateTest.yml@main
with:
test_type: prstatechange
asterisk_repo: ${{ github.repository }}
pr_number: ${{ github.event.number }}
base_branch: ${{ github.event.pull_request.base.ref }}
build_options: ${{ fromJSON(needs.Setup.outputs.vars).BUILD_OPTIONS }}
unittest_command: ${{ fromJSON(needs.Setup.outputs.vars).UNITTEST_COMMAND }}
testsuite_repo: ${{ fromJSON(needs.Setup.outputs.vars).TESTSUITE_REPO }}
testsuite_test_pr: ${{ needs.Setup.outputs.testsuite_test_pr }}
gatetest_list: ${{ fromJSON(needs.Setup.outputs.vars).GATETEST_LIST }}
gatetest_commands: ${{ fromJSON(needs.Setup.outputs.vars).GATETEST_COMMANDS }}
secrets:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PostWorkflow:
if: ${{ success() || failure() }}
runs-on: ubuntu-latest
needs: [Setup,Check]
env:
RESULT: ${{ needs.Check.result }}
steps:
- name: Create Job Summary
run: |
wget -qO asterisk-ci-actions.tar.gz \
https://github.com/${ACTIONS_OWNER}/${ACTIONS_REPO}/archive/refs/heads/${ACTIONS_BRANCH}.tar.gz
tar -xf asterisk-ci-actions.tar.gz --transform="s/^${ACTIONS_REPO}-${ACTIONS_BRANCH}/asterisk-ci-actions/g"
${SCRIPT_DIR}/createJobSummary.sh \
--result=${RESULT} \
--repo=${REPO} \
--workflow-name="${WORKFLOW_NAME}" \
--workflow-run=${WORKFLOW_RUN_ID} \
--tmp-dir=./run-${WORKFLOW_RUN_ID} \
--job-summary-output=job_summary.txt \
--write-step-summary \
--verbose || :
exit 0