From f762b49eb985fd335125b1120a8fd130b0618a97 Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Wed, 3 Apr 2024 15:34:39 +0000 Subject: [PATCH] test --- .github/workflows/status.yml | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/status.yml diff --git a/.github/workflows/status.yml b/.github/workflows/status.yml new file mode 100644 index 00000000000..2994394a4d7 --- /dev/null +++ b/.github/workflows/status.yml @@ -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\"}"