mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-30 12:27:15 +02:00
New workflow attempt.
This commit is contained in:
parent
2c1dfd82e3
commit
a42ad8738c
2
.github/workflows/pages.yml
vendored
2
.github/workflows/pages.yml
vendored
|
@ -19,4 +19,4 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
git config --global user.email "badlogicgames@gmail.com"
|
git config --global user.email "badlogicgames@gmail.com"
|
||||||
git config --global user.name "badlogic"
|
git config --global user.name "badlogic"
|
||||||
./pages.sh "https://${{ secrets.PAGES_ACCESS_TOKEN }}@github.com/badlogic/badlogic.github.io"
|
./pages.sh
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -10,3 +10,4 @@ access.log
|
||||||
billa-2020.csv
|
billa-2020.csv
|
||||||
report.html
|
report.html
|
||||||
spar-2020.csv
|
spar-2020.csv
|
||||||
|
tmp-dir/
|
40
pages.js
40
pages.js
|
@ -1,37 +1,14 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const https = require("https");
|
|
||||||
const analysis = require("./analysis.js");
|
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) {
|
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()
|
||||||
console.log("e.g. node pages.js data/ https://badlogic.github.io");
|
console.log("e.g. node pages.js data/");
|
||||||
console.log()
|
console.log()
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const dataDir = process.argv[2];
|
const dataDir = process.argv[2];
|
||||||
const repoUrl = process.argv[3];
|
|
||||||
|
|
||||||
if (!fs.existsSync(dataDir)) {
|
if (!fs.existsSync(dataDir)) {
|
||||||
fs.mkdirSync(dataDir);
|
fs.mkdirSync(dataDir);
|
||||||
|
@ -39,19 +16,6 @@ if (!fs.existsSync(dataDir)) {
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
try {
|
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);
|
await analysis.updateData(dataDir);
|
||||||
console.log(`Wrote ${JSON.parse(fs.readFileSync(`${dataDir}/latest-canonical.json`)).length} to ${dataDir}/latest-canonical.json`);
|
console.log(`Wrote ${JSON.parse(fs.readFileSync(`${dataDir}/latest-canonical.json`)).length} to ${dataDir}/latest-canonical.json`);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
25
pages.sh
25
pages.sh
|
@ -1,24 +1,22 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
repository_name=${GITHUB_REPOSITORY#*/}
|
||||||
|
if [[ $repository_name == *.github.io ]]; then
|
||||||
if [ -z "$1" ]; then
|
echo "Name ends with github.io"
|
||||||
echo "Please provide a GitHub Pages repository URL, e.g. https://github.com/badlogic/badlogic.github.io"
|
else
|
||||||
exit 1
|
echo "Name does not end with github.io, not generating pages"
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
repoUrl=$1
|
|
||||||
pagesUrl="https://${repoUrl##*/}"
|
|
||||||
|
|
||||||
rm -rf pages
|
|
||||||
rm -rf tmp-data
|
rm -rf tmp-data
|
||||||
mkdir tmp-data
|
mkdir tmp-data
|
||||||
|
mkdir -p docs
|
||||||
|
cp docs/latest-canonical.json tmp-data
|
||||||
|
|
||||||
npm install
|
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/* docs
|
||||||
cp site/* pages
|
|
||||||
cp tmp-data/latest-canonical.json pages
|
|
||||||
pushd pages
|
pushd pages
|
||||||
git add *
|
git add *
|
||||||
git commit -am "Updated $(date +'%Y-%m-%d')"
|
git commit -am "Updated $(date +'%Y-%m-%d')"
|
||||||
|
@ -26,4 +24,3 @@ git push
|
||||||
popd
|
popd
|
||||||
|
|
||||||
rm -rf tmp-data
|
rm -rf tmp-data
|
||||||
rm -rf pages
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user