Skip to content

Commit

Permalink
switch to js
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Apr 4, 2024
1 parent 19612f9 commit 50f8f77
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions .github/workflows/status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,49 @@ jobs:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
REPO_NAME: ${{ github.repository }}
ATTEMPTS: ${{ github.event.workflow_run.run_attempt }}
run: |
CONTENT_JSON=$(jq . < downloaded_artifacts/gh-status.json)
JOB_NAME=$(echo "$CONTENT_JSON" | jq -r .job_name)
JOB_ID=$(gh api repos/"$REPO_NAME"/actions/runs/"$WORKFLOW_RUN_ID"/jobs --paginate --jq ".jobs[] | select(.name == \"$JOB_NAME\") | .id")
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)
uses: actions/github-script@v7
with:
script: |
const github = require('@actions/github');
const core = require('@actions/core');
const { context } = github;
# Use default values if any field is missing
if [ -z "$CUSTOM_CONTEXT" ] || [ "$CUSTOM_CONTEXT" = "null" ]; then CUSTOM_CONTEXT="Custom CI Status Check"; fi
if [ -z "$CUSTOM_DESCRIPTION" ] || [ "$CUSTOM_DESCRIPTION" = "null" ]; then CUSTOM_DESCRIPTION="Custom CI Status description"; fi
# Default to Github action summary url page if not defined.
if [ -z "$CUSTOM_TARGET_URL" ] || [ "$CUSTOM_TARGET_URL" = "null" ]; then CUSTOM_TARGET_URL="https://github.com/$REPO_NAME/actions/runs/$WORKFLOW_RUN_ID/attempts/$ATTEMPTS#summary-$JOB_ID"; fi
if [ -z "$CUSTOM_STATE" ] || [ "$CUSTOM_STATE" = "null" ]; then CUSTOM_STATE="success"; fi
const CONTENT_JSON = require('./downloaded_artifacts/gh-status.json');
const JOB_NAME = CONTENT_JSON.job_name;
const CUSTOM_CONTEXT = CONTENT_JSON.context || "Custom CI Status Check";
const CUSTOM_DESCRIPTION = CONTENT_JSON.description || "Custom CI Status description";
const CUSTOM_TARGET_URL = CONTENT_JSON.target_url || `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/attempts/${context.runAttempt}#summary-${context.job}`;
const CUSTOM_STATE = CONTENT_JSON.state || "success";
// Fetch the first job ID from the workflow run
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
# Fetch the first job ID from the workflow run
const job = jobs.data.jobs.find(job => job.name === JOB_NAME);
const JOB_ID = job ? job.id : null;
echo "Job ID: $JOB_ID"
echo "$JOB_NAME"
echo "$CUSTOM_CONTEXT"
echo "$CUSTOM_DESCRIPTION"
echo "$CUSTOM_TARGET_URL"
echo "$CUSTOM_STATE"
echo "$ATTEMPTS"
echo "$JOB_ID"
console.log(`Job ID: ${JOB_ID}`);
console.log(JOB_NAME);
console.log(CUSTOM_CONTEXT);
console.log(CUSTOM_DESCRIPTION);
console.log(CUSTOM_TARGET_URL);
console.log(CUSTOM_STATE);
console.log(context.runAttempt);
console.log(JOB_ID);
# 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\"}"
// Create status
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: CUSTOM_STATE,
target_url: CUSTOM_TARGET_URL,
description: CUSTOM_DESCRIPTION,
context: CUSTOM_CONTEXT,
});
retries: 4

#abc123

0 comments on commit 50f8f77

Please sign in to comment.