Skip to content

ucacher blog post

ucacher blog post #100

Workflow file for this run

name: Create Top CTAs PR
on:
pull_request_target:
types: [opened, reopened]
paths:
- 'blog/_posts/*.md'
workflow_dispatch:
jobs:
create-pr:
runs-on: ubuntu-latest
if: >
(github.event.pull_request.head.repo.owner.login == 'earthly' ||
github.event.pull_request.head.repo.owner.login == 'Earthly-Staging') &&
!contains(github.event.pull_request.title, '[AUTO-PR]')
steps:
- name: Check Required Secrets
run: |
if [ -z "${{ secrets.OPENAI_API_KEY }}" ]; then
echo "Error: OPENAI_API_KEY is not set."
exit 1
fi
if [ -z "${{ secrets.ANTHROPIC_API_KEY }}" ]; then
echo "Error: ANTHROPIC_API_KEY is not set."
exit 1
fi
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Checkout PR
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 1
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Find and set first Markdown file changed
run: |
git fetch --unshallow origin main
MD_FILE=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' | head -n 1)
echo "First markdown file changed: $MD_FILE"
echo "MD_FILE=$MD_FILE" >> $GITHUB_ENV
- name: Set up GitHub CLI
run: |
curl -sSL https://github.com/cli/cli/releases/download/v2.0.0/gh_2.0.0_linux_amd64.tar.gz -o ghcli.tar.gz
tar xzf ghcli.tar.gz
sudo mv gh_*/bin/gh /usr/local/bin/
rm -rf gh_2.0.0_linux_amd64/ ghcli.tar.gz
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11' # This will get the latest version of Python 3
- name: Create a new branch
run: |
git config user.name 'GitHub Actions Bot'
git config user.email '[email protected]'
branch_name="automated-changes-$(date +'%d%m%Y')" # create a branch name based on the current day/month/year
git checkout -b $branch_name
- name: Dependencies
run: |
set -x
curl -sSL https://install.python-poetry.org | python3 -
poetry install --no-root
- name: Run Code
run: |
set -x
poetry run python util/psupport/psupport/scripts/excerpt.py --file $MD_FILE
poetry run python util/psupport/psupport/scripts/topcta.py --file $MD_FILE
git restore ./blog/_posts/2029-01-01-checklist.md
npm install -g [email protected]
markdownlint --fix "./blog/_posts/*.md" || true
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Check for changes
id: changes
run: |
git diff --exit-code || echo "::set-output name=has_changes::true"
- name: Commit changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git add -A
git commit -m "Automated code changes"
- name: Push changes and create PR
if: steps.changes.outputs.has_changes == 'true'
run: |
set -x
branch_name="automated-changes-$(date +'%Y-%m-%d-%H%M%S')"
git push --force --set-upstream origin HEAD:$branch_name
gh auth login --with-token <<< "${{ secrets.GH_PAT }}"
original_title=$(gh pr view ${{ github.event.pull_request.number }} --json title --jq .title)
echo "Original title: '$original_title'"
modified_title="[AUTO-PR] $original_title - CTA change"
echo "Modified title: '$modified_title'"
gh pr create -R "${{ github.event.pull_request.head.repo.full_name }}" --base "${{ github.event.pull_request.head.ref }}" --title "$modified_title" --body "This PR includes changes for CTA." >> $GITHUB_STEP_SUMMARY
env:
GH_CLI_TOKEN: ${{ secrets.GH_PAT }}