Skip to content

Commit ba9c7bf

Browse files
committed
Bring bot back and fix some tweet stuff.
1 parent 78b59e5 commit ba9c7bf

File tree

5 files changed

+78
-68
lines changed

5 files changed

+78
-68
lines changed

.codecov.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ comment:
1818
require_changes: no
1919

2020
ignore:
21-
- "strawberry/ext/mypy_plugin.py"
2221
- "setup.py"
23-
- "strawberry/experimental/pydantic/conversion_types.py"

.github/bot-action/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.9-alpine
2+
3+
RUN pip install httpx==0.18.2
4+
5+
6+
COPY . /action
7+
8+
ENTRYPOINT ["python", "/action/main.py"]

.github/bot-action/action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Strawberry Bot Action'
2+
inputs:
3+
pr_number:
4+
required: true
5+
status:
6+
required: true
7+
change_type:
8+
required: true
9+
changelog_base64:
10+
required: true
11+
tweet:
12+
required: false
13+
release_card_url:
14+
required: false
15+
runs:
16+
using: 'docker'
17+
image: 'Dockerfile'

.github/bot-action/main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# TODO: improve this to support multiple commands
2+
import base64
3+
import os
4+
5+
import httpx
6+
7+
API_URL = os.environ["BOT_API_URL"]
8+
API_TOKEN = os.environ["API_SECRET"]
9+
10+
11+
mutation = """mutation AddReleaseComment($input: AddReleaseFileCommentInput!) {
12+
addReleaseFileComment(input: $input)
13+
}"""
14+
15+
16+
release_info = None
17+
18+
if os.environ["INPUT_STATUS"] == "OK":
19+
changelog = base64.b64decode(os.environ["INPUT_CHANGELOG_BASE64"]).decode("utf-8")
20+
21+
release_info = {
22+
"changeType": os.environ["INPUT_CHANGE_TYPE"],
23+
"changelog": changelog,
24+
}
25+
26+
if tweet := os.environ.get("INPUT_TWEET"):
27+
tweet = base64.b64decode(tweet).decode("utf-8")
28+
29+
30+
mutation_input = {
31+
"prNumber": int(os.environ["INPUT_PR_NUMBER"]),
32+
"status": os.environ["INPUT_STATUS"],
33+
"releaseCardUrl": os.environ.get("INPUT_RELEASE_CARD_URL"),
34+
"tweet": tweet,
35+
"releaseInfo": release_info,
36+
}
37+
38+
response = httpx.post(
39+
API_URL,
40+
json={"query": mutation, "variables": {"input": mutation_input}},
41+
headers={"Authorization": f"Bearer {API_TOKEN}"},
42+
timeout=120,
43+
)
44+
response.raise_for_status()
45+
46+
response_data = response.json()
47+
48+
if "errors" in response_data:
49+
raise RuntimeError(f"Response contained errors: {response_data['errors']}")
50+
51+
print(response_data)

.github/workflows/release-check.yml

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches:
77
- main
88
paths:
9-
- "strawberry/**"
9+
- "src/strawberry_sqlalchemy_mapper/**"
1010
- "pyproject.toml"
1111

1212
jobs:
@@ -75,71 +75,9 @@ jobs:
7575
id: release-check
7676
if: github.event.pull_request.draft == false
7777

78-
79-
read-tweet-md:
80-
name: Read TWEET.md
81-
runs-on: ubuntu-latest
82-
needs: [get-contributor-info, release-file-check]
83-
84-
outputs:
85-
tweet: ${{ steps.extract.outputs.tweet }}
86-
card-text: ${{ steps.extract.outputs.card-text }}
87-
88-
steps:
89-
- uses: actions/checkout@v2
90-
with:
91-
ref: "refs/pull/${{ github.event.number }}/merge"
92-
- name: Extract tweet message and changelog
93-
id: extract
94-
uses: strawberry-graphql/tweet-actions/read-tweet@v4
95-
with:
96-
changelog: ${{ needs.release-file-check.outputs.changelog }}
97-
version: "(next)"
98-
contributor_name: ${{ needs.get-contributor-info.outputs.contributor-name }}
99-
contributor_twitter_username: ${{ needs.get-contributor-info.outputs.contributor-twitter-username }}
100-
101-
validate-tweet:
102-
runs-on: ubuntu-latest
103-
needs: read-tweet-md
104-
if: ${{ needs.read-tweet-md.outputs.tweet != '' }}
105-
steps:
106-
- name: Validate tweet
107-
uses: strawberry-graphql/tweet-actions/validate-tweet@v4
108-
with:
109-
tweet: ${{ needs.read-tweet-md.outputs.tweet }}
110-
111-
generate-preview:
112-
runs-on: ubuntu-latest
113-
needs: [release-file-check, read-tweet-md, get-contributor-info]
114-
if: github.event.pull_request.draft == false
115-
116-
outputs:
117-
url: ${{ steps.upload.outputs.url }}
118-
119-
steps:
120-
- name: Generate Twitter card preview
121-
uses: strawberry-graphql/release-cards@main
122-
if: ${{ needs.release-file-check.outputs.status == 'OK' }}
123-
with:
124-
version: "(next)"
125-
contributor: ${{ needs.get-contributor-info.outputs.contributor-name }}
126-
description_base64: ${{ needs.read-tweet-md.outputs.card-text }}
127-
128-
- name: Uploads preview
129-
id: upload
130-
if: ${{ needs.release-file-check.outputs.status == 'OK' }}
131-
run: |
132-
echo ::set-output name=url::$(curl --location --request POST "https://api.imgur.com/3/image" \
133-
--fail \
134-
--header "Authorization: Client-ID $IMGUR_CLIENT_ID" \
135-
--form "[email protected];filename=screenshot.png;type=image/png" \
136-
| jq --raw-output '.data.link')
137-
env:
138-
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
139-
14078
send-comment:
14179
runs-on: ubuntu-latest
142-
needs: [release-file-check, generate-preview, read-tweet-md]
80+
needs: [release-file-check]
14381
if: github.event.pull_request.draft == false
14482

14583
steps:
@@ -154,8 +92,6 @@ jobs:
15492
status: ${{ needs.release-file-check.outputs.status }}
15593
change_type: ${{ needs.release-file-check.outputs.change_type }}
15694
changelog_base64: ${{ needs.release-file-check.outputs.changelog }}
157-
release_card_url: ${{ needs.generate-preview.outputs.url }}
158-
tweet: ${{ needs.read-tweet-md.outputs.tweet }}
15995

16096
fail-if-status-is-not-ok:
16197
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)