Refactor for pull_request_target #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PRChanged | |
run-name: "${{ github.workflow }}-${{ github.event.label.name }}-${{ github.event.number }}" | |
on: | |
workflow_call: | |
inputs: | |
actions_ref: | |
description: 'JSON object reference to the actions: { "owner": "asterisk", "repo": "asterisk-ci-actions", "branch": "main" }' | |
type: string | |
required: false | |
default: '{ "owner": "asterisk", "repo": "asterisk-ci-actions", "branch": "main" }' | |
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 | |
BUILD_CACHE_KEY: ${{ github.workflow }}-${{ github.run_number }}-${{ github.event.number }}-${{ github.event.pull_request.base.ref }} | |
ACTIONS_OWNER: asterisk | |
ACTIONS_REPO: asterisk-ci-actions | |
ACTIONS_BRANCH: main | |
TESTING_IN_PROGRESS: ${{ vars.PR_SUBMIT_TESTING_IN_PROGRESS }} | |
TESTS_PASSED: ${{ vars.PR_SUBMIT_TESTS_PASSED }} | |
TESTS_FAILED: ${{ vars.PR_SUBMIT_TESTS_FAILED }} | |
jobs: | |
Setup: | |
runs-on: ubuntu-latest | |
outputs: | |
testsuite_test_pr: ${{ steps.setup.outputs.TESTSUITE_TEST_PR }} | |
normalized_branch: ${{ steps.setup.outputs.NORMALIZED_BRANCH }} | |
steps: | |
- name: DumpEnvironment | |
run: | | |
echo "::group::vars_context" | |
cat <<%%EOF%% | sed -r -e "/(TOKEN|token|ghs_)/d" | tee ${OUTPUT_DIR}/env_context.json | |
${{toJSON(vars)}} | |
%%EOF%% | |
echo "::endgroup::" | |
echo "::group::env_context" | |
cat <<%%EOF%% | sed -r -e "/(TOKEN|token|ghs_)/d" | tee ${OUTPUT_DIR}/env_context.json | |
${{toJSON(env)}} | |
%%EOF%% | |
echo "::endgroup::" | |
echo "::group::github_context" | |
cat <<%%EOF%% | sed -r -e "/(TOKEN|token|ghs_)/d" | tee ${OUTPUT_DIR}/github_context.json | |
${{toJSON(github)}} | |
%%EOF%% | |
echo "::endgroup::" | |
echo "::group::shell_env" | |
printenv | sort | sed -r -e "/(TOKEN|token|ghs_)/d" | tee ${OUTPUT_DIR}/shell_env.env | |
echo "::endgroup::" | |
if [ -n "${GITHUB_ACTION_PATH}" ] ; then | |
echo "::group::GITHUB_ACTION_PATH: ${GITHUB_ACTION_PATH}" | |
echo "${GITHUB_ACTION_PATH}" > ${OUTPUT_DIR}/GITHUB_ACTION_PATH.txt | |
ls -al ${GITHUB_ACTION_PATH} | tee -a ${OUTPUT_DIR}/GITHUB_ACTION_PATH.txt | |
echo "::endgroup::" | |
fi | |
uses: asterisk/asterisk-ci-actions/DumpEnvironmentAction@main | |
- id: setup | |
env: | |
PR_STATE_CHANGE_DELAY_SEC: ${{ vars.PR_STATE_CHANGE_DELAY_SEC || 120 }} | |
TESTSUITE_TEST_PR_REGEX: ${{ vars.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}" | |
gh cache delete -R ${REPO} ${BUILD_CACHE_KEY} &> /dev/null || : | |
# | |
gh pr edit --repo ${REPO} \ | |
--remove-label ${TESTS_PASSED} \ | |
--remove-label ${TESTS_FAILED} \ | |
--add-label ${TESTING_IN_PROGRESS} \ | |
$PR_NUMBER || : | |
Check: | |
name: Check | |
needs: Setup | |
permissions: | |
actions: read | |
checks: read | |
contents: read | |
issues: read | |
pull-requests: read | |
statuses: read | |
uses: ./.github/workflows/AsteriskUnitGateTest.yml | |
with: | |
test_type: prstatechange | |
asterisk_repo: ${{ github.repository }} | |
pr_number: ${{ github.event.number }} | |
base_branch: ${{ github.event.pull_request.base.ref }} | |
is_cherry_pick: false | |
build_options: ${{ vars.BUILD_OPTIONS }} | |
unittest_command: ${{ vars.UNITTEST_COMMAND }} | |
testsuite_repo: ${{ vars.TESTSUITE_REPO }} | |
testsuite_test_pr: ${{ needs.Setup.outputs.testsuite_test_pr }} | |
gatetest_list: ${{ vars.GATETEST_LIST }} | |
gatetest_commands: ${{ vars.GATETEST_COMMANDS }} | |
PostWorkflow: | |
if: ${{ success() || failure() || cancelled() }} | |
runs-on: ubuntu-latest | |
needs: [Setup,Check] | |
env: | |
RESULT: ${{ needs.Check.result }} | |
CHERRY_PICK_REGEX: ${{ vars.CHERRY_PICK_REGEX }} | |
CHERRY_PICK_REMINDER: ${{ vars.CHERRY_PICK_REMINDER }} | |
SQUASH_COMMITS_REMINDER: ${{ vars.SQUASH_COMMITS_REMINDER }} | |
USER_NOTE_REMINDER: ${{ vars.USER_NOTE_REMINDER }} | |
UPGRADE_NOTE_REMINDER: ${{ vars.UPGRADE_NOTE_REMINDER }} | |
steps: | |
- name: Add labels, reminders and summary | |
run: | | |
label="" | |
case $RESULT in | |
success) | |
label=$TESTS_PASSED | |
gh cache delete -R ${REPO} ${BUILD_CACHE_KEY} || : | |
;; | |
failure) | |
label=$TESTS_FAILED | |
;; | |
cancelled) | |
gh cache delete -R ${REPO} ${BUILD_CACHE_KEY} || : | |
;; | |
skipped) | |
;; | |
*) | |
;; | |
esac | |
gh pr edit --repo ${REPO} \ | |
--remove-label ${TESTING_IN_PROGRESS} \ | |
${label:+--add-label $label} \ | |
$PR_NUMBER || : | |
if [[ $RESULT =~ (success|failure) ]] ; then | |
${SCRIPT_DIR}/addCherryPickReminderIfNeeded.sh \ | |
--repo=${REPO} \ | |
--pr-number=${PR_NUMBER} \ | |
--cherry-pick-regex="${CHERRY_PICK_REGEX}" \ | |
--cherry-pick-reminder="${CHERRY_PICK_REMINDER}" | |
${SCRIPT_DIR}/createJobSummary.sh \ | |
--result=${RESULT} \ | |
--repo=${REPO} \ | |
--workflow-name="${WORKFLOW_NAME}" \ | |
--pr-number=${PR_NUMBER} \ | |
--workflow-run=${WORKFLOW_RUN_ID} \ | |
--tmp-dir=./run-${WORKFLOW_RUN_ID} \ | |
--job-summary-output=job_summary.txt \ | |
--add-pr-comment \ | |
--verbose || : | |
fi | |
exit 0 |