Skip to content
Closed
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
62 changes: 62 additions & 0 deletions .github/workflows/docs-generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: docs-generator

on:
# workflow_dispatch:
# inputs:
# pr_number:
# description: 'Number of PR to document'
# required: true
# type: string
push:

jobs:
generate_docs:
runs-on: ubuntu-latest
env:
AMAZON_Q_SIGV4: 1
CHAT_DOWNLOAD_ROLE_ARN: ${{ secrets.CHAT_DOWNLOAD_ROLE_ARN }}
CHAT_BUILD_BUCKET_NAME: ${{ secrets.CHAT_BUILD_BUCKET_NAME }}
PR_FILE: "pr-contents.txt"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_HASH: "latest"
TEST_PR_NUMBER: 2533
permissions:
id-token: write
contents: write
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_TB_ROLE }}
aws-region: us-east-1

- name: Make scripts executable
run: |
chmod +x docs-generation/setup_amazon_q.sh
chmod +x docs-generation/create-docs-pr.sh
chmod +x docs-generation/read-pr.sh
chmod +x docs-generation/update-docs.sh

- name: Run setup script
run: bash docs-generation/setup_amazon_q.sh

- name: Generate PR contents file
run: bash docs-generation/read-pr.sh ${{ env.TEST_PR_NUMBER }}

- name: Update docs
run: bash docs-generation/update-docs.sh

- name: Create PR
if: success()
run: bash docs-generation/create-docs-pr.sh ${{ env.TEST_PR_NUMBER }}






30 changes: 30 additions & 0 deletions docs-generation/create-docs-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

PR_NUMBER=$1
BRANCH_NAME="docs-update-for-pr-$PR_NUMBER"

# Ensure we have changes to merge
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
exit 0
fi

git config user.name "docs-generator[bot]"
git config user.email "docs-generator[bot]@amazon.com"

# Create branch and push
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "Update docs based on PR #$PR_NUMBER

Auto-generated by Q"

git push origin "$BRANCH_NAME"

# Create PR
gh pr create \
--title "Update docs based on PR #$PR_NUMBER" \
--body "Auto-generated documentation updates based on changes in PR #$PR_NUMBER" \
--base main \
--head "$BRANCH_NAME"
29 changes: 29 additions & 0 deletions docs-generation/read-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

PR_NUMBER=$1

# Add PR information
echo "====== PR Information ======\n" > $PR_FILE
gh pr view $PR_NUMBER --json title,body --jq '"Title: " + .title + "\nDescription: " + .body' >> $PR_FILE

# Include updated files
echo -e "\n====== Updated files ======\n" >> $PR_FILE
gh pr view $PR_NUMBER --json files --jq ".files[].path" | while read file; do
case "$file" in
*.lock|*-lock.*|*.min.*|dist/*|build/*|target/*)
continue
;;
esac
if [ -f "$file" ]; then
echo "---- $file ----" >> $PR_FILE
cat "$file" >> $PR_FILE
echo -e "\n" >> $PR_FILE
fi
done






54 changes: 54 additions & 0 deletions docs-generation/setup_amazon_q.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -e
# if git hash empty then set to latest auto
sudo apt-get update
sudo apt-get install -y curl wget unzip jq

# Create AWS credentials from environment variables
mkdir -p ~/.aws
cat > ~/.aws/credentials << EOF
[default]
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
aws_session_token = ${AWS_SESSION_TOKEN}
EOF
chmod 600 ~/.aws/credentials

cat > ~/.aws/config << EOF
[default]
region = us-east-1
EOF
chmod 600 ~/.aws/config

# Assume role and capture temporary credentials --> needed for s3 bucket access for build
echo "Assuming AWS s3 role"
TEMP_CREDENTIALS=$(aws sts assume-role --role-arn ${CHAT_DOWNLOAD_ROLE_ARN} --role-session-name S3AccessSession 2>/dev/null || echo '{}')
QCHAT_ACCESSKEY=$(echo $TEMP_CREDENTIALS | jq -r '.Credentials.AccessKeyId')
Q_SECRET_ACCESS_KEY=$(echo $TEMP_CREDENTIALS | jq -r '.Credentials.SecretAccessKey')
Q_SESSION_TOKEN=$(echo $TEMP_CREDENTIALS | jq -r '.Credentials.SessionToken')

# Download specific build from S3 based on commit hash
echo "Downloading Amazon Q CLI build from S3..."
S3_PREFIX="main/${GIT_HASH}/x86_64-unknown-linux-musl"
echo "Downloading qchat.zip from s3://.../${S3_PREFIX}/qchat.zip"

# Try download, if hash is invalid we fail.
AWS_ACCESS_KEY_ID="$QCHAT_ACCESSKEY" AWS_SECRET_ACCESS_KEY="$Q_SECRET_ACCESS_KEY" AWS_SESSION_TOKEN="$Q_SESSION_TOKEN" \
aws s3 cp s3://${CHAT_BUILD_BUCKET_NAME}/${S3_PREFIX}/qchat.zip ./qchat.zip --region us-east-1

# Handle the zip file, copy the qchat executable to /usr/local/bin + symlink from old code
echo "Extracting qchat.zip..."
unzip -q qchat.zip

# move it to /usr/local/bin/qchat for path as qchat may not work otherwise
if cp qchat /usr/local/bin/ && chmod +x /usr/local/bin/qchat; then
ln -sf /usr/local/bin/qchat /usr/local/bin/q
echo "qchat installed successfully"
else
echo "ERROR: Failed to install qchat"
exit 1
fi

echo "Cleaning q zip"
rm -f qchat.zip
rm -rf qchat
17 changes: 17 additions & 0 deletions docs-generation/update-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

if [ ! -f "$PR_FILE" ]; then
echo "PR file not found, aborting"
exit 1
fi

PROMPT="Before making any changes, read the 'docs' directory for the project's current
documentation. Then read 'pr-contents.txt' to see the contents of the current PR.\n\n
After reading both the directory and the PR file, update the files in the 'docs' directory
with new documentation reflecting the proposed changes in the PR. Make new files as appropriate."

cat pr-contents.txt
echo "Would prompt q chat here"
# timeout 10m echo -e $PROMPT | qchat chat --non-interactive --trust-all-tools
exit $?
Loading