Skip to content

Commit

Permalink
Merge pull request #4 from Readme-Workflows/version-replacer-readme
Browse files Browse the repository at this point in the history
Version replacer readme
  • Loading branch information
abhijoshi2k authored Jul 20, 2021
2 parents 17879e0 + b837ecc commit c643f7e
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
7 changes: 7 additions & 0 deletions .github/changelogReplacer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"search": "{TBA}",
"replace": "DATETIME",
"eval": true
}
]
7 changes: 7 additions & 0 deletions .github/versionReplacer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"search": "{version}",
"replace": "'v' + require('../package.json').version",
"eval": true
}
]
26 changes: 26 additions & 0 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Replace placeholders

on:
release:
types: [published]
branches:
- main
workflow_dispatch: # Allow manual trigger

jobs:
replace:
runs-on: ubuntu-latest
name: Replace Placeholders in File.

steps:
- uses: actions/checkout@v2
- uses: Readme-Workflows/readme-replacer@main
with:
CUSTOM_REPLACER_FILE: "./.github/changelogReplacer.json"
DATE_FORMAT: 'DD-MM-YYYY "UTC"'
TEMPLATE_FILE: "./CHANGELOG.md"
COMMIT_FILE: "./CHANGELOG.md"

- uses: Readme-Workflows/readme-replacer@main
with:
CUSTOM_REPLACER_FILE: "./.github/versionReplacer.json"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
name: Replace Placeholders in File.

steps:
- uses: actions/checkout@2.3.4
- uses: actions/checkout@v2
# Please replace {version} with the latest available release.
- uses: Readme-Workflows/readme-replacer@{version}
env:
Expand Down
77 changes: 77 additions & 0 deletions TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[default]: https://github.com/Readme-Workflows/readme-replacer/blob/main/src/replacers.json
[discord]: https://discord.gg/2a9VC4AK6x

# Readme-Replacer

Readme-Replacer is a GitHub Action that allows you define your own collections of placeholder text to replace with specific values.
The Action is designed to be as flexible as possible and to work with other Actions.

## Setup

To Set up the Action, first create a new workflow file and populate it with the following values:
```yaml
name: Replace placeholders

on:
schedule:
- cron: '*/30 * * * *' # Activate every 30 minutes
workflow_dispatch: # Allow manual trigger

jobs:
replace:
runs-on: ubuntu-latest
name: Replace Placeholders in File.

steps:
- uses: actions/checkout@v2
- uses: Readme-Workflows/readme-replacer@{version}
env:
GITHUB_TOKEN: {{ secrets.GITHUB_TOKEN }}
with:
# Those are all default values and only are shown for demonstration
TEMPLATE_FILE: './TEMPLATE.md'
COMMIT_FILE: './README.md'
CUSTOM_REPLACER_FILE: './.github/customReplacer.json'
```
### Options
| Option | Function | Default |
| ---------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| `GH_USERNAME` | Name of the user used. | `Repository Owner` |
| `TEMPLATE_FILE` | The template MD file to get content from. | `./TEMPLATE.md` |
| `COMMIT_FILE` | The target MD file to update with the template. | `./README.md` |
| `CUSTOM_REPLACER_FILE` | JSON file that contains the placeholders and their replacements. | `./.github/customReplacer.json` |
| `DATE_FORMAT` | Format used to display the date in. | `dddd, mmmm, dS, yyyy, h:MM:ss TT` |
| `TIMEZONE` | Timezone to use for the date fomatting. Can be a relative GMT-time (i.e. `+2:00`) or Locale-based. | `0` |
| `COMMIT_MESSAGE` | Message to use for the commit. | `⚡ Update README by replacing keywords` |
| `COMMIT_EMAIL` | E-Mail used for the Committer. | `41898282+github-actions[bot]@users.noreply.github.com` |
| `COMMIT_NAME` | Name used for the Committer. | `replacer-bot` |

### Replacer JSON file

A key-feature of this Action is the ability to define your own placeholders and their replacement for it.
This is done by creating and using a JSON file (Called `customReplacer.json` and located within the `.github` directory) and configuring it to have the right values.

