fix: reworking files
This commit is contained in:
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@@ -4,7 +4,6 @@ on: [workflow_dispatch]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
needs: [test]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
|
21
src/git.ts
21
src/git.ts
@@ -2,10 +2,17 @@
|
|||||||
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
const { GITHUB_REPOSITORY, GITHUB_REF } = process.env;
|
const { GITHUB_REPOSITORY, GITHUB_REF } = process.env;
|
||||||
|
|
||||||
const branch = GITHUB_REF?.replace('refs/heads/', '');
|
const branch = GITHUB_REF?.replace('refs/heads/', '');
|
||||||
|
|
||||||
|
type File = {
|
||||||
|
filename: string;
|
||||||
|
data: string;
|
||||||
|
};
|
||||||
|
|
||||||
class Git {
|
class Git {
|
||||||
constructor() {
|
constructor() {
|
||||||
const githubToken = core.getInput('github-token', { required: true });
|
const githubToken = core.getInput('github-token', { required: true });
|
||||||
@@ -89,6 +96,20 @@ class Git {
|
|||||||
updateOrigin = (repo: string) => this.exec(`remote set-url origin ${repo}`);
|
updateOrigin = (repo: string) => this.exec(`remote set-url origin ${repo}`);
|
||||||
|
|
||||||
createTag = (tag: string) => this.exec(`tag -a ${tag} -m "${tag}"`);
|
createTag = (tag: string) => this.exec(`tag -a ${tag} -m "${tag}"`);
|
||||||
|
|
||||||
|
async pushNewFiles(files: File[] = []): Promise<any> {
|
||||||
|
if (!files.length) return;
|
||||||
|
|
||||||
|
await this.pull();
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
files.map(({ filename, data }) => fs.writeFile(filename, data))
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.add(files.map(({ filename }) => filename));
|
||||||
|
await this.commit(`chore(updates): updated entries in files`);
|
||||||
|
await this.push();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new Git();
|
export default new Git();
|
||||||
|
@@ -1,15 +1,11 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import ejs from 'ejs';
|
import ejs from 'ejs';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { remark } from 'remark';
|
import { remark } from 'remark';
|
||||||
import toc from 'remark-toc';
|
import toc from 'remark-toc';
|
||||||
import git from './git';
|
|
||||||
|
|
||||||
export const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
|
export const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
|
||||||
export const API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${REPO_USERNAME}/starred`;
|
export const API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${REPO_USERNAME}/starred`;
|
||||||
|
|
||||||
const fsp = fs.promises;
|
|
||||||
|
|
||||||
export async function renderer(
|
export async function renderer(
|
||||||
data: { [key: string]: any },
|
data: { [key: string]: any },
|
||||||
templateString: string
|
templateString: string
|
||||||
@@ -38,22 +34,3 @@ export function generateMd(data: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const MARKDOWN_FILENAME: string = core.getInput('output-filename');
|
export const MARKDOWN_FILENAME: string = core.getInput('output-filename');
|
||||||
|
|
||||||
type File = {
|
|
||||||
filename: string;
|
|
||||||
data: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function pushNewFiles(files: File[] = []): Promise<any> {
|
|
||||||
if (!files.length) return;
|
|
||||||
|
|
||||||
await git.pull();
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
files.map(({ filename, data }) => fsp.writeFile(filename, data))
|
|
||||||
);
|
|
||||||
|
|
||||||
await git.add(files.map(({ filename }) => filename));
|
|
||||||
await git.commit(`chore(updates): updated entries in files`);
|
|
||||||
await git.push();
|
|
||||||
}
|
|
||||||
|
@@ -7,9 +7,9 @@ import {
|
|||||||
renderer,
|
renderer,
|
||||||
REPO_USERNAME,
|
REPO_USERNAME,
|
||||||
generateMd,
|
generateMd,
|
||||||
pushNewFiles,
|
|
||||||
MARKDOWN_FILENAME,
|
MARKDOWN_FILENAME,
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
|
import git from './git';
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
// set default template
|
// set default template
|
||||||
@@ -43,7 +43,7 @@ export async function main() {
|
|||||||
|
|
||||||
const markdown: string = await generateMd(rendered);
|
const markdown: string = await generateMd(rendered);
|
||||||
|
|
||||||
await pushNewFiles([
|
await git.pushNewFiles([
|
||||||
{
|
{
|
||||||
filename: MARKDOWN_FILENAME,
|
filename: MARKDOWN_FILENAME,
|
||||||
data: markdown,
|
data: markdown,
|
||||||
@@ -55,7 +55,7 @@ export async function main() {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run(): Promise<any> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await main();
|
await main();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Reference in New Issue
Block a user