New workflow attempt.

This commit is contained in:
Mario Zechner 2023-05-28 11:26:17 +02:00
parent 2c1dfd82e3
commit a42ad8738c
4 changed files with 15 additions and 53 deletions

View File

@ -19,4 +19,4 @@ jobs:
run: |
git config --global user.email "badlogicgames@gmail.com"
git config --global user.name "badlogic"
./pages.sh "https://${{ secrets.PAGES_ACCESS_TOKEN }}@github.com/badlogic/badlogic.github.io"
./pages.sh

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ access.log
billa-2020.csv
report.html
spar-2020.csv
tmp-dir/

View File

@ -1,37 +1,14 @@
const fs = require("fs");
const https = require("https");
const analysis = require("./analysis.js");
const downloadFile = async (fileUrl, destinationPath) => {
const file = fs.createWriteStream(destinationPath);
return new Promise((resolve, reject) => {
https.get(fileUrl, response => {
response.pipe(file);
file.on('finish', () => {
file.close();
resolve('File downloaded successfully.');
});
file.on('error', err => {
fs.unlink(destinationPath, () => {
reject(`Error downloading file: ${err.message}`);
});
});
}).on('error', err => {
reject(`Error downloading file: ${err.message}`);
});
});
};
if (process.argv.length < 4) {
console.log("Usage: node pages.js <data-dir> <pages-url>");
console.log("Usage: node pages.js <data-dir>");
console.log()
console.log("e.g. node pages.js data/ https://badlogic.github.io");
console.log("e.g. node pages.js data/");
console.log()
process.exit(1);
}
const dataDir = process.argv[2];
const repoUrl = process.argv[3];
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir);
@ -39,19 +16,6 @@ if (!fs.existsSync(dataDir)) {
(async function () {
try {
try {
await downloadFile(repoUrl + "/latest-canonical.json", dataDir + "/latest-canonical.json");
try {
JSON.parse(fs.readFileSync(dataDir + "/latest-canonical.json"))
console.log("Downloaded previous latest-canonical.json")
} catch(e) {
console.log("No previous latest-canonical.json found.");
fs.rmSync(dataDir + "/latest-canonical.json");
}
} catch(e) {
console.log(JSON.stringify(e, null, 2));
console.log("No previous latest-canonical.json found.");
}
await analysis.updateData(dataDir);
console.log(`Wrote ${JSON.parse(fs.readFileSync(`${dataDir}/latest-canonical.json`)).length} to ${dataDir}/latest-canonical.json`);
} catch(e) {

View File

@ -1,24 +1,22 @@
#!/bin/bash
set -e
if [ -z "$1" ]; then
echo "Please provide a GitHub Pages repository URL, e.g. https://github.com/badlogic/badlogic.github.io"
exit 1
repository_name=${GITHUB_REPOSITORY#*/}
if [[ $repository_name == *.github.io ]]; then
echo "Name ends with github.io"
else
echo "Name does not end with github.io, not generating pages"
exit
fi
repoUrl=$1
pagesUrl="https://${repoUrl##*/}"
rm -rf pages
rm -rf tmp-data
mkdir tmp-data
mkdir -p docs
cp docs/latest-canonical.json tmp-data
npm install
node pages.js tmp-data $pagesUrl
node pages.js tmp-data
cp tmp-data/latest-canonical.json docs
git clone $repoUrl pages
cp site/* pages
cp tmp-data/latest-canonical.json pages
cp site/* docs
pushd pages
git add *
git commit -am "Updated $(date +'%Y-%m-%d')"
@ -26,4 +24,3 @@ git push
popd
rm -rf tmp-data
rm -rf pages