Skip to content

fixing actions workflows #38

fixing actions workflows

fixing actions workflows #38

Workflow file for this run

name: blog-post-create-issues
on:
push:
branches: [ master ]
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: collect-titles
run: "grep -E '^name\\s*\\:' ./src/blog/ -R > posts.txt && cat posts.txt"
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm install js-yaml
- uses: actions/github-script@v8
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require("fs");
const yaml = require("js-yaml");
const { owner, repo } = context.repo;
const result = await github.issues.listForRepo({ owner, repo });
const issues = Object.fromEntries(result.data.map(x => [x.title, x]));
let lines = fs.readFileSync('posts.txt').toString().split('\n');
lines.forEach(l => {
l = l.trim()
if (!l) return;
let [f, nameLine] = l.split(':', 2);
let title = nameLine.slice(nameLine.indexOf(':')+1).trim();
let labels = ["blog-post"];
let contents = fs.readFileSync(f).toString().trim();
if (contents.startsWith('---')) {
const [_div, metaString, rest] = contents.split('---', 3);
const meta = yaml.load(metaString);
labels = labels.concat(meta['labels'] || []);
if (meta['name']) {
title = meta['name'].trim();
}
contents = rest;
}
const body = contents
.replace(/(!\[[^\]]*\]\()(\/[^\)]+\))/g, `$1https://github.com/${owner}/${repo}/raw/master$2`) // MD image
.replace(/(\[[^\]]*\]\()(\/[^\)]+\))/g, `$1https://github.com/${owner}/${repo}/blob/master$2`) // MD link
.replace(/(src=")(\/[^"]+")/g, `$1https://github.com/${owner}/${repo}/raw/master$2`); // <img> tag
if (title in issues) {
const found = issues[title];
github.issues.update({
owner, repo,
issue_number: found.number,
labels: found.labels.concat(labels),
title, body,
});
return;
}
github.issues.create({ owner, repo, title, body, labels });
});