Heroku-Account-Scheduler: Initial Commit

This commit is contained in:
Evan Ferrao 2021-12-29 22:18:12 +05:30
commit aea7df2693
3 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,74 @@
name: Heroku-Account-Scheduler
on:
workflow_dispatch:
push:
schedule:
- cron: '0 13 */15 * *'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkouts
uses: actions/checkout@v2
- name: Check Conditions And Configs
run: |
CURRENT_DAY=$(echo "$(date +%j) + 0" | bc)
if [[ "${CURRENT_DAY}" -lt "15" ]]; then
echo "USE_FIRST_ACCOUNT=true" >> "${GITHUB_ENV}"
else
echo "USE_FIRST_ACCOUNT=false" >> "${GITHUB_ENV}"
fi
if [[ "${{secrets.TG_TOKEN}}" != "" ]] && [[ "${{secrets.TG_CHAT}}" != "" ]]; then echo "TELEGRAM_UPDATE=true" >> "${GITHUB_ENV}" && echo "Telegram Update Enabled" ; fi
- name: Switch To First Heroku Account
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY_1}}
heroku_email: ${{secrets.HEROKU_EMAIL_1}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME_1}}
justlogin: true
- run: |
heroku auth:whoami
if [[ "${USE_FIRST_ACCOUNT}" == "true" ]]; then
echo "Switching To First Account App!"
heroku ps:scale web=1 --app ${{secrets.HEROKU_APP_NAME_1}} || heroku ps:scale worker=1 --app ${{secrets.HEROKU_APP_NAME_1}}
elif [[ "${USE_FIRST_ACCOUNT}" == "false" ]]; then
echo "Turning Off First Account App!"
heroku ps:scale web=0 --app ${{secrets.HEROKU_APP_NAME_1}} || heroku ps:scale worker=0 --app ${{secrets.HEROKU_APP_NAME_1}}
fi
- name: Switch To Second Heroku Account
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY_2}}
heroku_email: ${{secrets.HEROKU_EMAIL_2}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME_2}}
justlogin: true
- run: |
heroku auth:whoami
if [[ "${USE_FIRST_ACCOUNT}" == "false" ]]; then
echo "Switching To Second Account App!"
heroku ps:scale web=1 --app ${{secrets.HEROKU_APP_NAME_2}} || heroku ps:scale worker=1 --app ${{secrets.HEROKU_APP_NAME_2}}
elif [[ "${USE_FIRST_ACCOUNT}" == "true" ]]; then
echo "Turning Off Second Account App!"
heroku ps:scale web=0 --app ${{secrets.HEROKU_APP_NAME_2}} || heroku ps:scale worker=0 --app ${{secrets.HEROKU_APP_NAME_2}}
fi
- name: Send Telegram Notification
if: env.TELEGRAM_UPDATE == 'true'
run: |
TG_TOKEN=${{secrets.TG_TOKEN}}
TG_CHAT=${{secrets.TG_CHAT}}
HEROKU_APP_NAME_2=${{secrets.HEROKU_APP_NAME_2}}
HEROKU_APP_NAME_1=${{secrets.HEROKU_APP_NAME_1}}
HEROKU_EMAIL_1=${{secrets.HEROKU_EMAIL_1}}
HEROKU_EMAIL_2=${{secrets.HEROKU_EMAIL_2}}
if [[ "${USE_FIRST_ACCOUNT}" == "true" ]]; then
TEXT="#LOGGER #HEROKU Switched To Account 1 For App $HEROKU_APP_NAME_1 With Email $HEROKU_EMAIL_1 "
elif [[ "${USE_FIRST_ACCOUNT}" == "false" ]]; then
TEXT="#LOGGER #HEROKU Switched To Account 2 For App $HEROKU_APP_NAME_2 With Email $HEROKU_EMAIL_2 "
fi
curl -X POST "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" -d "chat_id=${TG_CHAT}&text=${TEXT}"

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Box In a Box
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

74
Readme.md Normal file
View File

@ -0,0 +1,74 @@
Heroku-Account-Scheduler
===============
Heroku-Account-Scheduler, A Simple Script Powered By GitHub Actions To Switch Heroku Accounts Every Fifteen Days.
This Repo Makes Sure You Never Run Out Of Dynos.
Deployment:
----------
1. Fork the reposistory:
2. Deploy Both Your Apps On Seperate Heroku Accounts
```
Note: Deploy First App. Test It, Turn It Off. Then Deploy 2nd App. Test It, Turn It Off.
Note: For Apps Like "Userbots" Which Need String Session, It's Recommended To Generate Seperate String Session For Each Of The Two Apps.
The Same Applies To Any Other Bot That Uses "One-Time-Tokens", "OAuth-Tokens" etc.
```
```
Make Sure Each App Runs As Intended Individually Before Moving Onto The Next Step
```
3. Turn Both The Deployed Apps Off On Both The Accounts
```
If You Don't Expect TOKENS and Stuff to Expire And Break.
```
4. Set The Following Github Actions Secrets:
```
HEROKU_EMAIL_1 : Your Heroku Account Email Of Your First Account.
HEROKU_EMAIL_2 : Your Heroku Account Email Of Your Second Account.
HEROKU_API_KEY_1 : Your Heroku Account API-KEY Of Your First Account. Get It From dashboard.heroku.com/account
HEROKU_API_KEY_2 : Your Heroku Account API-KEY Of Your Second Account. Get It From dashboard.heroku.com/account
HEROKU_APP_NAME_1 : Your Heroku Account APP-NAME Of First Account.
HEROKU_APP_NAME_2 : Your Heroku Account APP-NAME Of Second Account.
```
5. Make Sure Actions Are Enabled In GitHub:
- To Do This, Visit The "Actions" Tab Of Your Fork
- In The Workflows Section Click on "Heroku-Account-Scheduler.yml" Button
- Now Click On Run Workflow. A Prompt Telling You That Scheduled Workflows Are Disabled For Forks Will Come Up. Click Enable Workflow, Then Run Workflow
- If Done Right, The Script Would Swap Account Based On The Date Of The Month. Making Sure Your App Always Runs.
-------
Features Nobody Asked For(Additional Features):
----------
- Send Notification To Telegram Log Group About Switching Of The Accounts
- Set The Following Secrets In GitHub-Secrets
```
TG_TOKEN : Your Telegram Bot Token
TG_CHAT: Your Telegram Private Group ID
```
-------
Why Does This Script Exist?
----------
- Heroku Doesn't Provide Users Enough Dynos Under Their Free Quota For An App To Last An Entire Month Without Sleeping. And Not Everyone Has A Credit-Card. Even Worse. Heroku Refuses To Accept My Credit-Cards From Legit Banks, Even Though They Have International Payments Enabled. I'm Left With No Choice ;-;
- I Also Have Some Strange Deep Affection Towards Heroku.....um..yea, I'm Weird.
-------
## **Warnings:**
- This Bot/Script Uses GitHub Actions, Although Running One Lightweight Action Once In Fifteen Days, Is In No Way Considered Abuse Of It. You Are Still Warned Of Account Suspension(If You Reduce The Cron-Job Frequency)(If You Already Have A Billion Other Consecutive GitHub Actions Running[Although GitHub Allows Only 20 Concurrent Jobs Per Account])
- You Better Have A Backup Of Your App-Data/Configs As Heroku Can Ban Your Account Whenever They Please.
## **Credits:**
* **Box-boi** : [Github](https://github.com/Box-boi)