-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1810 from cathales/dashboard
ci: notification from Dashboard
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
pr_number: | ||
description: 'ID of the PR to comment' | ||
required: true | ||
type: string | ||
success: | ||
description: 'Is the workflow successful?' | ||
required: true | ||
type: boolean | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
welcome: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const inputs = context.payload.inputs | ||
const pr = inputs.pr_number | ||
const success = inputs.success == 'true' | ||
const status_text = success ? ":heavy_check_mark: successful" : ":x: failed" | ||
const url = `https://riscv-ci.pages.thales-invia.fr/dashboard/dashboard_core-v-verif_${pr}.html` | ||
await github.rest.issues.createComment({ | ||
issue_number: pr, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `${status_text} run, report available [here](${url}).` | ||
}) |
This file contains 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,63 @@ | ||
""" | ||
This module makes it possible to trigger GitHub workflows. | ||
""" | ||
|
||
from os import environ as env | ||
import requests | ||
|
||
def api_url(owner, repo): | ||
"Build API url for a given repository" | ||
return f"https://api.github.com/repos/{owner}/{repo}" | ||
|
||
def pulls(owner, repo): | ||
"Get (public) pull requests from a given repository" | ||
url = api_url(owner, repo) + '/pulls' | ||
headers = {} | ||
if 'GH_TOKEN' in env: | ||
headers["Authorization"] = f"Token {env['GH_TOKEN']}" | ||
response = requests.get(url, headers=headers) | ||
assert response.status_code == 200 | ||
return response.json() | ||
|
||
class Workflow: | ||
"GitHub Workflow that can be triggered on a dispatch event" | ||
def __init__(self, owner, repo, workflow_id, ref): | ||
dispatches = f"/actions/workflows/{workflow_id}/dispatches" | ||
self.url = api_url(owner, repo) + dispatches | ||
self.ref = ref | ||
|
||
def _trigger(self, inputs): | ||
"Trigger the workflow" | ||
data = { | ||
'ref': self.ref, | ||
'inputs': inputs, | ||
} | ||
token = env['GH_TOKEN'] | ||
headers = { | ||
'Accept': 'application/vnd.github+json', | ||
'Authorization': f"Bearer {token}", | ||
'X-GitHub-Api-Version': '2022-11-28', | ||
} | ||
return requests.post(url=self.url, json=data, headers=headers) | ||
|
||
class DashboardDone(Workflow): | ||
"`dashboard-done.yml` GitHub workflow" | ||
def __init__(self, owner, repo, ref): | ||
workflow_id = 'dashboard-done.yml' | ||
Workflow.__init__(self, owner, repo, workflow_id, ref) | ||
|
||
def send(self, pr, success): | ||
"Send success or failure message" | ||
inputs = { | ||
'pr_number': str(pr), | ||
'success': success, | ||
} | ||
return self._trigger(inputs) | ||
|
||
def send_success(self, pr): | ||
"Send message stating that job is successful" | ||
return self.send(pr, True) | ||
|
||
def send_failure(self, pr): | ||
"Send message stating that job is failed" | ||
return self.send(pr, False) |
This file contains 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