generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add workflow for automatic awscli version upgrade in aws-api-mcp #1435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae462c2
Added version workflow
290b415
Add more debug statements
18691b5
Also upgrade version in pyproject.toml
329f7bc
Cancel if there is no update in version
06c41e5
Only create branch after new version
a3c2525
Change branchname to use version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| --- | ||
| name: AWS API MCP Server - Upgrade AWS CLI Version | ||
| description: | | ||
| This workflow upgrades the AWS CLI version in src/aws-api-mcp-server using uv upgrade | ||
| and creates a pull request with the changes. | ||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: '0 5 * * *' # Daily at 6 AM Amsterdam time (UTC+1) | ||
| env: | ||
| BOT_USER_EMAIL: ${{ vars.BOT_USER_EMAIL || '[email protected]' }} | ||
| BOT_USER_NAME: ${{ vars.BOT_USER_NAME || 'awslabs-mcp' }} | ||
| permissions: | ||
| actions: none | ||
| attestations: none | ||
| checks: none | ||
| contents: none | ||
| deployments: none | ||
| discussions: none | ||
| id-token: none | ||
| issues: none | ||
| models: none | ||
| packages: none | ||
| pages: none | ||
| pull-requests: none | ||
| repository-projects: none | ||
| security-events: none | ||
| statuses: none | ||
| jobs: | ||
| upgrade-awscli: | ||
| name: Upgrade AWS CLI Version | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
| with: | ||
| token: ${{ secrets.BOT_GITHUB_TOKEN }} | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0 | ||
| - name: Check and upgrade AWS CLI version | ||
| id: upgrade | ||
| working-directory: src/aws-api-mcp-server | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| # Get current installed version | ||
| CURRENT_VERSION=$(uv run python -c "from importlib.metadata import version; print(version('awscli'))") | ||
| echo "::debug::Current AWS CLI version: $CURRENT_VERSION" | ||
|
|
||
| # Get latest version from PyPI | ||
| LATEST_VERSION=$(uv run --no-project python -c "import urllib.request, json; print(json.loads(urllib.request.urlopen('https://pypi.org/pypi/awscli/json').read())['info']['version'])") | ||
| echo "::debug::Latest AWS CLI version from PyPI: $LATEST_VERSION" | ||
|
|
||
| # Set version outputs | ||
| echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | ||
| echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| # Compare versions | ||
| if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then | ||
| echo "has-changes=false" >> $GITHUB_OUTPUT | ||
| echo "::notice::AWS CLI is already up to date (version $CURRENT_VERSION)" | ||
| else | ||
| echo "has-changes=true" >> $GITHUB_OUTPUT | ||
| echo "::notice::Upgrading AWS CLI from $CURRENT_VERSION to $LATEST_VERSION" | ||
|
|
||
| # Remove existing awscli dependency | ||
| echo "::debug::Removing existing awscli dependency" | ||
| uv remove awscli | ||
|
|
||
| # Add new version with exact pinning | ||
| echo "::debug::Adding awscli==$LATEST_VERSION" | ||
| uv add "awscli==$LATEST_VERSION" | ||
sten-vw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Sync dependencies | ||
| echo "::debug::Syncing dependencies" | ||
| uv sync | ||
|
|
||
| echo "::debug::AWS CLI upgrade completed" | ||
| fi | ||
| - name: Create upgrade branch | ||
| if: steps.upgrade.outputs.has-changes == 'true' | ||
| id: create-branch | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| LATEST_VERSION="${{ steps.upgrade.outputs.latest-version }}" | ||
| UPGRADE_BRANCH="upgrade/aws-api-mcp-awscli-v$LATEST_VERSION" | ||
|
|
||
| echo "::debug::Creating upgrade branch: $UPGRADE_BRANCH" | ||
|
|
||
| # Configure git user | ||
| git config --local user.email "${{ env.BOT_USER_EMAIL }}" | ||
| git config --local user.name "${{ env.BOT_USER_NAME }}" | ||
|
|
||
| # Create and push branch | ||
| git checkout -b "$UPGRADE_BRANCH" | ||
| git push --set-upstream origin "$UPGRADE_BRANCH" | ||
|
|
||
| # Verify branch was created | ||
| if ! git ls-remote --heads origin "$UPGRADE_BRANCH" | grep -q "$UPGRADE_BRANCH"; then | ||
| echo "::error::Failed to verify branch creation: $UPGRADE_BRANCH" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "upgrade-branch=$UPGRADE_BRANCH" >> $GITHUB_OUTPUT | ||
| echo "::debug::Successfully created upgrade branch: $UPGRADE_BRANCH" | ||
| - name: Configure Git and GPG securely | ||
| if: steps.upgrade.outputs.has-changes == 'true' | ||
| env: | ||
| GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | ||
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | ||
| GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | ||
| run: | | ||
| set -euo pipefail # SECURITY: Strict error handling | ||
|
|
||
| # Create secure temporary directory for GPG | ||
| export GNUPGHOME=$(mktemp -d) | ||
| chmod 700 "$GNUPGHOME" | ||
| echo "GNUPGHOME=$GNUPGHOME" >> $GITHUB_ENV | ||
|
|
||
| echo "::debug::Setting up secure GPG environment" | ||
|
|
||
| # Configure git user | ||
| git config --local user.email "${{ env.BOT_USER_EMAIL }}" | ||
| git config --local user.name "${{ env.BOT_USER_NAME }}" | ||
|
|
||
| # Import GPG key without exposing secrets in command line | ||
| echo "$GPG_PRIVATE_KEY" | gpg --batch --import --quiet | ||
| echo "$GPG_KEY_ID:6:" | gpg --import-ownertrust --quiet | ||
|
|
||
| # Configure git GPG settings | ||
| git config --global user.signingkey "$GPG_KEY_ID" | ||
| git config --global commit.gpgsign true | ||
| git config --global tag.gpgsign true | ||
|
|
||
| # Test GPG functionality | ||
| echo "test" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback \ | ||
| --sign --armor --local-user "$GPG_KEY_ID" <<< "$GPG_PASSPHRASE" > /dev/null | ||
|
|
||
| echo "::debug::GPG configuration completed successfully" | ||
| - name: Commit and push changes | ||
| if: steps.upgrade.outputs.has-changes == 'true' | ||
| env: | ||
| GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | ||
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | ||
| run: | | ||
| set -euo pipefail | ||
| echo "::debug::Committing changes" | ||
|
|
||
| # Add only the source directory | ||
| git add src/aws-api-mcp-server/ | ||
|
|
||
| # Cache GPG signature | ||
| echo "commit" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback \ | ||
| --sign --armor --local-user "$GPG_KEY_ID" <<< "$GPG_PASSPHRASE" > /dev/null | ||
|
|
||
| # Create signed commit | ||
| git commit -m "chore(aws-api-mcp-server): upgrade AWS CLI to v${{ steps.upgrade.outputs.latest-version }}" --sign | ||
|
|
||
| # Pull with rebase to maintain linear history | ||
| git pull --rebase origin "${{ steps.create-branch.outputs.upgrade-branch }}" | ||
|
|
||
| # Push changes | ||
| git push origin "${{ steps.create-branch.outputs.upgrade-branch }}" | ||
|
|
||
| echo "::debug::Successfully committed and pushed changes" | ||
| - name: Create pull request | ||
| if: steps.upgrade.outputs.has-changes == 'true' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| UPGRADE_BRANCH="${{ steps.create-branch.outputs.upgrade-branch }}" | ||
| BASE_BRANCH="${{ github.ref_name }}" | ||
|
|
||
| echo "::debug::Creating PR from $UPGRADE_BRANCH to $BASE_BRANCH" | ||
|
|
||
| # Validate branch names | ||
| if [[ ! "$UPGRADE_BRANCH" =~ ^upgrade/aws-api-mcp-awscli-v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "::error::Invalid upgrade branch format: $UPGRADE_BRANCH" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create PR with validated content | ||
| PR_URL="$(gh pr create \ | ||
| --base "$BASE_BRANCH" \ | ||
| --head "$UPGRADE_BRANCH" \ | ||
| --title "chore(aws-api-mcp-server): upgrade AWS CLI to v${{ steps.upgrade.outputs.latest-version }}" \ | ||
| --body "# AWS CLI Version Upgrade | ||
|
|
||
| This PR upgrades the AWS CLI version in the aws-api-mcp-server package. | ||
|
|
||
| ## Changes | ||
| * Updated AWS CLI from **v${{ steps.upgrade.outputs.current-version }}** to **v${{ steps.upgrade.outputs.latest-version }}** | ||
|
|
||
| ## Checklist | ||
| - [ ] Dependencies have been upgraded | ||
| - [ ] Lock file has been updated | ||
| - [ ] Tests pass with new versions | ||
|
|
||
| ## Acknowledgment | ||
| By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the [project license](https://github.com/awslabs/mcp/blob/main/LICENSE).")" | ||
|
|
||
| echo "::debug::Successfully created pull request $PR_URL" | ||
| echo "### :arrow_up: AWS CLI Upgrade Ready" >> $GITHUB_STEP_SUMMARY | ||
| echo "Pull request $PR_URL created for [$UPGRADE_BRANCH](https://github.com/${{ github.repository }}/tree/$UPGRADE_BRANCH) branch" >> $GITHUB_STEP_SUMMARY | ||
| - name: Secure GPG cleanup | ||
| if: always() | ||
| run: | | ||
| set +e # Don't fail on cleanup errors | ||
| echo "::debug::Performing secure cleanup" | ||
| if [[ -n "${GNUPGHOME:-}" && -d "$GNUPGHOME" ]]; then | ||
| rm -rf "$GNUPGHOME" | ||
| echo "::debug::Cleaned up GPG directory" | ||
| fi | ||
| gpgconf --kill gpg-agent 2>/dev/null || true | ||
| unset GPG_PRIVATE_KEY GPG_PASSPHRASE GPG_KEY_ID GNUPGHOME 2>/dev/null || true | ||
| echo "::debug::Secure cleanup completed" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.