-
-
Notifications
You must be signed in to change notification settings - Fork 62
Bedevere as GH Actions #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
383afcf
Bedevere as GitHub Actions
Mariatta 6f5ecee
Set the python-version
Mariatta 3c8d9a9
Create Dockerfile
Mariatta 6c0af43
use setup actions v3 and Python 3.11
Mariatta dc5bd1d
Update Dockerfile and copy the bedevere directory
Mariatta 1ad09f8
File formatting. Empty line at the end of the file.
Mariatta c8afadd
Typo in Dockerfile
Mariatta 3250100
RUN dir -s
Mariatta d562d69
Copy to GitHub workspace directory
Mariatta e6d77d6
Create entrypoint.sh
Mariatta e9c572e
Entrypoint was in wrong dir
Mariatta 7d0c3a7
Typo in entrypoint filename
Mariatta ae8aaab
Make entrypoint executable
Mariatta 494aba6
Copy bedevere to GitHub workspace
Mariatta 5cf8707
Copy bedevere folder
Mariatta 17e9c42
Copy bedevere folder
Mariatta cde6ac1
debug 400 error
Mariatta 4e267ef
debug gh token
Mariatta 4b385c8
Set the GH Token env var
Mariatta d9d8c6c
Revert changes
Mariatta 484ece3
Remove debug prints
Mariatta db8e6cb
Remove Procfile
Mariatta 3f9ea88
Remove runtime.txt. It was for Heroku.
Mariatta 784a19c
Set exit code if bedevere errors out.
Mariatta 9dac39a
Debugging
Mariatta 424509d
Debugging
Mariatta 6fa714a
Debugging
Mariatta 9d1a990
Use repo_full_name when retrieving Git Hash
Mariatta f59a006
Fix tests
Mariatta 05b6aa1
Remove prints
Mariatta 4834a6f
Debug post status
Mariatta 8ec31af
Debug post status
Mariatta 67849cf
Debug post status
Mariatta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: Bedevere | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - synchronize | ||
| - reopened | ||
| - edited | ||
| - labeled | ||
| - unlabeled | ||
| - review_requested | ||
| - ready_for_review | ||
| - converted_to_draft | ||
| - closed | ||
| create: | ||
| types: | ||
| - branch | ||
| pull_request_review: | ||
| types: | ||
| - submitted | ||
| - dismissed | ||
| issue_comment: | ||
| types: | ||
| - created | ||
| push: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: [ "3.11" ] | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v3 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install -r requirements.txt | ||
| - name: execute bedevere | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| python -m bedevere | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM python:3.11-slim | ||
|
|
||
| COPY requirements.txt requirements.txt | ||
| COPY dev-requirements.txt dev-requirements.txt | ||
|
Mariatta marked this conversation as resolved.
|
||
|
|
||
|
|
||
| COPY entrypoint.sh /entrypoint.sh | ||
| COPY bedevere/ /bedevere/ | ||
|
|
||
| RUN pip install --no-cache-dir -U pip | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| ENTRYPOINT ["/entrypoint.sh"] | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| name: bedevere-action | ||
| description: Bedevere GitHub Actions | ||
|
|
||
| branding: | ||
| color: blue | ||
| icon: activity | ||
| runs: | ||
| using: docker | ||
| image: Dockerfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import asyncio | ||
| import importlib | ||
|
|
||
| import os | ||
| import sys | ||
| import traceback | ||
|
|
@@ -10,27 +10,30 @@ | |
| from gidgethub import aiohttp as gh_aiohttp | ||
| from gidgethub import routing | ||
| from gidgethub import sansio | ||
| from gidgethub import actions | ||
|
|
||
| from . import backport, gh_issue, close_pr, filepaths, news, stage | ||
|
|
||
| import sentry_sdk | ||
| # import sentry_sdk | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we still use sentry in GitHub Actions? Is it needed? If not we can remove it from requirements.txt |
||
|
|
||
| router = routing.Router(backport.router, gh_issue.router, close_pr.router, | ||
| filepaths.router, news.router, | ||
| stage.router) | ||
| cache = cachetools.LRUCache(maxsize=500) | ||
|
|
||
| sentry_sdk.init(os.environ.get("SENTRY_DSN")) | ||
| # sentry_sdk.init(os.environ.get("SENTRY_DSN")) | ||
|
|
||
| async def main(request): | ||
| async def main(event_payload): | ||
| try: | ||
| body = await request.read() | ||
| secret = os.environ.get("GH_SECRET") | ||
| event = sansio.Event.from_http(request.headers, body, secret=secret) | ||
| event_name = os.environ["GITHUB_EVENT_NAME"] | ||
| job_id = os.environ["GITHUB_JOB"] | ||
| event = sansio.Event(event_payload, event=event_name, delivery_id=job_id) | ||
| print(f"{event.data=}") | ||
| print(f"{event_payload}") | ||
| print(f"{event_name=}") | ||
| print('GH delivery ID', event.delivery_id, file=sys.stderr) | ||
| if event.event == "ping": | ||
| return web.Response(status=200) | ||
| oauth_token = os.environ.get("GH_AUTH") | ||
|
|
||
| oauth_token = os.environ.get("GITHUB_TOKEN") | ||
| async with aiohttp.ClientSession() as session: | ||
| gh = gh_aiohttp.GitHubAPI(session, "python/bedevere", | ||
| oauth_token=oauth_token, | ||
|
|
@@ -42,16 +45,14 @@ async def main(request): | |
| print('GH requests remaining:', gh.rate_limit.remaining) | ||
| except AttributeError: | ||
| pass | ||
| return web.Response(status=200) | ||
|
|
||
| except Exception as exc: | ||
| traceback.print_exc(file=sys.stderr) | ||
| return web.Response(status=500) | ||
|
|
||
| sys.exit(1) | ||
|
|
||
| if __name__ == "__main__": # pragma: no cover | ||
| app = web.Application() | ||
| app.router.add_post("/", main) | ||
| port = os.environ.get("PORT") | ||
| if port is not None: | ||
| port = int(port) | ||
| web.run_app(app, port=port) | ||
| if os.environ.get("GITHUB_EVENT_PATH"): | ||
| event_from = actions.event() | ||
| asyncio.run(main(event_from)) | ||
| else: | ||
| print(f"Environment Variable 'GITHUB_EVENT_PATH' not found.") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/sh -l | ||
|
|
||
| cp -r /bedevere ./bedevere | ||
|
|
||
| python -m bedevere |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import os | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def tmp_event_name(request, monkeypatch): | ||
| monkeypatch.setenv("GITHUB_EVENT_NAME", request.param) | ||
|
|
||
| @pytest.fixture | ||
| def tmp_job_id(monkeypatch): | ||
| monkeypatch.setenv("GITHUB_JOB", "12345") | ||
|
|
||
| @pytest.fixture | ||
| def tmp_webhook(tmp_path, monkeypatch): | ||
| """Create a temporary file for an actions webhook event.""" | ||
| tmp_file_path = tmp_path / "event.json" | ||
| monkeypatch.setenv("GITHUB_EVENT_PATH", os.fspath(tmp_file_path)) | ||
| return tmp_file_path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,25 @@ | ||
| from aiohttp import web | ||
| import pytest | ||
|
|
||
| from bedevere import __main__ as main | ||
|
|
||
| from tests.fixtures import tmp_webhook, tmp_event_name, tmp_job_id | ||
|
|
||
| async def test_ping(aiohttp_client): | ||
| app = web.Application() | ||
| app.router.add_post("/", main.main) | ||
| client = await aiohttp_client(app) | ||
| headers = {"x-github-event": "ping", | ||
| "x-github-delivery": "1234"} | ||
| data = {"zen": "testing is good"} | ||
| response = await client.post("/", headers=headers, json=data) | ||
| assert response.status == 200 | ||
|
|
||
| @pytest.mark.parametrize('tmp_event_name', ["created"], indirect=True) | ||
| async def test_success(tmp_webhook, tmp_event_name, tmp_job_id, monkeypatch): | ||
| from bedevere import __main__ as main | ||
|
|
||
| async def test_success(aiohttp_client): | ||
| app = web.Application() | ||
| app.router.add_post("/", main.main) | ||
| client = await aiohttp_client(app) | ||
| headers = {"x-github-event": "project", | ||
| "x-github-delivery": "1234"} | ||
| # Sending a payload that shouldn't trigger any networking, but no errors | ||
| # either. | ||
| data = {"action": "created"} | ||
| response = await client.post("/", headers=headers, json=data) | ||
| assert response.status == 200 | ||
|
|
||
|
|
||
| async def test_failure(aiohttp_client): | ||
| """Even in the face of an exception, the server should not crash.""" | ||
| app = web.Application() | ||
| app.router.add_post("/", main.main) | ||
| client = await aiohttp_client(app) | ||
| # Missing key headers. | ||
| response = await client.post("/", headers={}) | ||
| assert response.status == 500 | ||
| event_payload = {"action": "created"} | ||
| await main.main(event_payload) | ||
|
|
||
|
|
||
| async def test_failure(tmp_webhook): | ||
| from bedevere import __main__ as main | ||
| """Actions will have exit code in case of errors.""" | ||
|
|
||
| # Missing GitHub environment variables | ||
| event_payload = {} | ||
| with pytest.raises(SystemExit) as exc: | ||
| await main.main(event_payload) | ||
| assert exc.value.code == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.