Skip to content
Open
Changes from 1 commit
Commits
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
62 changes: 62 additions & 0 deletions .github/workflows/pr-deployment-status.yml
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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Author

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: .

Copy link
Copy Markdown
Author

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.

- name: Build Jenkins Deployment URL
shell: bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shell: bash
shell: bash
env:
PR_NUMBER: {{ github.event.pull_request.number }}
COMMIT_SHA: {{ github.event.pull_request.head.sha }}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
APP_LIST="rag-dev"
DEFAULT_APPLICATION="rag-dev"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.
Done


# pass this to downstream pipeline, so that it can update the check status if needed
UPDATE_STATUS=true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please remove UPDATE_STATUS var

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give some different name instead of PR_Q and APP_Q

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEPLOY_URL="${JENKINS_URL}/job/${JOB_NAME}/parambuild/?CHECKOUT=${PR_Q}&ApplicationList=${APP_Q}&updateGitStatus=${UPDATE_STATUS}"
DEPLOY_URL="${JENKINS_URL}/job/${JOB_NAME}/parambuild/?CHECKOUT=${PR_Q}&ApplicationList=${APP_Q}&updateGitStatus=true"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.
Updated the code 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GH_TOKEN: ${{ github.token }} # built-in GitHub token
GH_TOKEN: ${{ github.token }}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming you want me to remove the comment here.
Done.

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."