From c43addb5407f3eaa9c0050ea9c3fa0f3e07af4e2 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sun, 6 Nov 2022 19:47:11 +0100 Subject: [PATCH] github: fix + enable cron workflows --- .github/scripts/mail-for-all-new-open-prs.py | 86 ++++++++++++++++++++ .github/workflows/CMake-MSVC-noyasm.yml | 30 ------- .github/workflows/cron-git.yml | 30 +++++++ .github/workflows/cron-pr.yml | 27 ++++++ 4 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 .github/scripts/mail-for-all-new-open-prs.py delete mode 100644 .github/workflows/CMake-MSVC-noyasm.yml create mode 100644 .github/workflows/cron-git.yml create mode 100644 .github/workflows/cron-pr.yml diff --git a/.github/scripts/mail-for-all-new-open-prs.py b/.github/scripts/mail-for-all-new-open-prs.py new file mode 100644 index 00000000..33bb11c8 --- /dev/null +++ b/.github/scripts/mail-for-all-new-open-prs.py @@ -0,0 +1,86 @@ +import logging +import os +import re +import smtplib +import ssl + +import github + +logging.basicConfig(format='[%(asctime)s] %(message)s') +logging.root.setLevel(logging.INFO) + +mailinglist_message = "The [mpg123-devel mailing list](https://sourceforge.net/p/mpg123/mailman/mpg123-devel/) has been notified of the existence of this pr." +mailinglist_label = "mailing-list-notified" + +g = github.Github(os.environ["GITHUB_TOKEN"]) +user_me = g.get_user() +repo = g.get_repo(os.environ["GITHUB_REPOSITORY"]) + +for pr in repo.get_pulls(state="open"): + logging.info("Checking PR #%d", pr.number) + already_handled = False + for label in pr.get_labels(): + if label.name == mailinglist_label: + already_handled = True + if already_handled: + continue + + logging.info("PR #%d was NOT handled already", pr.number) + + mail_body = f"""\ +A pull request by {pr.user.login} was opened at {pr.created_at}. + +Please visit {pr.html_url} to give feedback and review the code. + +--- + +{pr.body} + +--- + +patch details: +- url: {pr.html_url} +- patch: {pr.html_url}.patch + +url details: +- user name: {pr.user.login} +- user url: {pr.user.html_url} +""" + logging.info("mail body: %s", mail_body) + + mail_title = "Opened GH-#{}: {} [{}]".format(pr.number, pr.title, pr.user.login) + + logging.info("mail title: %s", mail_title) + logging.info("mail body: %s", mail_body) + + mail_message = f"""\ +MIME-Version: 1.0 +Content-type: text/plain; charset=utf-8 +Subject: {mail_title} + +{mail_body} +""" + + sender_email = "{} <{}>".format("{} (via github PR)".format(pr.user.login), os.environ["MAIL_SENDER"]) + receiver_email = os.environ["MAIL_RECEIVER"].split(";") + + logging.info("mail from: %s", re.sub("[a-z0-9]", "x", sender_email, flags=re.I)) + logging.info("receiver to: %s", receiver_email) + + port = 465 + server = os.environ["MAIL_SERVER"] + login = os.environ["MAIL_LOGIN"] + password = os.environ["MAIL_PASSWORD"] + + context = ssl.create_default_context() + + with smtplib.SMTP_SSL(server, port, context=context) as server: + server.login(login, password) + server.sendmail(sender_email, receiver_email, mail_message) + + logging.info("Creating comment at PR#%d", pr.number) + pr.add_to_labels(mailinglist_label) + comment = pr.create_issue_comment(mailinglist_message) + logging.info("Visit comment at %s", comment.html_url) + + logging.info("mail sent") diff --git a/.github/workflows/CMake-MSVC-noyasm.yml b/.github/workflows/CMake-MSVC-noyasm.yml deleted file mode 100644 index d2766485..00000000 --- a/.github/workflows/CMake-MSVC-noyasm.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: CMake MSVC noyasm - -on: push - -jobs: - build: - defaults: - run: - shell: cmd - strategy: - matrix: - # currently windows-latest==windows-2022 - # windows-2022: VS2022 - # windows-2019: VS2019 - os: [windows-2022, windows-2019] - arch: [x86, x64, amd64_arm, amd64_arm64] - shared: [ON, OFF] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - - name: Setup vcvars - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: ${{ matrix.arch }} - - name: Install ninja - uses: turtlesec-no/get-ninja@main - - name: CMake (configure) - run: cmake -S ports\cmake -B build -GNinja -DBUILD_SHARED_LIBS=${{ matrix.shared }} . - - name: CMake --build - run: cmake --build build diff --git a/.github/workflows/cron-git.yml b/.github/workflows/cron-git.yml new file mode 100644 index 00000000..cccb7114 --- /dev/null +++ b/.github/workflows/cron-git.yml @@ -0,0 +1,30 @@ +on: + schedule: + - cron: "0 * * * *" # Run every hour + +jobs: + git_svn_sync: + if: ${{ github.repository == 'madebr/mpg123' }} + runs-on: "ubuntu-latest" + steps: + - name: "Checkout git mpg123 clone" + uses: "actions/checkout@v4" + with: + fetch-depth: 0 + token: ${{ secrets.PUSH_GITHUB_TOKEN }} + - name: "Configure git client" + run: | + git config --global user.name "mpg123 GitHub bot" + git config --global user.email "mpg123-github-bot@github.com" + - name: "Download (new) revisions from mpg123 git-svn" + run: | + git remote add mpg123 https://mpg123.org/trunk/.git/ + git fetch mpg123 + - name: "Merge mpg123's master" + run: | + git checkout master-with-github-ci + git merge mpg123/master -X ours + - name: "Force push (new) master" + run: | + git push origin master-with-github-ci -f + git push origin mpg123/master:master -f diff --git a/.github/workflows/cron-pr.yml b/.github/workflows/cron-pr.yml new file mode 100644 index 00000000..dcacc40b --- /dev/null +++ b/.github/workflows/cron-pr.yml @@ -0,0 +1,27 @@ +on: + schedule: + - cron: "0 * * * *" # Run every hour + +jobs: + send_mail: + if: ${{ github.repository == 'madebr/mpg123' }} + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v4 + - name: "Setup python" + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: "Install Python requirements" + run: | + python -m pip install --user pygithub + - name: "Send mail" + run: | + python .github/scripts/mail-for-all-new-open-prs.py + env: + GITHUB_TOKEN: ${{ github.token }} + MAIL_RECEIVER: ${{ secrets.MAIL_RECEIVER }} + MAIL_SENDER: ${{ secrets.MAIL_SENDER }} + MAIL_SERVER: ${{ secrets.MAIL_SERVER }} + MAIL_LOGIN: ${{ secrets.MAIL_LOGIN }} + MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}