The structure of the JSON file may look like this:
```json
[
{
"search": "{foo}",
"replace": "Bar",
"eval": false
}
]
```
Here is a quick rundown of the different options:

- `search` is the text that the Action should look for in the Template file. It can be any text you like.
- `replace` is the value that the `search` value should be replaced with. In our example above would any appearance of `{foo}` be replaced with `Bar`.
- `eval` is a boolean to set whether the `replace` value should be evaluated by the Action for further manipulation. It essentially allows you to set Javascript code that would be executed when the Action runs (i.e. `new Date().toLocaleString()` would be executed as Javascript code and the result used as replacement for the search string).

You can find a [JSON file][default] which would be the default placeholders in the workflow in this repository.

## Links

- [Discord]
Make sure to follow the `#news` channel for any updates towards this and any other Products of the Readme-Workflows Organisation!
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21497,7 +21497,7 @@ const COMMIT_MESSAGE = core.getInput("COMMIT_MESSAGE");
const COMMIT_EMAIL = core.getInput("COMMIT_EMAIL");
const COMMIT_NAME = core.getInput("COMMIT_NAME");

const TIMEZONE = getDate(
const DATETIME = getDate(
core.getInput("DATE_FORMAT"),
core.getInput("TIMEZONE")
);
Expand All @@ -21510,7 +21510,7 @@ module.exports = {
COMMIT_MESSAGE,
COMMIT_EMAIL,
COMMIT_NAME,
TIMEZONE,
DATETIME,
};


Expand All @@ -21520,7 +21520,7 @@ module.exports = {
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

// eslint-disable-next-line no-unused-vars
const { TIMEZONE } = __nccwpck_require__(4570);
const { DATETIME } = __nccwpck_require__(4570);

/**
* Copyright (c) 2021 The Readme-Workflows organisation and Contributors
Expand Down Expand Up @@ -21672,7 +21672,7 @@ module.exports = (format, timezone) => {
/* eslint-disable no-unused-vars */
const fs = __nccwpck_require__(5747);

const { CUSTOM_REPLACER_FILE, TIMEZONE } = __nccwpck_require__(4570);
const { CUSTOM_REPLACER_FILE, DATETIME } = __nccwpck_require__(4570);
const customReplacer = __nccwpck_require__(9239);
const replacers = __nccwpck_require__(3656);

Expand Down Expand Up @@ -21763,7 +21763,7 @@ module.exports = JSON.parse('{"name":"signale","version":"1.4.0","description":"
/***/ ((module) => {

"use strict";
module.exports = JSON.parse('[{"search":"{replace: DATE}","replace":"TIMEZONE","eval":true},{"search":"{octicons/issueClosed}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueClosed.svg)","eval":false},{"search":"{octicons/issueClosedOld}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueClosedOld.svg)","eval":false},{"search":"{octicons/issueOpened}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueOpened.svg)","eval":false},{"search":"{octicons/issueOpenedOld}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueOpenedOld.svg)","eval":false},{"search":"{octicons/issueNeutral}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueNeutral.svg)","eval":false},{"search":"{octicons/issueDrafted}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueDrafted.svg)","eval":false},{"search":"{octicons/issueReopened}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueReopened.svg)","eval":false},{"search":"{octicons/prOpened}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestOpened.svg)","eval":false},{"search":"{octicons/prClosed}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestClosed.svg)","eval":false},{"search":"{octicons/prMerged}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestMerged.svg)","eval":false},{"search":"{octicons/prNeutral}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestNeutral.svg)","eval":false},{"search":"{octicons/comment}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Comment.svg)","eval":false},{"search":"{octicons/requestedChanges}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/RequestedChanges.svg)","eval":false},{"search":"{octicons/approved}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/ApprovedChanges.svg)","eval":false},{"search":"{octicons/repo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Repository.svg)","eval":false},{"search":"{octicons/release}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Release.svg)","eval":false},{"search":"{octicons/star}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/StarredRepository.svg)","eval":false},{"search":"{octicons/wiki}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Wiki.svg)","eval":false},{"search":"{octicons/forkedRepo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/ForkedRepository.svg)","eval":false},{"search":"{octicons/people}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/People.svg)","eval":false},{"search":"{octicons/discussions}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Discussions.svg)","eval":false},{"search":"{octicons/license}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/License.svg)","eval":false},{"search":"{octicons/unwatchRepo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/UnwatchRepository.svg)","eval":false},{"search":"{octicons/watchRepo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/WatchRepository.svg)","eval":false},{"search":"{gifs/wave}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/gifs/wave.gif)","eval":false}]');
module.exports = JSON.parse('[{"comment":"Adds date and time in format specified in DATE_FORMAT input in YAML","search":"{replace: DATE}","replace":"DATETIME","eval":true},{"search":"{octicons/issueClosed}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueClosed.svg)","eval":false},{"search":"{octicons/issueClosedOld}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueClosedOld.svg)","eval":false},{"search":"{octicons/issueOpened}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueOpened.svg)","eval":false},{"search":"{octicons/issueOpenedOld}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueOpenedOld.svg)","eval":false},{"search":"{octicons/issueNeutral}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueNeutral.svg)","eval":false},{"search":"{octicons/issueDrafted}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueDrafted.svg)","eval":false},{"search":"{octicons/issueReopened}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueReopened.svg)","eval":false},{"search":"{octicons/prOpened}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestOpened.svg)","eval":false},{"search":"{octicons/prClosed}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestClosed.svg)","eval":false},{"search":"{octicons/prMerged}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestMerged.svg)","eval":false},{"search":"{octicons/prNeutral}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/PullRequestNeutral.svg)","eval":false},{"search":"{octicons/comment}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Comment.svg)","eval":false},{"search":"{octicons/requestedChanges}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/RequestedChanges.svg)","eval":false},{"search":"{octicons/approved}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/ApprovedChanges.svg)","eval":false},{"search":"{octicons/repo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Repository.svg)","eval":false},{"search":"{octicons/release}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Release.svg)","eval":false},{"search":"{octicons/star}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/StarredRepository.svg)","eval":false},{"search":"{octicons/wiki}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Wiki.svg)","eval":false},{"search":"{octicons/forkedRepo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/ForkedRepository.svg)","eval":false},{"search":"{octicons/people}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/People.svg)","eval":false},{"search":"{octicons/discussions}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/Discussions.svg)","eval":false},{"search":"{octicons/license}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/License.svg)","eval":false},{"search":"{octicons/unwatchRepo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/UnwatchRepository.svg)","eval":false},{"search":"{octicons/watchRepo}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/WatchRepository.svg)","eval":false},{"search":"{gifs/wave}","replace":"![image](https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/gifs/wave.gif)","eval":false}]');

/***/ }),

Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const COMMIT_MESSAGE = core.getInput("COMMIT_MESSAGE");
const COMMIT_EMAIL = core.getInput("COMMIT_EMAIL");
const COMMIT_NAME = core.getInput("COMMIT_NAME");

const TIMEZONE = getDate(
const DATETIME = getDate(
core.getInput("DATE_FORMAT"),
core.getInput("TIMEZONE")
);
Expand All @@ -26,5 +26,5 @@ module.exports = {
COMMIT_MESSAGE,
COMMIT_EMAIL,
COMMIT_NAME,
TIMEZONE,
DATETIME,
};
2 changes: 1 addition & 1 deletion src/customReplacer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line no-unused-vars
const { TIMEZONE } = require("./config");
const { DATETIME } = require("./config");

/**
* Copyright (c) 2021 The Readme-Workflows organisation and Contributors
Expand Down
2 changes: 1 addition & 1 deletion src/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable no-unused-vars */
const fs = require("fs");

const { CUSTOM_REPLACER_FILE, TIMEZONE } = require("./config");
const { CUSTOM_REPLACER_FILE, DATETIME } = require("./config");
const customReplacer = require("./customReplacer");
const replacers = require("./replacers.json");

Expand Down
3 changes: 2 additions & 1 deletion src/replacers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[
{
"comment": "Adds date and time in format specified in DATE_FORMAT input in YAML",
"search": "{replace: DATE}",
"replace": "TIMEZONE",
"replace": "DATETIME",
"eval": true
},
{
Expand Down

0 comments on commit c643f7e

Please sign in to comment.