From a42ad8738c8f9073ac92ae68067fde72d59149e2 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sun, 28 May 2023 11:26:17 +0200 Subject: [PATCH] New workflow attempt. --- .github/workflows/pages.yml | 2 +- .gitignore | 1 + pages.js | 40 ++----------------------------------- pages.sh | 25 ++++++++++------------- 4 files changed, 15 insertions(+), 53 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index cc05791..3cfdd81 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -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" \ No newline at end of file + ./pages.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index e30cd42..b72008d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ access.log billa-2020.csv report.html spar-2020.csv +tmp-dir/ \ No newline at end of file diff --git a/pages.js b/pages.js index 43bfce8..49e1795 100644 --- a/pages.js +++ b/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 "); + console.log("Usage: node pages.js "); 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) { diff --git a/pages.sh b/pages.sh index bd71aea..cddd8fd 100755 --- a/pages.sh +++ b/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