Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Apr 3, 2024
1 parent 8a9f078 commit f762b49
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Process Workflow Artifacts and Update Status

on:
workflow_run:
workflows: ["Echo abc"]
types:
- completed

jobs:
process_artifacts:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: gh-status
path: downloaded_artifacts/

- name: Read artifact JSON
id: read_artifact
run: |
CONTENT=$(cat downloaded_artifacts/gh-status.json)
echo "::set-output name=content::$CONTENT"
- name: Create status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_CONTENT: ${{ steps.read_artifact.outputs.content }}
run: |
CONTENT_JSON=$(echo $ARTIFACT_CONTENT | jq .)
CUSTOM_CONTEXT=$(echo $CONTENT_JSON | jq -r .context)
CUSTOM_DESCRIPTION=$(echo $CONTENT_JSON | jq -r .description)
CUSTOM_TARGET_URL=$(echo $CONTENT_JSON | jq -r .target_url)
CUSTOM_STATE=$(echo $CONTENT_JSON | jq -r .state)
COMMIT_SHA="${{ github.event.workflow_run.head_sha }}"
WORKFLOW_RUN_ID="${{ github.event.workflow_run.id }}"
REPO_NAME="${{ github.repository }}"
DEFAULT_TARGET_URL="https://github.com/$REPO_NAME/actions/runs/$WORKFLOW_RUN_ID"
# Use default values if any field is missing
if [ -z "$CUSTOM_CONTEXT" ]; then CUSTOM_CONTEXT="Custom CI Status Check"; fi
if [ -z "$CUSTOM_DESCRIPTION" ]; then CUSTOM_DESCRIPTION="Custom CI Status description"; fi
if [ -z "$CUSTOM_TARGET_URL" ]; then CUSTOM_TARGET_URL=$DEFAULT_TARGET_URL; fi
if [ -z "$CUSTOM_STATE" ]; then CUSTOM_STATE="success"; fi
# Create status
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO_NAME/statuses/$COMMIT_SHA" \
-d "{\"state\":\"$CUSTOM_STATE\",\"target_url\":\"$CUSTOM_TARGET_URL\",\"description\":\"$CUSTOM_DESCRIPTION\",\"context\":\"$CUSTOM_CONTEXT\"}"

0 comments on commit f762b49

Please sign in to comment.