From 0f9b3999b3539a4022c89804face3253fe558a2c Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Tue, 26 Apr 2022 13:46:50 +0200 Subject: [PATCH] get rid of workflow, use pre-commit hook instead --- .github/workflows/main.yml | 36 -------------------------- hooks/postdeploy.js | 20 ++++++++++++++ jamstack-init.js => hooks/precommit.js | 25 ++++++++---------- package.json | 3 ++- 4 files changed, 33 insertions(+), 51 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 hooks/postdeploy.js rename jamstack-init.js => hooks/precommit.js (56%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 0e2142d..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: CI - -on: - push: - branches: [ master ] - -env: - WEBMENTION_TOKEN: ${{secrets.WEBMENTION_TOKEN}} - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - - uses: actions/cache@v2 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: yarn jamstack build - run: | - yarn install - yarn run jamstack - - - name: commit generated hugo stuff - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: jamstack update metadata diff --git a/hooks/postdeploy.js b/hooks/postdeploy.js new file mode 100644 index 0000000..175de1b --- /dev/null +++ b/hooks/postdeploy.js @@ -0,0 +1,20 @@ + +const { webmention } = require('jam-my-stack'); + +if(!process.env.WEBMENTION_TOKEN) { + throw "No webmention token set!" +} + +const wmconfig = { + endpoint: 'https://jam.brainbaking.com', + token: process.env.WEBMENTION_TOKEN +}; + +(async function() { + // 1. send webmentions + console.log("1. Sending webmentions...") + const since = await webmention.send("redzuurdesem.be", wmconfig) + console.log(` -- done`) + + console.log("-- all done!") +})() diff --git a/jamstack-init.js b/hooks/precommit.js similarity index 56% rename from jamstack-init.js rename to hooks/precommit.js index 1430b10..9958664 100644 --- a/jamstack-init.js +++ b/hooks/precommit.js @@ -11,32 +11,29 @@ const wmconfig = { token: process.env.WEBMENTION_TOKEN }; +const rootdir = `${__dirname}/../`; + (async function() { // 1. build Lunr index console.log("1. Building lunr search index...") const index = await lunr.buildIndex([ - `${__dirname}/content/post`, - `${__dirname}/content/kort`, - `${__dirname}/content/leren`]) - await fsp.writeFile(`${__dirname}/static/js/redzuurdesem-post.json`, JSON.stringify(index), 'utf-8') + `${rootdir}/content/post`, + `${rootdir}/content/kort`, + `${rootdir}/content/leren`]) + await fsp.writeFile(`${rootdir}/static/js/redzuurdesem-post.json`, JSON.stringify(index), 'utf-8') // 2. get webmentions console.log("2. Fetching webmentions...") const mentions = await webmention.getWebmentions("redzuurdesem.be", wmconfig) const json = JSON.stringify(mentions, null, 4) - await fsp.writeFile(`${__dirname}/data/webmentions.json`, json, 'utf-8') + await fsp.writeFile(`${rootdir}/data/webmentions.json`, json, 'utf-8') - // 3. send webmentions - console.log("3. Sending webmentions...") - const since = await webmention.send("redzuurdesem.be", wmconfig) - console.log(` -- done`) - - // 4. build youtube thumbnails + // 3. build youtube thumbnails console.log("4. building youtube thumbnails...") await youtube.thumbify({ - postDir: `${__dirname}/content`, - downloadDir: `${__dirname}/static/images/yt`, - overlayImg: `${__dirname}/play.png` + postDir: `${rootdir}/content`, + downloadDir: `${rootdir}/static/images/yt`, + overlayImg: `${rootdir}/play.png` }) diff --git a/package.json b/package.json index ae5cef2..cf6ba59 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "@babel/preset-env": "^7.9.6" }, "scripts": { - "jamstack": "node jamstack-init.js" + "precommit": "node hooks/precommit.js", + "postdeploy": "node hooks/postdeploy.js" }, "repository": { "type": "git",