From aea7df2693f0664400114818a8e260c982cb429c Mon Sep 17 00:00:00 2001 From: Box In A Box Date: Wed, 29 Dec 2021 22:18:12 +0530 Subject: [PATCH] Heroku-Account-Scheduler: Initial Commit --- .../workflows/Heroku-Account-Scheduler.yml | 74 +++++++++++++++++++ LICENSE | 21 ++++++ Readme.md | 74 +++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 .github/workflows/Heroku-Account-Scheduler.yml create mode 100644 LICENSE create mode 100644 Readme.md diff --git a/.github/workflows/Heroku-Account-Scheduler.yml b/.github/workflows/Heroku-Account-Scheduler.yml new file mode 100644 index 0000000..5eac2bb --- /dev/null +++ b/.github/workflows/Heroku-Account-Scheduler.yml @@ -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}" \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0e9c827 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..bc8269c --- /dev/null +++ b/Readme.md @@ -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) \ No newline at end of file