Skip to content

Commit cc5b757

Browse files
committed
test uploading workflow
new file: .github/workflows/upload-new-graph.yml modified: uploader/src/upload.cpp
1 parent a7bad57 commit cc5b757

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Upload New Graph
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
check-new-files:
8+
runs-on: ubuntu-24.04
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
- name: set up C++ environment and dependencies
13+
env:
14+
DEBIAN_FRONTEND: noninteractive
15+
TZ: Etc/UTC
16+
run: |
17+
apt update
18+
apt install -y git g++ gdb make cmake curl libcurl4-openssl-dev libcurlpp-dev nlohmann-json3-dev
19+
- name: Compile upload
20+
run: |
21+
mkdir build
22+
cmake -DCMAKE_BUILD_TYPE=Release -B build/ uploader/
23+
make -C build/ upload
24+
- name: Get file list needed in task
25+
id: collect
26+
run: |
27+
echo "Collecting .tex files..."
28+
files=$(git diff --name-status HEAD~10 HEAD | awk '$1 == "A" && $2 ~ /\.tex$/ { print $2 }')
29+
echo "$files"
30+
echo "files<<EOF" >> $GITHUB_OUTPUT
31+
echo "$files" >> $GITHUB_OUTPUT
32+
echo "EOF" >> $GITHUB_OUTPUT
33+
- name: Run upload on each file
34+
env:
35+
WIKITOKEN: ${{ secrets.WIKITOKEN }}
36+
run: |
37+
echo "Running command for each .tex file:"
38+
echo "${{steps.collect.outputs.files }}" | while read filepath; do
39+
[ -z "$filepath" ] && continue
40+
echo "Processing file: $filepath"
41+
done

uploader/src/upload.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@
77
#include<string>
88
#include<nlohmann/json.hpp>
99
#include"wiki.hpp"
10-
const std::string API="http://localhost:8080/api.php";
10+
const std::string API="https://wiki.byrdocs.org/api.php";
1111
const std::string LOGIN="/tmp/wiki_login_cookies";
1212
const std::string CSRF="/tmp/wiki_csrf_cookies";
1313
const std::list<std::string> HEADER{std::format("X-Byrdocs-Token:{}",std::getenv("WIKITOKEN"))};
1414
int main(int argc,char *argv[]){
1515
try{
16-
std::string file_path{argv[1]};
17-
std::filesystem::path fs_path{file_path};
1816
if(argc!=2){
1917
std::cout<<std::format(R"(Usage: {} <path-to-file>)",argv[0])<<std::endl;
2018
return 1;
2119
}
20+
std::string file_path{argv[1]};
21+
std::filesystem::path fs_path{file_path};
2222
const std::string login_token=wiki::get_login_token(API,LOGIN);
2323
wiki::login(
2424
API,
2525
LOGIN,
2626
"CppHusky@uploader",
2727
std::getenv("WIKIPASS_UPLOADER"),
28-
login_token
28+
login_token,
29+
HEADER
2930
);
3031
std::clog<<std::format("Logged in. Started uploading {}...",argv[1])<<std::endl;
3132
const std::string csrf_token=wiki::get_csrf_token(API,LOGIN,CSRF);
@@ -46,9 +47,11 @@ int main(int argc,char *argv[]){
4647
csrf_token,
4748
HEADER
4849
);
49-
std::clog<<result<<std::endl;
50-
if(result["upload"]["result"]!="Success")
51-
return 3;
50+
if(result["upload"]["result"]!="Success"){
51+
std::clog<<"The uploader bot encountered a non-success result. See the log in current directory for more information."<<std::endl;
52+
std::ofstream logs{std::format("{}.log",filename)};
53+
logs<<result<<std::endl;
54+
}
5255
}catch(const curlpp::RuntimeError &e){
5356
std::cerr<<e.what()<<std::endl;
5457
assert(false);

0 commit comments

Comments
 (0)