Skip to content
Merged
Changes from all commits
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
50 changes: 49 additions & 1 deletion .github/workflows/spec-update.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "Spec File Update Workflow"
run-name: "Spec File Update Workflow: ${{ github.event.inputs.file }}-${{ github.event.inputs.file-ref }}"

on:
workflow_dispatch:
Expand Down Expand Up @@ -140,13 +141,50 @@ jobs:

gh api $API_URL -H "Accept: application/vnd.github.raw" > $FILE_PATH

- name: "Exit if there are no changes"
- name: "Exit if there are no spec changes"
id: spec_diff
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
run: |
# if there are no spec changes in this commit, check if previous run on this branch is red. If it is red, exit 1; if it is green, exit 0.
if [[ `git status --porcelain` ]]; then
echo "Spec changes detected, continuing with generation."
echo "spec_diff=true" >> "$GITHUB_OUTPUT"
else
echo "No spec changes detected. Checking status of previous run."
echo "spec_diff=false" >> "$GITHUB_OUTPUT"

# The current run of this workflow
CURRENT_RUN=${{ github.run_id }}

# name must match the workflow run-name pattern above
RUN_NAME="Spec File Update Workflow: $CHOICE-$REF"
echo "Run name used for search: $RUN_NAME"

# Get the most recent completed run of this workflow with respect to the same feature branch
PREVIOUS_RUN=$(gh run list \
--workflow "${{ github.workflow }}" \
--branch main \
--json databaseId,status,conclusion,displayTitle \
--jq "map(select(.databaseId != ${CURRENT_RUN} and (.displayTitle | contains(\"${RUN_NAME}\")))) | .[0]")

echo "Previous run: $PREVIOUS_RUN"

if [ -n "$PREVIOUS_RUN" ] && [ "$PREVIOUS_RUN" != "null" ]; then
CONCLUSION=$(echo "$PREVIOUS_RUN" | jq -r '.conclusion')
echo "Previous run conclusion: $CONCLUSION"

if [ "$CONCLUSION" = "failure" ]; then
echo "Previous run failed and there were no spec changes since, thus failing this run as well."
echo "prev_run_success=false" >> "$GITHUB_OUTPUT"
else
echo "Previous run succeeded and there were no spec changes since, thus the current run succeeds as well."
echo "prev_run_success=true" >> "$GITHUB_OUTPUT"
fi
else
echo "There was no previous run, thus the current run succeeds."
echo "prev_run_success=true" >> "$GITHUB_OUTPUT"
fi
fi

- name: "Generate"
Expand Down Expand Up @@ -235,6 +273,10 @@ jobs:
echo "| File Download | ${{ steps.download.outcome == 'success' && '✅' || '❌' }} ${{ steps.download.outcome }}" >> $GITHUB_STEP_SUMMARY
echo "| Spec File Changes | ${{ steps.spec_diff.outputs.spec_diff == 'true' && '🔄 Changes Detected' || '⏹️ No Changes' }}" >> $GITHUB_STEP_SUMMARY

if ${{ steps.spec_diff.outputs.spec_diff == 'false' }}; then
echo "| Outcome Previous Run | ${{ steps.spec_diff.outputs.prev_run_success == 'true' && '✅ (Current run succeeds as a result.)' || '❌ (Current run fails as a result.)' }}" >> $GITHUB_STEP_SUMMARY
fi

if ${{ steps.spec_diff.outputs.spec_diff == 'true' }}; then
echo "| Client Generation | ${{ steps.generate.outputs.generation_result == 'success' && '✅' || '❌' }} ${{ steps.generate.outputs.generation_result }}" >> $GITHUB_STEP_SUMMARY
echo "| Client Compilation | ${{ steps.compile.outputs.compilation_result == 'success' && '✅' || '❌' }} ${{ steps.compile.outputs.compilation_result }}" >> $GITHUB_STEP_SUMMARY
Expand All @@ -249,6 +291,12 @@ jobs:
echo "Client generation failed. Please check the Generate step logs for details."
exit 1

- name: "Fail if no spec changes and previous run failed"
if: steps.spec_diff.outputs.prev_run_success == 'false'
run: |
echo "Previous run failed and there were no spec changes since, thus failing this run as well."
exit 1

- name: "Slack Notification"
if: failure() && github.event.inputs.create-pr == 'true'
uses: slackapi/slack-github-action@v2.1.1
Expand Down