mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-09-21 00:01:02 +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: |
|
||||
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
1
.gitignore
vendored
|
@ -10,3 +10,4 @@ access.log
|
|||
billa-2020.csv
|
||||
report.html
|
||||
spar-2020.csv
|
||||
tmp-dir/
|
40
pages.js
40
pages.js
|
@ -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) {
|
||||
|
|
25
pages.sh
25
pages.sh
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user