Skip to content

Commit

Permalink
#15: first pass on token file replacer part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed May 8, 2024
1 parent 32d4735 commit b294707
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ All inputs are optional however if you are **NOT** triggering this action on a `
| `sync-tags` | A list of other tags to sync back to the repo. | `[]` | `v2` |
| `sync-token` | A Personal Access Token to use for `git` sync ops. | `${{ github.token }}` | `${{ secrets.MY_PAT }}` |
| `sync-username` | The username to use when syncing changes back to the repo. | `github-actions` | `w.t.riker` |
| `update-files` | The username to use when syncing changes back to the repo. | `[]` | `CHANGELOG.md` |
| `update-files-header` | The username to use when syncing changes back to the repo. | `false` | `{{ NEW VERSION }}` |
| `update-files-meta` | The username to use when syncing changes back to the repo. | `[]` | `NEW_VERSION=${{ github.event.release.tag_name }}` |
| `version-match` | A regex to help find the latest tag. Only used when `version=dev`. | `v[0-9].*` | `[1-2].*` |
| `lando-plugin` | A special easy-mode setting to prepare and valdiate Lando plugins. | `false` | `true` |

Expand Down
23 changes: 17 additions & 6 deletions prepare-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,29 @@ const main = async () => {
core.info(`{{ ${token} }}: ${value}`);
content = content.replace(new RegExp(`\\{\\{\\s*${token}\\s*\\}\\}`, 'g'), value);
}

// prepend update header
if (inputs.updateHeader !== false && typeof inputs.updateHeader === 'string') {
content = `${inputs.updateHeader}${content}`;
}
core.endGroup();

// debug and update the file with new contents
core.debug(`updated ${file} with new contents:`);
fs.writeFileSync(file, content);
core.debug(`updated ${file} with tokens:`);
core.debug(`${fs.readFileSync(file, {encoding: 'utf-8'})}`);
}

// loop through and update-files with header
if (inputs.updateHeader !== false && typeof inputs.updateHeader === 'string') {
for (const file of inputs.updateFiles.filter(file => fs.existsSync(file))) {
core.startGroup(`Updating ${file} with update-files-header content`);
core.info(`update-header: ${inputs.updateHeader}`);
core.endGroup();

const content = fs.readFileSync(file, {encoding: 'utf-8'});
fs.writeFileSync(file, `${inputs.updateHeader}${content}`);

core.debug(`updated ${file} with update-header:`);
core.debug(`${fs.readFileSync(file, {encoding: 'utf-8'})}`);
}
}

// if using landoPlugin ez-mode then validate lando plugin
// it should be impossible to get here at this point but lets keep this just in case
if (inputs.landoPlugin && !isLandoPlugin(jsonfile.readFileSync(inputs.pjson))) {
Expand Down

0 comments on commit b294707

Please # to comment.