Skip to content
Merged
Show file tree
Hide file tree
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
100 changes: 100 additions & 0 deletions .github/actions/await-workflow/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: "Await Workflow"
description: "Waits until a workflow run completes."

inputs:
run-id:
description: "The id of the workflow run to wait for."
required: true
poll-interval:
description: "The interval (in seconds) to poll for the workflow run status."
required: false
default: "60"
commit-status:
description: "The commit status message. Leave empty to not create a commit status."
required: false

outputs:
succeeded:
description: "Whether the triggered run succeeded."
value: ${{ steps.wait-for-workflow.outputs.RUN_SUCCEEDED }}
conclusion:
description: "The conclusion of the triggered workflow run."
value: ${{ steps.wait-for-workflow.outputs.CONCLUSION }}

runs:
using: composite
steps:
- name: Print Action Input
run: |
echo "[DEBUG] Starting 'Await Workflow' Action; inputs = ${{ toJson(inputs) }}"
shell: bash

- name: View Run
if: ${{ inputs.commit-status != '' }}
id: view-run
env:
GH_TOKEN: ${{ github.token }}
run: |
JSON=$(gh run view ${{ inputs.run-id }} --json url,headSha)
echo "URL=$(echo $JSON | jq -r '.url')" >> $GITHUB_OUTPUT
echo "HEAD_SHA=$(echo $JSON | jq -r '.headSha')" >> $GITHUB_OUTPUT
shell: bash

- name: Create Commit Status
if: ${{ inputs.commit-status != '' }}
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ steps.view-run.outputs.HEAD_SHA }}',
state: 'pending',
target_url: '${{ steps.view-run.outputs.URL }}',
context: '${{ inputs.commit-status }}'
})

- name: Wait for Workflow to Complete
id: wait-for-workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "[DEBUG] Waiting for run '${{ inputs.run-id }}' to complete..."
gh run watch ${{ inputs.run-id }} --interval ${{ inputs.poll-interval }} > /dev/null
CONCLUSION=$(gh run view ${{ inputs.run-id }} --json conclusion | jq -r '.conclusion')

echo "CONCLUSION=$CONCLUSION" >> $GITHUB_OUTPUT
echo "[DEBUG] Run '${{ inputs.run-id }}' finished with conclusion '$CONCLUSION'."

if [[ "$CONCLUSION" != "success" ]]; then
echo "RUN_SUCCEEDED=false" >> $GITHUB_OUTPUT
exit 1
fi

echo "RUN_SUCCEEDED=true" >> $GITHUB_OUTPUT
shell: bash

- name: Determine Final Commit Status
id: determine-final-commit-status
if: ${{ always() && inputs.commit-status != '' }}
run: |
if [[ "${{ steps.wait-for-workflow.outputs.CONCLUSION }}" == "success" ]]; then
echo "FINAL_COMMIT_STATUS=success" >> $GITHUB_OUTPUT
else
echo "FINAL_COMMIT_STATUS=failure" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Update Commit Status
if: ${{ always() && inputs.commit-status != '' }}
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ steps.view-run.outputs.HEAD_SHA }}',
state: '${{ steps.determine-final-commit-status.outputs.FINAL_COMMIT_STATUS }}',
target_url: '${{ steps.view-run.outputs.URL }}',
context: '${{ inputs.commit-status }}'
})
67 changes: 67 additions & 0 deletions .github/actions/trigger-workflow/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "Trigger Workflow"
description: "Triggers a workflow without waiting for it to complete."

inputs:
workflow:
description: "The workflow file name"
required: true
workflow-ref:
description: "The ref (i.e. branch name, or tag name) where the workflow is located."
required: true
parameters:
description: "The workflow parameters"
required: false
commit-sha:
description: "The commit SHA to trigger the workflow on"
required: false
default: ${{ github.sha }}

outputs:
run-id:
description: "The id of the workflow run that was triggered."
value: ${{ steps.trigger-workflow.outputs.RUN_ID }}
run-url:
description: "The url of the workflow run that was triggered."
value: ${{ steps.trigger-workflow.outputs.RUN_URL }}

runs:
using: composite
steps:
- name: Print Action Input
run: |
echo "[DEBUG] Starting 'Trigger Workflow' Action; inputs = ${{ toJson(inputs) }}"
shell: bash

- name: Trigger Workflow
id: trigger-workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
PREVIOUS_RUN_ID=$(gh run list --workflow=${{ inputs.workflow}} --commit=${{ inputs.commit-sha }} --json databaseId | jq -r '.[0].databaseId')
echo "[DEBUG] Previous run id = '$PREVIOUS_RUN_ID'"

