diff --git a/LICENSE b/LICENSE index 2b1382f9..24f2ff4d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019 Yakuhzi +Copyright (c) 2024 Yakuhzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index e33e20d5..c1a76761 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,17 @@ # Notify Workflow -A GitHub Action to send workflow status over a Telegram bot and Firebase. +A GitHub Action to send the GitHub Action workflow status over a Telegram bot. -Usage -------- -Here is an example how to use this action: +## Usage -```yaml -- name: Notify workflow status - uses: yakuhzi/notify-workflow@v2 - if: always() - with: - chat_id: ${{ secrets.CHAT_ID }} - bot_token: ${{ secrets.BOT_TOKEN }} - job_status: ${{ job.status }} -``` +Here is an example how to use this action: -If you also want to send a Firebase message: ```yaml - name: Notify workflow status - uses: yakuhzi/notify-workflow@v2 + uses: yakuhzi/notify-workflow@v3 if: always() with: - chat_id: ${{ secrets.CHAT_ID }} - bot_token: ${{ secrets.BOT_TOKEN }} - firebase_server_key: ${{ secrets.FIREBASE_SERVER_KEY }} - firebase_topic: ${{ secrets.FIREBASE_TOPIC }} - app_name: ${{ secrets.APP_NAME }} - job_status: ${{ job.status }} -``` + job-status: ${{ job.status }} + bot-token: ${{ secrets.BOT_TOKEN }} + chat-id: ${{ secrets.CHAT_ID }} +``` \ No newline at end of file diff --git a/action.yml b/action.yml index 48be1ac1..ef75d629 100644 --- a/action.yml +++ b/action.yml @@ -2,24 +2,15 @@ name: 'Notify Workflow' description: 'Send workflow status over a Telegram bot and Firebase' author: 'yakuhzi' inputs: - chat_id: - description: 'Chat to send the status' + job-status: + description: 'Job status' required: true - bot_token: + bot-token: description: 'Telegram bot token' required: true - job_status: - description: 'Job status' + chat-id: + description: 'Chat to send the status' required: true - firebase_server_key: - description: 'Firebase server key' - required: false - firebase_topic: - description: 'Topic channel of the Firebase message' - required: false - app_name: - description: 'Name of the released app' - required: false runs: using: 'node16' main: 'dist/main.js' diff --git a/release.sh b/release.sh index 914ef102..bc78ead8 100644 --- a/release.sh +++ b/release.sh @@ -2,17 +2,17 @@ # Actions requires a node_modules dir https://github.com/actions/toolkit/blob/master/docs/javascript-action.md#publish-a-releasesv1-action # It is recommended not to check these in https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations -git checkout -b releases/v2 +git checkout -b releases/v3 rm -rf node_modules dist npm install npm run build git add -f node_modules dist git commit -m "Chore: Update node_modules & dist" -git push -f origin releases/v2 +git push -f origin releases/v3 -git push origin :refs/tags/v2 -git tag -f v2 -git push origin v2 +git push origin :refs/tags/v3 +git tag -f v3 +git push origin v3 git checkout main -git branch -D releases/v2 +git branch -D releases/v3 npm install diff --git a/src/main/main.ts b/src/main/main.ts index 5f6f0c40..efa0cc7b 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -3,22 +3,7 @@ import axios from 'axios' async function run(): Promise { try { - const repository = process.env.GITHUB_REPOSITORY - const workflow = process.env.GITHUB_WORKFLOW - const runId = process.env.GITHUB_RUN_ID - const runNumber = process.env.GITHUB_RUN_NUMBER - const commit = process.env.GITHUB_SHA - let ref = process.env.GITHUB_REF - const jobStatus = process.env.INPUT_JOB_STATUS - - const botToken = process.env.INPUT_BOT_TOKEN - const chatId = process.env.INPUT_CHAT_ID - - const appName = process.env.INPUT_APP_NAME - const firebaseServerKey = process.env.INPUT_FIREBASE_SERVER_KEY - const firebaseTopic = process.env.INPUT_FIREBASE_TOPIC - let statusMessage = 'Undefined ❎' switch (jobStatus) { @@ -33,6 +18,7 @@ async function run(): Promise { break } + let ref = process.env.GITHUB_REF let tag: string | undefined if (ref?.startsWith('refs/tags/')) { @@ -44,6 +30,13 @@ async function run(): Promise { ref = '' } + const botToken = process.env.INPUT_BOT_TOKEN + const chatId = process.env.INPUT_CHAT_ID + const repository = process.env.GITHUB_REPOSITORY + const workflow = process.env.GITHUB_WORKFLOW + const runId = process.env.GITHUB_RUN_ID + const runNumber = process.env.GITHUB_RUN_NUMBER + const commit = process.env.GITHUB_SHA const checkURL = `https://github.com/${repository}/commit/${commit}/checks` console.log(`📧️ Sending Telegram message to chat '${chatId}'`) @@ -56,24 +49,6 @@ async function run(): Promise { disable_web_page_preview: true, }, }) - - if (jobStatus !== 'success' || !firebaseServerKey || !firebaseTopic || !appName || !tag) { - return - } - - console.log(`🔔 Sending Firebase message to topic '${firebaseTopic}'`) - await axios.post('https://fcm.googleapis.com/fcm/send', { - to: `/topics/${firebaseTopic}`, - data: { - name: appName, - version: tag.replace('v', ''), - }, - }, { - headers: { - 'Authorization': `key=${firebaseServerKey}`, - 'Content-Type': 'application/json', - } - }) } catch (error) { if (error instanceof Error) { core.setFailed(error.message)