Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cicd with new commenting structure #3813

Open
wants to merge 21 commits into
base: v2.x/staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
577ce7c
update cicd with new commenting structure
MarkAckert Apr 26, 2024
7bf71a5
Merge branch 'v2.x/staging' into user/markackert/smarter-pr-comments
MarkAckert May 1, 2024
5ed87a2
remove token from find-comment
MarkAckert May 1, 2024
0e91aa1
hard-code to test root cause
MarkAckert May 1, 2024
f018cea
try changing type of pr number
MarkAckert May 1, 2024
0de2b08
fix formatting
MarkAckert May 1, 2024
956a401
fix BUILD_WHAT
MarkAckert May 1, 2024
2db24f0
change env context
MarkAckert May 1, 2024
d087182
refactor comment formatting
MarkAckert May 1, 2024
424f2ad
string placement
MarkAckert May 1, 2024
b569a9f
use files instead of github_output for comments
MarkAckert May 1, 2024
adaf27d
uncaught syntax errors
MarkAckert May 1, 2024
510ea92
maintain correct trigger behavior
MarkAckert May 1, 2024
c6e396e
always run pr comment after failed test
MarkAckert May 1, 2024
9d99485
add ids to steps so they appear in steps.*
MarkAckert May 2, 2024
fa55e41
Merge branch 'v2.x/staging' into user/markackert/smarter-pr-comments
MarkAckert May 15, 2024
3d065a5
Merge branch 'v2.x/staging' into user/markackert/smarter-pr-comments
MarkAckert Jun 4, 2024
e5a0a1e
Merge branch 'v2.x/staging' into user/markackert/smarter-pr-comments
MarkAckert Jun 13, 2024
a24cd36
remove hardcoded pr number
MarkAckert Jun 13, 2024
85cb107
Merge branch 'v2.x/staging' into user/markackert/smarter-pr-comments
MarkAckert Jun 13, 2024
7b343a3
Merge branch 'v2.x/staging' into user/markackert/smarter-pr-comments
MarkAckert Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 85 additions & 65 deletions .github/workflows/build-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,40 @@ on:
required: false
type: boolean

env:
PR_LABELS:

jobs:

set-run-conditions:
runs-on: ubuntu-latest
outputs:
pr-number: ${{ steps.get-pr-num.outputs.result }}
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 PR Number'
id: get-pr-num
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if ('${{ github.event_name}}' == 'pull_request') {
return ${{ github.event.pull_request.number }}
}
else if ('${{ github.event.inputs.ORIGIN_ISSUE_TRIGGER}}' == 'true') {
const res = await github.rest.pulls.list({
state: 'open',
head: 'zowe:${{ github.ref_name }}',
owner: 'zowe',
repo: 'zowe-install-packaging'
}).then((resp) => {
const pr = resp.data.find((item) => item.head.ref == '${{ github.ref_name }}')
return pr.number
})
return res;
} else {
return ''
}

- name: 'Get labels'
id: get-labels
uses: actions/github-script@v7
Expand Down Expand Up @@ -136,19 +158,11 @@ jobs:
run: |
COMMIT_HASH=$(git rev-parse --verify HEAD)
CURRENT_TIME=$(date +%s)
if [[ -z "${{ github.event.pull_request.number }}" ]]; then
# meaning the workflow is NOT triggered from pull_request
# sometimes user can manually trigger a workflow on a branch that a PR is open,
# thus try to find out if a PR is opened against this running branch
pr_num=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref }} | jq -r '.[] | .number')
if [[ -z "$pr_num" ]]; then
# meaning PR is not open, we collect the branch name
CURRENT_BRANCH=${GITHUB_REF_NAME}
else
CURRENT_BRANCH=PR-$pr_num
fi
if [[ -z "${{ needs.set-run-conditions.outputs.pr-number }}" ]]; then
# meaning PR is not open, we collect the branch name
CURRENT_BRANCH=${GITHUB_REF_NAME}
else
CURRENT_BRANCH=PR-${{ github.event.pull_request.number }}
CURRENT_BRANCH=PR-${{ needs.set-run-conditions.outputs.pr-number }}
fi

sed -e "s#{BUILD_BRANCH}#${CURRENT_BRANCH}#g" \
Expand Down Expand Up @@ -176,7 +190,6 @@ jobs:
}

- name: '[Prep 6a] Process labels for ci build (pull, push, comment)'
id: process-labels
if: github.event_name != 'workflow_dispatch'
run: |
BUILD_WHAT="PAX"
Expand All @@ -199,10 +212,9 @@ jobs:

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
echo BUILD_WHAT=$BUILD_WHAT >> $GITHUB_ENV

- name: '[Prep 6b] Process github.event.inputs for manually triggered build'
id: process-inputs
if: github.event_name == 'workflow_dispatch'
run: |
BUILD_WHAT="${{ steps.process-labels.outputs.BUILD_WHAT_LABELS }}"
Expand Down Expand Up @@ -230,12 +242,12 @@ jobs:

