Skip to content

Commit

Permalink
Feat: Remove Firebase message feature
Browse files Browse the repository at this point in the history
  • Loading branch information
yakuhzi committed Apr 2, 2024
1 parent 7b24434 commit 0c03133
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 76 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 }}
```
19 changes: 5 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 6 additions & 6 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 8 additions & 33 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,7 @@ import axios from 'axios'

async function run(): Promise<void> {
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) {
Expand All @@ -33,6 +18,7 @@ async function run(): Promise<void> {
break
}

let ref = process.env.GITHUB_REF
let tag: string | undefined

if (ref?.startsWith('refs/tags/')) {
Expand All @@ -44,6 +30,13 @@ async function run(): Promise<void> {
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}'`)
Expand All @@ -56,24 +49,6 @@ async function run(): Promise<void> {
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)
Expand Down

0 comments on commit 0c03133

Please sign in to comment.