Merge pull request #515 from tycrek/update-build-process

pull/517/head
Josh Moore 8 months ago committed by GitHub
commit a64b4ba314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,10 +4,10 @@ on:
branches:
- master
paths: # Only build if these files were modified
- yaml/*.yml
- md/*.md
- _build.js
- _wiki.js
- src/yaml/*.yml
- src/md/*.md
- src/_build.js
- src/_wiki.js
jobs:
build:
runs-on: ubuntu-latest
@ -20,7 +20,7 @@ jobs:
with:
node-version: 20.x
- name: Build README
run: npm i && node _build.js
run: npm i && node src/_build.js
- name: Commit & Push
# GH_NAME/GH_EMAIL can be any collaborator account with Force Push access
run: |

@ -4,8 +4,8 @@
1. **English only** for issues & pull requests.
2. **Do not edit README.md!** This file is automatically generated. Instead, use:
- [`yaml/`](https://github.com/tycrek/degoogle/tree/master/yaml) for structured data
- [`md/`](https://github.com/tycrek/degoogle/tree/master/md) for regular text
- [`src/yaml/`](https://github.com/tycrek/degoogle/tree/master/src/yaml) for structured data
- [`src/md/`](https://github.com/tycrek/degoogle/tree/master/src/md) for regular text
3. Personal opinions will **not** be considered. Instead, provide detailed links as supporting evidence.
4. **Use the templates** when submitting an Issue or Pull Request. Blank Issues/PRs are not allowed.

@ -1,10 +1,10 @@
// Build tool for generating README.md
const { EOL } = require('os');
const path = require('path');
const fs = require('fs-extra');
const { DateTime } = require('luxon');
const path = require('path');
const YAML = require('yaml');
const { EOL } = require('os');
const { DateTime } = require('luxon');
const BUILD_SECTION = {
header: () => readFile('md/_header.md').replace('{{DATE}}', DateTime.now().toFormat('MMMM dd, yyyy').replace(/ /g, '%20')),
@ -175,5 +175,5 @@ function generatePublications(pubTitle, filename) {
}
// ! Generate README.md
fs.writeFileSync(path.join(__dirname, 'README.md'), Object.values(BUILD_SECTION).map((section) => section()).join(`${EOL}${EOL}`));
fs.writeFileSync(path.join(process.cwd(), 'README.md'), Object.values(BUILD_SECTION).map((section) => section()).join(`${EOL}${EOL}`));
console.log('Done!');

@ -1,33 +1,26 @@
// Build tool for uploading generated README.md to Reddit Wiki
const qs = require('qs');
const fs = require('fs-extra');
const path = require('path');
const fetch = require('node-fetch');
const qs = require('qs');
const { DateTime } = require('luxon');
// REDDIT_: For authentication with Reddit API. Oauth MUST be used. ID and Secret come from a "script" app type.
const REDDIT_USER = process.env.REDDIT_USER || 'username';
const REDDIT_PASS = process.env.REDDIT_PASS || 'password';
const REDDIT_CLIENT_ID = process.env.REDDIT_CLIENT_ID || 'clientid';
const REDDIT_CLIENT_SECRET = process.env.REDDIT_CLIENT_SECRET || 'clientsecret';
// Initial basic authorization for getting the Oauth token
const BASIC_AUTH = `Basic ${Buffer.from(REDDIT_CLIENT_ID + ':' + REDDIT_CLIENT_SECRET).toString('base64')}`;
// WIKI_: For the Reddit Wiki
const WIKI_SUBREDDIT = 'privacy';
const WIKI_PAGE = 'de-google';
const WIKI_REASON = 'Automated edit from GitHub repo: https://github.com/tycrek/degoogle';
// REDDIT.: For authentication with Reddit API. Oauth MUST be used. ID and Secret come from a "script" app type.
const REDDIT = {
USER: process.env.REDDIT_USER || 'username',
PASS: process.env.REDDIT_PASS || 'password',
CLIENT_ID: process.env.REDDIT_CLIENT_ID || 'clientid',
CLIENT_SECRET: process.env.REDDIT_CLIENT_SECRET || 'clientsecret',
};
// Endpoints for each of our fetches to Reddit
const ENDPOINTS = {
revisions: `https://old.reddit.com/r/${WIKI_SUBREDDIT}/wiki/revisions/${WIKI_PAGE}.json`,
revisions: `https://old.reddit.com/r/privacy/wiki/revisions/de-google.json`,
token: 'https://www.reddit.com/api/v1/access_token',
edit: `https://oauth.reddit.com/r/${WIKI_SUBREDDIT}/api/wiki/edit`
edit: `https://oauth.reddit.com/r/privacy/api/wiki/edit`
};
// Helps POST data be submitted properly
const CONTENT_TYPE = 'application/x-www-form-urlencoded';
// Update the wiki
Promise.all([getLastRevision(), getToken()])
.then(([lastId, token]) => putWiki(lastId, token))
@ -52,8 +45,15 @@ function getToken() {
return new Promise((resolve, reject) =>
fetch(ENDPOINTS.token, {
method: 'POST',
headers: { 'Authorization': BASIC_AUTH, 'Content-Type': CONTENT_TYPE },
body: qs.stringify({ grant_type: 'password', username: REDDIT_USER, password: REDDIT_PASS })
headers: {
'Authorization': `Basic ${Buffer.from(`${REDDIT.CLIENT_ID}:${REDDIT.CLIENT_SECRET}`).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: qs.stringify({
grant_type: 'password',
username: REDDIT.USER,
password: REDDIT.PASS
})
})
.then((response) => response.json())
.then(({ access_token }) => resolve(access_token))
@ -69,11 +69,14 @@ function putWiki(lastId, token) {
return new Promise((resolve, reject) =>
fetch(ENDPOINTS.edit, {
method: 'POST',
headers: { 'Authorization': `bearer ${token}`, 'Content-Type': CONTENT_TYPE },
headers: {
'Authorization': `bearer ${token}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: qs.stringify({
content: fixContent(fs.readFileSync(path.join(__dirname, 'README.md')).toString()),
page: WIKI_PAGE,
reason: WIKI_REASON,
content: fixContent(fs.readFileSync(path.join(process.cwd(), 'README.md')).toString()),
page: 'de-google',
reason: 'Automated edit from GitHub repo: https://github.com/tycrek/degoogle',
previous: lastId
})
})
@ -90,12 +93,12 @@ function putWiki(lastId, token) {
* @param {String} content The content in README.md
*/
function fixContent(content) {
// Fix updated timestamp
content = content.replace(/\!\[Updated\](.*?)square\)/g, `#### Updated: ${DateTime.now().toFormat('MMMM dd, yyyy')}`);
return content
// Fix published timestamps
content = content.replace(/\!\[Published\]\(https\:\/\/img\.shields\.io\/badge\//g, '**');
content = content.replace(/-informational\?style=flat-square\)/g, '**');
// Fix updated timestamp
.replace(/\!\[Updated\](.*?)square\)/g, `#### Updated: ${DateTime.now().toFormat('MMMM dd, yyyy')}`)
return content;
} // * If this is highlighted weirdly, it's because of the 'updated timestamp' regex, don't worry about it
// Fix published timestamps
.replace(/\!\[Published\]\(https\:\/\/img\.shields\.io\/badge\//g, '**')
.replace(/-informational\?style=flat-square\)/g, '**');
}
Loading…
Cancel
Save