gh workflow run "${{ inputs.workflow }}" --ref "${{ inputs.workflow-ref }}" ${{ inputs.parameters }}
# allow for some initial delay as workflows take a moment to spin up
sleep 20

for i in {0..6}; do
LATEST_RUN_ID=$(gh run list --workflow=${{ inputs.workflow }} --commit=${{ inputs.commit-sha }} --json databaseId | jq -r '.[0].databaseId')

if [[ -z "$LATEST_RUN_ID" || "$LATEST_RUN_ID" == "$PREVIOUS_RUN_ID" ]]; then
echo "[DEBUG] No new run detected. Waiting for 10 seconds."
sleep 10
else
echo "[DEBUG] New workflow run detected: '$LATEST_RUN_ID'."

RUN_URL=$(gh run view $LATEST_RUN_ID --json url | jq -r '.url')
echo "[DEBUG] ${{ inputs.workflow }} run #$LATEST_RUN_ID successfully triggered: $RUN_URL"
echo "[${{ inputs.workflow }} run (#$LATEST_RUN_ID)]($RUN_URL)" >> $GITHUB_STEP_SUMMARY
echo "RUN_ID=$LATEST_RUN_ID" >> $GITHUB_OUTPUT
echo "RUN_URL=$RUN_URL" >> $GITHUB_OUTPUT
exit 0
fi
done

echo "[DEBUG] Unable to detect new run of workflow '${{ inputs.workflow }}'."
exit 1
shell: bash
22 changes: 22 additions & 0 deletions .github/workflows/perform-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ on:
env:
MVN_CLI_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version -DskipTests
JAVA_VERSION: 17
DOCS_REPO: SAP/ai-sdk

jobs:
prerequisites:
name: "Prerequisites"
outputs:
code-branch: ${{ steps.determine-branch-names.outputs.CODE_BRANCH_NAME }}
release-notes-branch: ${{ steps.determine-branch-names.outputs.RELEASE_NOTES_BRANCH_NAME }}
release-tag: ${{ steps.determine-branch-names.outputs.RELEASE_TAG }}
release-commit: ${{ steps.determine-branch-names.outputs.RELEASE_COMMIT }}
permissions: write-all # contents and push are needed to see the draft release
Expand All @@ -33,11 +35,13 @@ jobs:
RELEASE_VERSION=$(echo $CODE_BRANCH_NAME | cut -d '-' -f2)
RELEASE_TAG=rel/$RELEASE_VERSION
RELEASE_COMMIT=$(gh release view $RELEASE_TAG --repo ${{github.repository}} --json targetCommitish --jq '.targetCommitish')
RELEASE_NOTES_BRANCH_NAME=java/release-notes-$RELEASE_VERSION

echo "CODE_BRANCH_NAME=$CODE_BRANCH_NAME" >> $GITHUB_OUTPUT
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "RELEASE_COMMIT=$RELEASE_COMMIT" >> $GITHUB_OUTPUT
echo "RELEASE_NOTES_BRANCH_NAME=$RELEASE_NOTES_BRANCH_NAME" >> $GITHUB_OUTPUT

echo -e "[DEBUG] Current GITHUB_OUTPUT:\n$(cat $GITHUB_OUTPUT)"
env:
Expand All @@ -64,6 +68,18 @@ jobs:
workflow: "Continuous Integration"
sha: ${{ steps.determine-branch-names.outputs.RELEASE_COMMIT }}

- name: "Check Whether Release Notes PR Can Be Merged"
if: ${{ inputs.skip-pr-merge != 'true' }}
uses: ./.github/actions/pr-is-mergeable
with:
pr-ref: ${{ steps.determine-branch-names.outputs.RELEASE_NOTES_BRANCH_NAME }}
repo: ${{ env.DOCS_REPO }}
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
excluded-check-runs: |
{
\"Build Cloud SDK Documentation\": [\"dependabot\"]
}

release:
name: "Release"
needs: [ prerequisites ]
Expand Down Expand Up @@ -114,3 +130,9 @@ jobs:
run: gh release edit ${{ needs.prerequisites.outputs.release-tag }} --draft=false --repo "${{ github.repository }}"
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}

- name: "Merge Release Notes PR"
if: ${{ inputs.skip-pr-merge != 'true' }}
run: gh pr merge --squash "${{ needs.prerequisites.outputs.release-notes-branch }}" --delete-branch --repo "${{ env.DOCS_REPO }}"
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
Loading
Loading