Skip to content

Commit

Permalink
fix: normalize template file loadup
Browse files Browse the repository at this point in the history
  • Loading branch information
simonecorsi committed May 11, 2022
1 parent ec10b79 commit 445f562
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ You can see an example of the output at my own [simonecorsi/awesome](https://git

<!-- toc -->

- [Table of Contents](#table-of-contents)
- [Documentation](#documentation)
- [Requirements](#requirements)
- [Configuration](#configuration)
Expand All @@ -21,32 +20,34 @@ You can see an example of the output at my own [simonecorsi/awesome](https://git

### Requirements

- An empty repository
- A personal github api key
- An empty repository
- A personal github api key

### Configuration

The service can be configured setting the appropriate environment variables or writing an `.env` file.

| Variable | Description | Default |
| -------------- | ------------------------------------------- | -------------------------------- |
| `api-token` | Personal github api token. | `${{ secrets.API_TOKEN }}` |
| `github-token` | Action Token | `${{ secrets.GITHUB_TOKEN }}` |
| `github-name` | Name used for the commit, default to action | Github Action |
| `github-email` | email used for commit, default to action | actions@users.noreply.github.com |
| Variable | Description | Default |
| ----------------- | -------------------------------------------------------------------- | -------------------------------- |
| `api-token` | Personal github api token. | `${{ secrets.API_TOKEN }}` |
| `github-token` | Action Token | `${{ secrets.GITHUB_TOKEN }}` |
| `github-name` | Name used for the commit, default to action | Github Action |
| `github-email` | email used for commit, default to action | actions@users.noreply.github.com |
| `template-path` | Custom output template file ([EJS](https://ejs.co/) template engine) | [TEMPLATE.ejs](./TEMPLATE.ejs) |
| `output-filename` | Output filename | `README.md` |

#### `api-token`

The Personal API Access Token is mandatory to fetch stars from the API without incurring in Rate Limits.

You'll have to generate a [personal api token](https://github.com/settings/tokens/new) and then add
You'll have to generate a [personal api token](https://github.com/settings/tokens/new) and then add

## Example workflow

```yml
name: Update awesome list

on:
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
Expand All @@ -63,5 +64,4 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-email: ${{ secrets.USER_EMAIL }}
github-name: ${{ github.repository_owner }}

```
3 changes: 1 addition & 2 deletions src/template.ts → TEMPLATE.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default `# <%= username %> Awesome List [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
# <%= username %> Awesome List [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)

> :star: generated with [simonecorsi/mawesome](https://github.com/simonecorsi/mawesome)

Expand All @@ -11,4 +11,3 @@ export default `# <%= username %> Awesome List [![Awesome](https://cdn.rawgit.co
<% } %>
<% } %>
`;
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import * as core from '@actions/core';
import { readdir, readFile } from 'fs/promises';
import { readFile } from 'fs/promises';
import ghStarFetch from 'gh-star-fetch';

import {
Expand All @@ -9,11 +10,13 @@ import {
pushNewFiles,
MARKDOWN_FILENAME,
} from './helpers';
import MD_TEMPLATE from './template';

export async function main() {
// set default template
let template = MD_TEMPLATE;
let template = await readFile(
path.resolve(__dirname, './TEMPLATE.md'),
'utf8'
);

// get template if found in the repo
const customTemplatePath = core.getInput('template-path');
Expand Down

0 comments on commit 445f562

Please sign in to comment.