This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run Newman Tests (Self-Hosted with Direct Access - Testnet) | |
| on: | |
| repository_dispatch: | |
| types: [run-tests] | |
| jobs: | |
| run-tests: | |
| runs-on: self-hosted | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/[email protected] | |
| with: | |
| persist-credentials: true | |
| - name: Update Last Processed Upstream Run ID | |
| run: | | |
| NEW_RUN_ID="${{ github.event.client_payload.run_id }}" | |
| TARGET_FILE=".last_upstream_run_id.txt" | |
| echo "$NEW_RUN_ID" > "$TARGET_FILE" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git stash push -u -m "workflow_stash_for_run_id_update" || echo "No local changes to stash, or stash command failed." | |
| git pull --rebase | |
| if git rev-parse -q --verify refs/stash >/dev/null; then | |
| if ! git stash pop; then | |
| echo "Warning: 'git stash pop' failed. Will attempt to force update $TARGET_FILE and proceed." | |
| echo "$NEW_RUN_ID" > "$TARGET_FILE" # Ensure our file content is prioritized | |
| # Note: Other conflicts from the stash pop might remain. | |
| # The script will try to `git add $TARGET_FILE` and commit. | |
| # If other unmerged paths exist from the failed pop, the commit might fail. | |
| # This simplified handling prioritizes the TARGET_FILE update. | |
| git stash drop || echo "Warning: Failed to drop stash after a failed pop attempt." | |
| fi | |
| fi | |
| # Ensure the target file has the correct content and is staged. | |
| # This covers successful pop, failed pop (where we overwrote), or no stash. | |
| echo "$NEW_RUN_ID" > "$TARGET_FILE" | |
| git add "$TARGET_FILE" | |
| # Commit if there are changes. If $TARGET_FILE was unchanged and no other changes, this will do nothing. | |
| git commit -m "[skip ci] Update last processed upstream run id to $NEW_RUN_ID" || echo "No changes to commit for last run ID, or commit failed." | |
| git push | |
| - name: Run Newman Tests (Ultra-Simple Execution) | |
| id: newman | |
| run: | | |
| newman run postman/collection.json \ | |
| -e postman/environment.testnet.json | |
| continue-on-error: true | |
| - name: Upload Test Results (JUnit XML) | |
| if: always() | |
| uses: actions/[email protected] | |
| with: | |
| name: postman-test-results | |
| path: results.xml | |
| if-no-files-found: warn | |
| - name: Upload HTML Report (Nice UI) | |
| if: always() | |
| uses: actions/[email protected] | |
| with: | |
| name: postman-html-report | |
| path: newman-report.html | |
| if-no-files-found: warn | |
| - name: Notify Slack Channel and Handle Overall Job Failure | |
| if: always() | |
| env: | |
| NEWMAN_CONCLUSION: ${{ steps.newman.conclusion }} | |
| JOB_CONTEXT_STATUS: ${{ job.status }} | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| run: | | |
| TITLE_TEXT="Newman Test Run (Testnet on Self-Hosted - No VPN)" | |
| MARK_JOB_AS_FAILED_FLAG=false | |
| ICON=":test_tube:" | |
| COLOR="warning" | |
| FINAL_MESSAGE="" | |
| if [ "$NEWMAN_CONCLUSION" == "success" ]; then | |
| FINAL_MESSAGE="All Newman tests passed successfully!" | |
| ICON=":white_check_mark:" | |
| COLOR="good" | |
| elif [ "$NEWMAN_CONCLUSION" == "failure" ]; then | |
| FINAL_MESSAGE="Newman tests encountered failures." | |
| ICON=":warning:" | |
| COLOR="danger" | |
| MARK_JOB_AS_FAILED_FLAG=true | |
| elif [ "$NEWMAN_CONCLUSION" == "skipped" ]; then | |
| FINAL_MESSAGE="Newman step was skipped." | |
| ICON=":zzz:" | |
| COLOR="neutral" | |
| else # cancelled, unknown status | |
| FINAL_MESSAGE="Newman step status: $NEWMAN_CONCLUSION." | |
| ICON=":grey_question:" | |
| COLOR="neutral" | |
| MARK_JOB_AS_FAILED_FLAG=true # Treat cancelled or unknown as a failure for the job | |
| fi | |
| if [ "$JOB_CONTEXT_STATUS" == "failure" ]; then | |
| PREFIX_FOR_PRIOR_FAILURE="A prior required step in the job failed. " | |
| FINAL_MESSAGE="${PREFIX_FOR_PRIOR_FAILURE}${FINAL_MESSAGE}" | |
| ICON=":x:" # Override icon to definite failure | |
| COLOR="danger" # Override color to definite failure | |
| MARK_JOB_AS_FAILED_FLAG=true # Ensure job is marked for failure | |
| fi | |
| TEXT_MESSAGE="$FINAL_MESSAGE Workflow: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }} Run #${{ github.run_number }}>" | |
| # Check if SLACK_WEBHOOK_URL is set | |
| if [ -z "$SLACK_WEBHOOK_URL" ]; then | |
| echo "SLACK_WEBHOOK_URL is not set. Skipping Slack notification." | |
| else | |
| PAYLOAD=$(jq -n \ | |
| --arg channel "indexer-api-testing" \ | |
| --arg username "GitHub Actions" \ | |
| --arg icon_emoji "$ICON" \ | |
| --arg color "$COLOR" \ | |
| --arg title "$TITLE_TEXT" \ | |
| --arg text "$TEXT_MESSAGE" \ | |
| '{channel: $channel, username: $username, icon_emoji: $icon_emoji, attachments: [{color: $color, title: $title, text: $text}]}') | |
| echo "Sending Slack notification..." | |
| curl -X POST -H "Content-type: application/json" --data "$PAYLOAD" "$SLACK_WEBHOOK_URL" | |
| fi | |
| if [ "$MARK_JOB_AS_FAILED_FLAG" = true ]; then | |
| echo "Final determination: Marking job as FAILED based on step outcomes." | |
| exit 1 | |
| else | |
| echo "Final determination: Job considered SUCCESSFUL by this script's logic." | |
| fi |