-
Notifications
You must be signed in to change notification settings - Fork 40
GHAction for PR status check #614
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||||||||
| name: Post Deployment Status Link | ||||||||||||
|
|
||||||||||||
| on: | ||||||||||||
| pull_request_target: | ||||||||||||
| types: [opened, synchronize, reopened] | ||||||||||||
|
|
||||||||||||
| # Without this, GitHub may reject the commit status POST! | ||||||||||||
| permissions: | ||||||||||||
| statuses: write # allow posting commit statuses | ||||||||||||
| contents: read | ||||||||||||
|
|
||||||||||||
| jobs: | ||||||||||||
| post-status: | ||||||||||||
| runs-on: ubuntu-latest | ||||||||||||
|
|
||||||||||||
| steps: | ||||||||||||
| - name: Extract PR commit SHA and branch | ||||||||||||
| run: | | ||||||||||||
| echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV | ||||||||||||
| echo "COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | ||||||||||||
| echo "BRANCH=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV | ||||||||||||
|
|
||||||||||||
| - name: Build Jenkins Deployment URL | ||||||||||||
| shell: bash | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||||||||
| run: | | ||||||||||||
| # Jenkins job users will click to open "Build with Parameters" | ||||||||||||
|
|
||||||||||||
| JOB_NAME="ai-services/job/pr-preview-pipeline" | ||||||||||||
| JENKINS_URL="https://sys-powercloud-team-jenkins.swg-devops.com" | ||||||||||||
|
|
||||||||||||
| # Default ApplicationList value | ||||||||||||
| APP_LIST="rag-dev" | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. That came from my Jenkins configuration testing time. There is no list here. |
||||||||||||
|
|
||||||||||||
| # pass this to downstream pipeline, so that it can update the check status if needed | ||||||||||||
| UPDATE_STATUS=true | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please remove
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||
|
|
||||||||||||
| # Add encoding | ||||||||||||
| PR_Q=$(printf %s "$PR_NUMBER" | jq -sRr @uri) | ||||||||||||
| APP_Q=$(printf %s "$APP_LIST" | jq -sRr @uri) | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we give some different name instead of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||||
|
|
||||||||||||
| # Construct Jenkins Build-with-Parameters URL | ||||||||||||
| DEPLOY_URL="${JENKINS_URL}/job/${JOB_NAME}/parambuild/?CHECKOUT=${PR_Q}&ApplicationList=${APP_Q}&updateGitStatus=${UPDATE_STATUS}" | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was using the control flag outside, just to not hide it in the long URL. But I have no issues going with your suggestion. |
||||||||||||
|
|
||||||||||||
| echo "DEPLOY_URL=${DEPLOY_URL}" >> $GITHUB_ENV | ||||||||||||
| echo "Generated Deployment URL: ${DEPLOY_URL}" | ||||||||||||
|
|
||||||||||||
| - name: Post GitHub Commit Status (Pending) | ||||||||||||
| env: | ||||||||||||
| GH_TOKEN: ${{ github.token }} # built-in GitHub token | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am assuming you want me to remove the comment here. |
||||||||||||
| run: | | ||||||||||||
| echo "Posting pending status to GitHub..." | ||||||||||||
| curl -sS -H "Authorization: Bearer ${GH_TOKEN}" \ | ||||||||||||
| -H "Accept: application/vnd.github+json" \ | ||||||||||||
| -X POST \ | ||||||||||||
| -d "{ | ||||||||||||
| \"state\": \"pending\", | ||||||||||||
| \"target_url\": \"${DEPLOY_URL}\", | ||||||||||||
| \"description\": \"Click to open Jenkins → Build with Parameters\", | ||||||||||||
| \"context\": \"Manual Deployment\" | ||||||||||||
| }" \ | ||||||||||||
| "https://api.github.com/repos/${{ github.repository }}/statuses/${COMMIT_SHA}" | ||||||||||||
| echo "Status posted successfully." | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove Extract PR commit SHA and branch, as we can use env tag to fill values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with using step-level env: block. The only reason I used $GITHUB_ENV so the values are available to other steps without duplication just in case the job grows. That being said, I have deleted this block now and used env: .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also removed the BRANCH variable. It was a left over code from my previous lines. Good catch.