Skip to content

Commit

Permalink
Merge pull request #3772 from zowe/user/markackert/ci-label-behavior-…
Browse files Browse the repository at this point in the history
…updates

Updates to `/ci` behavior
  • Loading branch information
MarkAckert authored Apr 16, 2024
2 parents 2235990 + fceb36e commit 1b3f629
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 36 deletions.
114 changes: 78 additions & 36 deletions .github/workflows/build-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ on:
- v2.x/staging
pull_request:
types: [opened, synchronize]
issue_comment:
types: [created, edited]

workflow_dispatch:
inputs:
Expand All @@ -32,6 +30,16 @@ on:
required: false
default: false
type: boolean
PSWI_SMPE_ARTIFACTORY_PATH:
description: 'Optional. Artifactory path to a pre-built SMP/e artifact.'
required: false
default: ''
type: string
PSWI_SMPE_AZWE_ARTIFACTORY_PATH:
description: 'Optional. Artifactory path to a pre-built pre-built AZWE FMID.'
required: false
default: ''
type: string
KEEP_TEMP_PAX_FOLDER:
description: 'do we need to keep temp pax folder?'
required: false
Expand All @@ -41,39 +49,57 @@ on:
description: 'random dispatch event id'
required: false
type: string
ORIGIN_ISSUE_TRIGGER:
description: 'is being triggered from PR issue comment'
default: false
required: false
type: boolean

jobs:

pr-comment-check:
env:
PR_LABELS:

name: 'PR Comment Check'
runs-on: ubuntu-latest
outputs:
issue_run_ci: ${{ steps.check-comment.outputs.issue_run_ci }}
steps:
- name: Check for a comment triggering a build
id: check-comment
run: |
echo "issue_run_ci=false" >> $GITHUB_OUTPUT
if [[ ! -z "${{ github.event.issue.pull_request }}" && ${{ github.event_name == 'issue_comment' }} && "${{ github.event.comment.body }}" = '/ci' ]]; then
echo "issue_run_ci=true" >> $GITHUB_OUTPUT
fi
jobs:

set-run-conditions:
runs-on: ubuntu-latest
needs: pr-comment-check
outputs:
pr-labels: ${{ steps.get-labels.outputs.result }}
should-build: ${{ steps.check-build.outputs.run_build }}
should-test: ${{ steps.check-test.outputs.run_test}}
steps:
- name: 'Get labels'
id: get-labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if ('${{ github.event_name}}' == 'pull_request') {
return JSON.stringify(${{ toJson(github.event.pull_request.labels) }})
}
else if ('${{ github.event.inputs.ORIGIN_ISSUE_TRIGGER}}' == 'true') {
github.rest.pulls.list({
state: 'open',
head: 'zowe:${{ env.GITHUB_HEAD_REF }}',
owner: 'zowe',
repo: 'zowe-install-packaging'
}).then((resp) => {
const pr = resp.data.find((item) => item.head.ref == 'user/markackert/ci-label-behavior-updates')
return JSON.stringify(pr.labels)
})
} else {
return '[]'
}
- id: check-build
name: 'export conditional used to determine if we should run a build'
# run_build explanation: workflow_dispatch can be manual, '/ci' comment trigger, or nightly.
# If this is a workflow_disaptch and not a '/ci' trigger, always run, ignoring PR labels. Otherwise, always check the label.
run: |
echo "run_build=${{ (github.event_name != 'issue_comment' || needs.pr-comment-check.outputs.issue_run_ci == 'true') && (github.event_name == 'workflow_dispatch' || !contains(github.event.pull_request.labels.*.name, 'Build: None')) }}" >> $GITHUB_OUTPUT
echo "run_build=${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.ORIGIN_ISSUE_TRIGGER == 'false') || !contains(fromJson(steps.get-labels.outputs.result), 'Build: None') }}" >> $GITHUB_OUTPUT
- id: check-test
name: 'export conditional used to determine if we should run a test suite'
run: |
echo "run_test=${{ ( github.event_name == 'push' && contains(github.ref, 'staging') ) || ( (github.event_name == 'pull_request' || github.event_name == 'issue_comment') && !contains(github.event.pull_request.labels.*.name, 'Build: None') && !contains(github.event.pull_request.labels.*.name, 'Test: None') ) }}" >> $GITHUB_OUTPUT
echo "run_test=${{ (steps.check-build.outputs.run_build == 'true' && !contains(fromJson(steps.get-labels.outputs.result), 'Test: None')) }}" >> $GITHUB_OUTPUT
display-dispatch-event-id:
if: github.event.inputs.RANDOM_DISPATCH_EVENT_ID != ''
Expand All @@ -99,9 +125,7 @@ jobs:
steps:
- name: '[Prep 1] Checkout'
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || '' }}


