Skip to content

Commit

Permalink
Merge pull request #13 from DevsOnTheBoard/feature/workflow/BuildFini…
Browse files Browse the repository at this point in the history
…shNotify

Feature/workflow/build finish notify
  • Loading branch information
tsubasa-alife authored Nov 28, 2023
2 parents d2799d8 + f9a9f21 commit 1c92fc2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/send_download_artifact_url/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-dotenv==0.20.0
requests==2.28.0
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)))
31 changes: 31 additions & 0 deletions .github/workflows/build_finish_notify.yml
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

0 comments on commit 1c92fc2

Please sign in to comment.