Skip to content

Commit 505ad9c

Browse files
authored
Merge pull request #23 from mattalbr/cicd
Rip as much of Strawberry's CI/CD as possible for Sqlalchemy mapper.
2 parents b6cf024 + d81ecbb commit 505ad9c

36 files changed

+2375
-451
lines changed

.alexignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHANGELOG.md
2+
TWEET.md

.alexrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"allow": [
3+
"black",
4+
"hook",
5+
"hooks",
6+
"failure",
7+
"period",
8+
"execute",
9+
"executed",
10+
"executes",
11+
"execution",
12+
"special",
13+
"primitive",
14+
"invalid"
15+
]
16+
}

.codecov.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: yes
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: "70...100"
9+
10+
status:
11+
project: yes
12+
patch: yes
13+
changes: no
14+
15+
comment:
16+
layout: "header, diff"
17+
behavior: default
18+
require_changes: no
19+
20+
ignore:
21+
- "setup.py"

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ARG VARIANT=3.8
2+
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
3+
4+
RUN pip3 install poetry pre-commit
5+
RUN poetry config virtualenvs.in-project true

.devcontainer/devcontainer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "Strawberry Sqlalchemy Mapper",
3+
"context": "..",
4+
"build": {
5+
"dockerfile": "Dockerfile"
6+
},
7+
8+
"settings": {
9+
"terminal.integrated.shell.linux": "/bin/bash",
10+
"python.pythonPath": "/usr/local/bin/python",
11+
"python.linting.enabled": true,
12+
"python.linting.pylintEnabled": true,
13+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
14+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
15+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
16+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
17+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
18+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
19+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
20+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
21+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
22+
},
23+
24+
"extensions": ["ms-python.python", "ms-python.vscode-pylance", "eamodio.gitlens"],
25+
"postCreateCommand": "sh ./.devcontainer/post-install.sh",
26+
}

.devcontainer/post-install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
poetry install
2+
pre-commit install --install-hooks

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.github
3+
.benchmarks
4+
.devcontainer
5+
.venv
6+
.mypy_cache
7+
.nox
8+
.ruff_cache

.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)

0 commit comments

Comments
 (0)