diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/.github/changelogReplacer.json b/.github/changelogReplacer.json new file mode 100644 index 0000000..2c08beb --- /dev/null +++ b/.github/changelogReplacer.json @@ -0,0 +1,7 @@ +[ + { + "search": "{TBA}", + "replace": "DATETIME", + "eval": true + } +] diff --git a/.github/versionReplacer.json b/.github/versionReplacer.json new file mode 100644 index 0000000..2233a0d --- /dev/null +++ b/.github/versionReplacer.json @@ -0,0 +1,7 @@ +[ + { + "search": "{version}", + "replace": "'v' + require('../package.json').version", + "eval": true + } +] diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml new file mode 100644 index 0000000..980a575 --- /dev/null +++ b/.github/workflows/post-release.yml @@ -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" diff --git a/README.md b/README.md index 417f5f1..722d671 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/TEMPLATE.md b/TEMPLATE.md new file mode 100644 index 0000000..cc1a243 --- /dev/null +++ b/TEMPLATE.md @@ -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! diff --git a/dist/index.js b/dist/index.js index ceddd40..312f47a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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") ); @@ -21510,7 +21510,7 @@ module.exports = { COMMIT_MESSAGE, COMMIT_EMAIL, COMMIT_NAME, - TIMEZONE, + DATETIME, }; @@ -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 @@ -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); @@ -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}]'); /***/ }), diff --git a/src/config.js b/src/config.js index fad0fe9..7a151cf 100644 --- a/src/config.js +++ b/src/config.js @@ -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") ); @@ -26,5 +26,5 @@ module.exports = { COMMIT_MESSAGE, COMMIT_EMAIL, COMMIT_NAME, - TIMEZONE, + DATETIME, }; diff --git a/src/customReplacer.js b/src/customReplacer.js index afec37b..786fa13 100644 --- a/src/customReplacer.js +++ b/src/customReplacer.js @@ -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 diff --git a/src/replace.js b/src/replace.js index e443f2f..68f6ad1 100644 --- a/src/replace.js +++ b/src/replace.js @@ -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"); diff --git a/src/replacers.json b/src/replacers.json index bfc90a4..0ddf4e3 100644 --- a/src/replacers.json +++ b/src/replacers.json @@ -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 }, {