Skip to content

Blog - How to Speed Up Your Docker Build with BuildKit Cache #6

Blog - How to Speed Up Your Docker Build with BuildKit Cache

Blog - How to Speed Up Your Docker Build with BuildKit Cache #6

Workflow file for this run

name: Create Top CTAs PR
on:
pull_request_target:
types: [opened, reopened]
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'
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: 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 --dir ./blog/_posts
poetry run python util/psupport/psupport/scripts/topcta.py --dir ./blog/_posts
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
## The idea here it to make a PR onto the existing PR.
## That should be something like `gh pr create --base Earthly-Staging/website:agbell/testpr1 --head earthly/website:automated-changes-12012024`
## But the tool doesn't work that way, so we are doing something simpler.
# See these for clues towards a real solution
# - https://github.com/cli/cli/issues/1985
# - https://github.com/cli/cli/issues/5465
branch_name="automated-changes-$(date +'%d%m%Y')" # re-define branch name since we're in a new step
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="$original_title - CTA change"
echo "Modified title: '$modified_title'"
## Nope, not working
## gh pr create --base ${{ github.event.pull_request.head.ref }} --head $branch_name --title "$modified_title" --body "This PR includes changes for CTA."
# Just create a new pull request against the main branch of the origin repository
gh pr create -R ${{ github.repository }} -B main -H $branch_name --title "$modified_title" --body "This PR includes changes for CTA."
env:
GH_CLI_TOKEN: ${{ secrets.GH_PAT }}