-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from DevsOnTheBoard/feature/workflow/BuildFini…
…shNotify Feature/workflow/build finish notify
- Loading branch information
Showing
3 changed files
with
68 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,2 @@ | ||
python-dotenv==0.20.0 | ||
requests==2.28.0 |
35 changes: 35 additions & 0 deletions
35
.github/send_download_artifact_url/send-download-artifact-page-url.py
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,35 @@ | ||
import os | ||
import requests | ||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
headers = { | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": os.getenv("GITHUB_TOKEN"), | ||
} | ||
|
||
res = requests.get(f" https://api.github.com/repos/{os.getenv('GITHUB_REPOSITORY')}/actions/artifacts", | ||
headers=headers).json() | ||
|
||
|
||
def get_download_url(content): | ||
for artifact in content["artifacts"]: | ||
if artifact["name"] == "Build": | ||
run_id = artifact["workflow_run"]["id"] | ||
url = f"https://github.com/{os.getenv('GITHUB_REPOSITORY')}/actions/runs/{run_id}" | ||
return url | ||
return None | ||
|
||
|
||
def message(url): | ||
content = { | ||
"username": "ビルドダウンロードページ", | ||
"content": "ビルドが終了しました。" | ||
+ f"\nダウンロードページ: {url}" | ||
} | ||
return content | ||
|
||
|
||
requests.post(os.getenv("DISCORD_WEBHOOK_URL"), message(get_download_url(res))) |
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,31 @@ | ||
name: 'GitHub Build Finish Notification' | ||
|
||
env: | ||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
|
||
on: | ||
workflow_run: | ||
workflows: [Build] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- name: Set up Python 3.9 | ||
uses: actions/[email protected] | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install -r ".github/send_download_artifact_url/requirements.txt" | ||
- name: send download artifact page url | ||
env: | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
python .github/send_download_artifact_url/send-download-artifact-page-url.py |