- name: '[Prep 2] Setup jFrog CLI'
uses: jfrog/setup-jfrog-cli@v2
env:
Expand Down Expand Up @@ -156,23 +180,23 @@ jobs:
run: |
BUILD_WHAT="PAX"
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'Build: PSWI') }}" == "true" ]]; then
if [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Build: PSWI') }}" == "true" ]]; then
echo INPUTS_BUILD_PSWI=true >> $GITHUB_ENV
echo INPUTS_BUILD_SMPE=true >> $GITHUB_ENV
BUILD_WHAT=$BUILD_WHAT", SMPE, PSWI"
else
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'Build: SMPE') }}" == "true" ]]; then
if [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Build: SMPE') }}" == "true" ]]; then
echo INPUTS_BUILD_SMPE=true >> $GITHUB_ENV
BUILD_WHAT=$BUILD_WHAT", SMPE"
fi
fi
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'Build: Kubernetes') }}" == "true" ]]; then
if [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Build: Kubernetes') }}" == "true" ]]; then
echo INPUTS_BUILD_KUBERNETES=true >> $GITHUB_ENV
BUILD_WHAT=$BUILD_WHAT", K8S"
fi
echo "INPUTS_KEEP_TEMP_PAX_FOLDER=${{ contains(github.event.pull_request.labels.*.name, 'Build: Debug-Remote') }}" >> $GITHUB_ENV
echo "INPUTS_KEEP_TEMP_PAX_FOLDER=${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Build: Debug-Remote') }}" >> $GITHUB_ENV
echo BUILD_WHAT=$BUILD_WHAT >> $GITHUB_OUTPUT
Expand All @@ -184,8 +208,13 @@ jobs:
echo INPUTS_BUILD_PSWI=${{ github.event.inputs.BUILD_PSWI }} >> $GITHUB_ENV
if [[ "${{ github.event.inputs.BUILD_PSWI }}" == true ]]; then
echo INPUTS_BUILD_SMPE=true >> $GITHUB_ENV
BUILD_WHAT=$BUILD_WHAT", SMPE, PSWI"
if [[ "${{ github.event.inputs.PSWI_SMPE_ARTIFACTORY_PATH }}" == "" ]]; then
echo INPUTS_BUILD_SMPE=true >> $GITHUB_ENV
BUILD_WHAT=$BUILD_WHAT", SMPE, PSWI"
else
echo INPUTS_BUILD_SMPE=false >> $GITHUB_ENV
BUILD_WHAT="PSWI"
fi
else
echo INPUTS_BUILD_SMPE=${{ github.event.inputs.BUILD_SMPE }} >> $GITHUB_ENV
if [[ "${{ github.event.inputs.BUILD_SMPE }}" == true ]]; then
Expand Down Expand Up @@ -266,8 +295,13 @@ jobs:
id: pax-prep
run: |
if [ "${{ env.INPUTS_BUILD_SMPE }}" == "true" ] || [ "${{ env.INPUTS_BUILD_PSWI }}" == "true" ] ; then
echo EXTRA_FILES=zowe-smpe.zip,fmid.zip,pd.htm,smpe-promote.tar,smpe-build-logs.pax.Z,rename-back.sh >> $GITHUB_OUTPUT
echo BUILD_SMPE=yes >> $GITHUB_OUTPUT
if [[ "${{ github.event.inputs.PSWI_SMPE_ARTIFACTORY_PATH }}" == "" || "${{github.event.inputs.PSWI_SMPE_AZWE_ARTIFACTORY_PATH}}" == "" ]]; then
echo EXTRA_FILES=zowe-smpe.zip,fmid.zip,pd.htm,smpe-promote.tar,smpe-build-logs.pax.Z,rename-back.sh >> $GITHUB_OUTPUT
echo BUILD_SMPE=yes >> $GITHUB_OUTPUT
else
echo EXTRA_FILES= >> $GITHUB_OUTPUT
echo BUILD_SMPE= >> $GITHUB_OUTPUT
fi
else
echo EXTRA_FILES= >> $GITHUB_OUTPUT
echo BUILD_SMPE= >> $GITHUB_OUTPUT
Expand All @@ -281,6 +315,7 @@ jobs:
- name: '[PAX/SMPE Pax 2] Packaging'
timeout-minutes: 60
if: env.INPUTS_BUILD_PSWI != 'true' || (env.INPUTS_BUILD_PSWI == 'true' && github.event.inputs.PSWI_SMPE_ARTIFACTORY_PATH == '' && github.event.inputs.PSWI_SMPE_AZWE_ARTIFACTORY_PATH == '')
uses: zowe-actions/shared-actions/make-pax@main
with:
pax-name: zowe
Expand All @@ -295,7 +330,7 @@ jobs:
KEEP_TEMP_FOLDER=${{ steps.pax-prep.outputs.KEEP_TEMP_FOLDER }}
- name: '[SMPE Pax 3] Post-make pax'
if: env.INPUTS_BUILD_SMPE == 'true' || env.INPUTS_BUILD_PSWI == 'true'
if: env.INPUTS_BUILD_SMPE == 'true' || (env.INPUTS_BUILD_PSWI == 'true' && github.event.inputs.PSWI_SMPE_ARTIFACTORY_PATH == '' && github.event.inputs.PSWI_SMPE_AZWE_ARTIFACTORY_PATH == '')
run: |
cd .pax
chmod +x rename-back.sh
Expand All @@ -311,6 +346,13 @@ jobs:
lock-resource-name: zowe-psi-build-zzow07-lock
lock-avg-retry-interval: 60

- name: '[PSWI 0] PSWI pre-build check for existing smpe'
if: env.INPUTS_BUILD_PSWI == 'true' && github.event.inputs.PSWI_SMPE_ARTIFACTORY_PATH != '' && github.event.inputs.PSWI_SMPE_AZWE_ARTIFACTORY_PATH != ''
run: |
jfrog rt dl ${{github.event.inputs.PSWI_SMPE_AZWE_ARTIFACTORY_PATH}}/AZWE002*.zip --flat=true .pax/AZWE002.zip
jfrog rt dl ${{github.event.inputs.PSWI_SMPE_ARTIFACTORY_PATH}}/zowe-smpe-*.zip --flat=true .pax/zowe-smpe.zip
- name: '[SMPE Pax 4] Build PSWI'
if: env.INPUTS_BUILD_PSWI == 'true'
timeout-minutes: 60
Expand Down Expand Up @@ -410,13 +452,13 @@ jobs:
id: get-test-suite
run: |
TEST_SUITE="Convenience Pax"
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'Test: Basic') }}" = "true" ]]; then
if [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Test: Basic') }}" = "true" ]]; then
TEST_SUITE="Convenience Pax"
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'Test: SMPE') }}" = "true" ]]; then
elif [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Test: SMPE') }}" = "true" ]]; then
TEST_SUITE="SMPE PTF"
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'Test: Extended') }}" = "true" ]]; then
elif [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Test: Extended') }}" = "true" ]]; then
TEST_SUITE="Zowe Nightly Tests"
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'Test: Silly') }}" = "true" ]]; then
elif [[ "${{ contains(fromJson(needs.set-run-conditions.outputs.pr-labels), 'Test: Silly') }}" = "true" ]]; then
TEST_SUITE="Zowe Release Tests"
else
echo "Unknown test label encountered; defaulting to 'Test: Basic' and running Convenience Pax tests."
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/cicd-comment-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Triggers when comments are made on issues/PRs, runs when '/ci' is added to a pull request.
name: Zowe CICD Issue Trigger

