-
Notifications
You must be signed in to change notification settings - Fork 8
103 lines (95 loc) · 4.07 KB
/
add-bottom-ctas.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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/bottomcta.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 - Bottom 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 }}