echo INPUTS_KEEP_TEMP_PAX_FOLDER=${{ github.event.inputs.KEEP_TEMP_PAX_FOLDER }} >> $GITHUB_ENV

echo BUILD_WHAT=$BUILD_WHAT >> $GITHUB_OUTPUT
- name: '[Prep 7] Comment on PR to indicate build is started'
echo BUILD_WHAT=$BUILD_WHAT >> $GITHUB_ENV

- name: '[Prep 7a] Create build status comment body'
uses: actions/github-script@v5
id: create-comment
if: (github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request') && startsWith(env.CURRENT_BRANCH, 'PR-')
id: create-comment-body
if: ${{ needs.set-run-conditions.outputs.pr-number != '' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
Expand All @@ -257,15 +269,33 @@ jobs:
const finish_time_UTC = finish_time.toLocaleString('en-GB', { timeZone: 'Europe/London' }).split(', ')[1] + " GMT"
const finish_time_PST = finish_time.toLocaleString('en-US', { timeZone: 'America/Los_Angeles' }).split(', ')[1] + " PST"

const prNum='${{ env.CURRENT_BRANCH }}'.split('-')[1]

const { data: comment } = await github.rest.issues.createComment({
issue_number: prNum,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ steps.process-inputs.outputs.BUILD_WHAT }} build ${context.runNumber} is started, please wait... \n Estimated build time: ${total_bld_time} mins. Check back around: \n ${finish_time_EST} | ${finish_time_CET} | ${finish_time_UTC} | ${finish_time_PST} \n (This comment will get updated once build result is out) \n Link to workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`
});
return comment.id;
const fs = require('fs');
fs.writeFileSync('/tmp/comment.txt', `Build status
${{ env.BUILD_WHAT }} build ${context.runNumber} is started, please wait...
Estimated build time: ${total_bld_time} mins. Check back around:
${finish_time_EST} | ${finish_time_CET} | ${finish_time_UTC} | ${finish_time_PST}
(This comment will get updated once build result is out)
Link to workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`);
return 'OK'

- name: '[Prep 7b] Find Comment'
uses: peter-evans/find-comment@v3
if: ${{ steps.create-comment-body.outputs.result != '' }}
id: fc
with:
issue-number: ${{ needs.set-run-conditions.outputs.pr-number }}
comment-author: 'github-actions[bot]'
body-includes: Build status

- name: '[Prep 7c] Create or update comment'
uses: peter-evans/create-or-update-comment@v4
if: ${{ steps.create-comment-body.outputs.result != '' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: /tmp/comment.txt
edit-mode: replace

- name: '[PAX/SMPE Download 1] Download from jfrog according to manifest'
timeout-minutes: 5
Expand Down Expand Up @@ -393,44 +423,34 @@ jobs:
env:
DEBUG: 'zowe-actions:shared-actions:publish'

- name: '[Post Prep 7] Update PR comment to indicate build succeeded'
- name: '[Post Prep 7] Update PR comment to indicate final build status'
uses: actions/github-script@v5
if: steps.create-comment.outputs.result != '' && success()
if: steps.fc.outputs.comment-id != ''
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.create-comment.outputs.result }},
body: `${{ steps.process-inputs.outputs.BUILD_WHAT }} build ${context.runNumber} SUCCEEDED. \n Link to workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`
});

- name: '[Post Prep 7] Update PR comment to indicate build failed'
uses: actions/github-script@v5
if: steps.create-comment.outputs.result != '' && failure()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.create-comment.outputs.result }},
body: `${{ steps.process-inputs.outputs.BUILD_WHAT }} build ${context.runNumber} FAILED. \n Link to workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`
});

- name: '[Post Prep 7] Update PR comment to indicate build cancelled'
uses: actions/github-script@v5
if: steps.create-comment.outputs.result != '' && cancelled()
let status = "SUCCEEDED";
if (${{ contains(steps.*.outcome, 'failure') }} == true) {
status = "FAILED"
} else if (${{ contains(steps.*.outcome, 'cancelled')}} == true) {
status = "CANCELLED"
}
const fs = require('fs');
fs.writeFileSync('/tmp/comment.txt', `Build status
${{ env.BUILD_WHAT }} build ${context.runNumber} ${status}.
Link to workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`);
return 'OK'


- name: '[Post Prep 7b] Create or update comment'
uses: peter-evans/create-or-update-comment@v4
if: steps.fc.outputs.comment-id != ''
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.create-comment.outputs.result }},
body: `${{ steps.process-inputs.outputs.BUILD_WHAT }} build ${context.runNumber} CANCELLED. \n Link to workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`
});
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: /tmp/comment.txt
edit-mode: replace

# only run auto integration tests when the workflow is triggered by pull request
# default running Convenience Pax on any zzow server
Expand Down
Loading
Loading