permissions:
issues: write
pull-requests: write
contents: write


on:
issue_comment:
types: [created, edited]

jobs:

pr-comment-check:

name: 'PR Comment Check'
runs-on: ubuntu-latest
outputs:
issue_run_ci: ${{ steps.check-comment.outputs.issue_run_ci }}
steps:
- name: Check for a comment triggering a build
id: check-comment
run: |
echo "issue_run_ci=false" >> $GITHUB_OUTPUT
if [[ ! -z "${{ github.event.issue.pull_request }}" && ${{ github.event_name == 'issue_comment' }} && "${{ github.event.comment.body }}" = '/ci' ]]; then
echo "issue_run_ci=true" >> $GITHUB_OUTPUT
fi
get-pr-branch:
name: 'Get PR Branch'
runs-on: ubuntu-latest
outputs:
pr_branch_name:
steps:
- name: Find PR Branch Name
run: |
gh config set pager cat
PR_BRANCH=$(gh pr view ${{ github.event.issue.pull_request }} -R zowe/zowe-install-packaging --json headRefName -q .headRefName)
echo "pr_branch_name=$PR_BRANCH" >> $GITHUB_OUTPUT
trigger-ci:
name: 'Trigger Build'
runs-on: ubuntu-latest
needs: [pr-comment-check, get-pr-branch]
if: ${{ needs.pr-comment-check.outputs.issue_run_ci == 'true' }}
steps:
- name: 'Trigger Build workflow'
uses: zowe-actions/shared-actions/workflow-remote-call-wait@main
with:
github-token: ${{ secrets.ZOWE_ROBOT_TOKEN }}
owner: zowe
repo: zowe-install-packaging
workflow-filename: build-packaging.yml
branch-name: ${{ needs.get-pr-branch.outputs.pr_branch_name }}
poll-frequency: 3
inputs-json-string: '{"ORIGIN_ISSUE_TRIGGER":"true", "KEEP_TEMP_PAX_FOLDER":"false"}'
env:
DEBUG: zowe-actions:shared-actions:workflow-remote-call-wait

0 comments on commit 1b3f629

Please sign in to comment.