mirror of
https://github.com/ansible/awx.git
synced 2026-10-31 06:26:15 -02:30
fix: update openapi sync workflow to eda (#16588)
In particular, this brings two important changes: - rather than opening a new PR every time it runs, it uses a stable branch name updating its content instead; this means that at most there is one open PR per target branch - a new secret "OPENAPI_SPEC_PR_REVIEW_TEAM" is introduced to specify the name of the github team to notify when creating new PRs; this helps to make sure that PRs are reviewed
This commit is contained in:
@@ -112,18 +112,16 @@ jobs:
|
|||||||
cp "./schema.json" "spec-repo/controller.json"
|
cp "./schema.json" "spec-repo/controller.json"
|
||||||
echo "✅ Updated spec-repo/controller.json"
|
echo "✅ Updated spec-repo/controller.json"
|
||||||
|
|
||||||
- name: Create PR in spec repo
|
- name: Create or update PR in spec repo
|
||||||
if: steps.compare.outputs.has_diff == 'true'
|
if: steps.compare.outputs.has_diff == 'true'
|
||||||
working-directory: spec-repo
|
working-directory: spec-repo
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.OPENAPI_SPEC_SYNC_TOKEN }}
|
GH_TOKEN: ${{ secrets.OPENAPI_SPEC_SYNC_TOKEN }}
|
||||||
GPG_PRIVATE_KEY: ${{ secrets.OPENAPI_SPEC_SYNC_GPG_PRIVATE_KEY }}
|
GPG_PRIVATE_KEY: ${{ secrets.OPENAPI_SPEC_SYNC_GPG_PRIVATE_KEY }}
|
||||||
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
|
||||||
SPEC_REPO: ansible-automation-platform/aap-openapi-specs
|
SPEC_REPO: ansible-automation-platform/aap-openapi-specs
|
||||||
REF_NAME: ${{ github.ref_name }}
|
SPEC_PR_REVIEW_TEAM: ${{ secrets.OPENAPI_SPEC_PR_REVIEW_TEAM }}
|
||||||
GITHUB_SHA_FULL: ${{ github.sha }}
|
SPEC_BRANCH: ${{ github.ref_name }}
|
||||||
GITHUB_REPO: ${{ github.repository }}
|
SOURCE_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
||||||
IS_NEW_FILE: ${{ steps.compare.outputs.is_new_file }}
|
|
||||||
run: |
|
run: |
|
||||||
# Import GPG key and configure git for signed commits
|
# Import GPG key and configure git for signed commits
|
||||||
echo "$GPG_PRIVATE_KEY" | gpg --batch --import 2>/dev/null
|
echo "$GPG_PRIVATE_KEY" | gpg --batch --import 2>/dev/null
|
||||||
@@ -140,59 +138,88 @@ jobs:
|
|||||||
# Configure git to use the token for push
|
# Configure git to use the token for push
|
||||||
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${SPEC_REPO}.git"
|
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${SPEC_REPO}.git"
|
||||||
|
|
||||||
SHORT_SHA="${GITHUB_SHA_FULL:0:7}"
|
# Use a stable branch name so we can reuse it across runs
|
||||||
BRANCH_NAME="update-Controller-${REF_NAME}-${SHORT_SHA}"
|
BRANCH_NAME="auto/update-controller-${SPEC_BRANCH}"
|
||||||
|
|
||||||
|
# Check if there's already an open PR from this branch
|
||||||
|
EXISTING_PR=$(gh pr list \
|
||||||
|
--repo "$SPEC_REPO" \
|
||||||
|
--head "$BRANCH_NAME" \
|
||||||
|
--base "$SPEC_BRANCH" \
|
||||||
|
--state open \
|
||||||
|
--json number \
|
||||||
|
--jq '.[0].number // empty')
|
||||||
|
|
||||||
|
if [ -n "$EXISTING_PR" ]; then
|
||||||
|
echo "📝 Found existing PR #${EXISTING_PR} - will update it"
|
||||||
|
else
|
||||||
|
echo "📝 No existing PR found - will create a new one"
|
||||||
|
# Clean up stale remote branch from a previously merged PR
|
||||||
|
git push origin --delete "$BRANCH_NAME" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
git checkout -b "$BRANCH_NAME"
|
git checkout -b "$BRANCH_NAME"
|
||||||
|
|
||||||
# Add and commit changes
|
# Add and commit changes
|
||||||
git add "controller.json"
|
git add "controller.json"
|
||||||
|
|
||||||
if [ "${IS_NEW_FILE}" == "true" ]; then
|
if [ "${{ steps.compare.outputs.is_new_file }}" == "true" ]; then
|
||||||
COMMIT_MSG="Add Controller OpenAPI spec for ${REF_NAME}"
|
COMMIT_MSG="Add Controller OpenAPI spec for ${SPEC_BRANCH}"
|
||||||
else
|
else
|
||||||
COMMIT_MSG="Update Controller OpenAPI spec for ${REF_NAME}"
|
COMMIT_MSG="Update Controller OpenAPI spec for ${SPEC_BRANCH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git commit -m "${COMMIT_MSG}
|
git commit -m "$COMMIT_MSG
|
||||||
|
|
||||||
Synced from ${GITHUB_REPO}@${GITHUB_SHA_FULL}
|
Synced from ${{ github.repository }}@${{ github.sha }}
|
||||||
Source branch: ${REF_NAME}
|
Source branch: ${SPEC_BRANCH}
|
||||||
|
Spec repo branch: ${SPEC_BRANCH}
|
||||||
|
|
||||||
Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
|
Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
|
||||||
|
|
||||||
# Push branch
|
# Push branch
|
||||||
git push origin "$BRANCH_NAME"
|
git push --force origin "$BRANCH_NAME"
|
||||||
|
|
||||||
# Create PR
|
# Create PR (commit message passed via env var to avoid script injection)
|
||||||
PR_TITLE="[${REF_NAME}] Update Controller spec from merged commit"
|
PR_TITLE="[${SPEC_BRANCH}] Update Controller spec from merged commit"
|
||||||
PR_BODY="## Summary
|
PR_BODY=$(cat <<EOF
|
||||||
|
## Summary
|
||||||
Automated OpenAPI spec sync from component repository merge.
|
Automated OpenAPI spec sync from component repository merge.
|
||||||
|
|
||||||
**Source:** ${GITHUB_REPO}@${GITHUB_SHA_FULL}
|
**Source:** ${{ github.repository }}@${{ github.sha }}
|
||||||
**Branch:** \`${REF_NAME}\`
|
**Source Branch:** \`${SPEC_BRANCH}\`
|
||||||
|
**Spec Repo Branch:** \`${SPEC_BRANCH}\`
|
||||||
**Component:** \`Controller\`
|
**Component:** \`Controller\`
|
||||||
**Spec File:** \`controller.json\`
|
**Spec File:** \`controller.json\`
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
$(if [ "${IS_NEW_FILE}" == "true" ]; then echo "- 🆕 New spec file created"; else echo "- 📝 Spec file updated with latest changes"; fi)
|
$(if [ "${{ steps.compare.outputs.is_new_file }}" == "true" ]; then echo "- 🆕 New spec file created"; else echo "- 📝 Spec file updated with latest changes"; fi)
|
||||||
|
|
||||||
## Source Commit
|
## Source Commit
|
||||||
\`\`\`
|
\`\`\`
|
||||||
${COMMIT_MESSAGE}
|
${SOURCE_COMMIT_MESSAGE}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
---
|
---
|
||||||
🤖 This PR was automatically generated by the OpenAPI spec sync workflow."
|
🤖 This PR was automatically generated by the OpenAPI spec sync workflow.
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ -n "$EXISTING_PR" ]; then
|
||||||
|
gh pr edit "$EXISTING_PR" \
|
||||||
|
--repo "$SPEC_REPO" \
|
||||||
|
--body "$PR_BODY"
|
||||||
|
echo "✅ Updated existing PR #${EXISTING_PR}"
|
||||||
|
else
|
||||||
gh pr create \
|
gh pr create \
|
||||||
--repo "${SPEC_REPO}" \
|
--repo "$SPEC_REPO" \
|
||||||
--title "$PR_TITLE" \
|
--title "$PR_TITLE" \
|
||||||
--body "$PR_BODY" \
|
--body "$PR_BODY" \
|
||||||
--base "${REF_NAME}" \
|
--base "$SPEC_BRANCH" \
|
||||||
--head "$BRANCH_NAME"
|
--head "$BRANCH_NAME" \
|
||||||
|
--reviewer "$SPEC_PR_REVIEW_TEAM"
|
||||||
echo "✅ Created PR in spec repo"
|
echo "✅ Created PR in spec repo"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Report results
|
- name: Report results
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
Reference in New Issue
Block a user