revert back to cron job

This commit is contained in:
user2 2024-07-11 15:31:10 +03:00
parent 4bcb57d46a
commit 71d5a29c6e
4 changed files with 39 additions and 49 deletions

View File

@ -1,14 +0,0 @@
name: Push commit
on:
push:
schedule:
- cron: "30 * * * *"
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: https://github.com/ischanx/checkout@06c611454073903c9d44641d7e085b21115d3dcf
- run: DISCORD_WEBHOOK=${{ secrets.DISCORD_WEBHOOK }} bash update_cec_list.bash

View File

@ -1,30 +0,0 @@
#!/bin/bash
set -euo pipefail
set -x
send() {
local _msg=$1
if [[ -z $_msg ]]; then
return
fi
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\":\"\`\`\`diff\n$_msg\`\`\`\"}" \
"$DISCORD_WEBHOOK"
}
msg=""
while IFS= read -r line; do
line="$(sed 's@"@\\"@g' <<< "$line")" # Json screening
len="$(wc -m <<< "$msg$line")"
if [[ $len -ge 1985 ]]; then
send "$msg"
msg="$line"
else
msg+="$line\\n"
fi
done
send "$msg"

26
stdin2discord.py Normal file
View File

@ -0,0 +1,26 @@
import sys
import requests
import os
def send(_msg: str):
if len(_msg) == 0:
return
r = requests.post(
url=os.environ['DISCORD_WEBHOOK'],
data=f'content=```diff\n{requests.utils.quote(_msg)}```'.encode('utf-8'),
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
)
r.raise_for_status()
msg = ''
for line in sys.stdin:
if len(msg + line) >= 2000:
send(msg)
msg = ''
else:
msg += line
send(msg)

View File

@ -1,20 +1,28 @@
#!/usr/bin/bash #!/usr/bin/bash
set -euo pipefail set -euo pipefail
cd "$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" || { exit 1; echo "changing directory failed"; exit 1; }
http_response=$(curl -s -L -o list.csv -w "%{http_code}" "https://docs.google.com/spreadsheets/d/e/2PACX-1vTXE8HCavThmJt1Wshy3GyF2ZJ-264SbNRVucsPUe2rbEgpm-e3tqsX-8K2mwsG4ozBj6qUyOOd4RMe/pub?gid=1832580214&single=true&output=csv") http_response=$(curl -s -L -o list.csv -w "%{http_code}" "https://docs.google.com/spreadsheets/d/e/2PACX-1vTXE8HCavThmJt1Wshy3GyF2ZJ-264SbNRVucsPUe2rbEgpm-e3tqsX-8K2mwsG4ozBj6qUyOOd4RMe/pub?gid=1832580214&single=true&output=csv")
if [ $http_response != "200" ]; then if [ $http_response != "200" ]; then
#echo "page not found" #echo "page not found"
#cat list.csv #cat list.csv
git reset --hard git reset --hard | grep -v "HEAD is now at"
exit 1 exit 1
else else
git config user.name 'user2'
git config user.email 'user2@localhost'
git remote set-url origin https://x-access-token:$GITHUB_TOKEN@gitea.demb.uk/$GITHUB_REPOSITORY
git diff "list.csv" git diff "list.csv"
git diff "list.csv" | bash stdin2discord.bash git diff "list.csv" | python3 stdin2discord.py
git add "list.csv" git add "list.csv"
git commit -m "commit" git commit -m "commit"
git push git push
fi fi
#curl -L -o "list.csv" -s "https://docs.google.com/spreadsheets/d/e/2PACX-1vTXE8HCavThmJt1Wshy3GyF2ZJ-264SbNRVucsPUe2rbEgpm-e3tqsX-8K2mwsG4ozBj6qUyOOd4RMe/pub?gid=1832580214&single=true&output=csv" || { echo "downloading failed"; exit 1; }
#git diff "list.csv"
#git add "list.csv"
#git commit -m "commit" | grep -vE 'On branch master|nothing to commit, working tree clean'