Skip to content

Commit

Permalink
Add parse_file.js
Browse files Browse the repository at this point in the history
- takes a path, regex, and regex flags and returns the captured group
    - probably needs some refinement
- add an example changelog entry
  • Loading branch information
CobyPear committed Dec 18, 2023
1 parent d25f4d5 commit ba3ee48
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:
git commit -m "Release $VERSION"
git tag "$VERSION"
git push --tags
- name: Release
run: |
node ./scripts/parse_file.js ./README.MD #{3}\s[0-9+\.]+[-\w+]+([\s\w0-9]+)#{3}\s[0-9+\.]+.* gm
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ See the robots hard at work.

### 0.1.1-dev

Example Changelog

### 0.1.0 (6 June 2023)
* Initial Release [[1](https://github.com/pantheon-systems/plugin-pipeline-example/pull/1)]
20 changes: 20 additions & 0 deletions scripts/parse_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
const { readFileSync } = require("fs");
const { resolve } = require("path");

// get the args
const [path, regex, flags] = process.argv.slice(2);
// throw if necessary args are missing
if (!path) {
throw new Error("Please provide a path to the file to parse");
}
if (!regex) {
throw new Error("Please provide a regex to parse the file");
}

const filePath = resolve(__dirname,'..', path);
const fileContent = fs.readFileSync(filePath, "utf8");
const rx = new RegExp(regex, flags);

Check failure

Code scanning / CodeQL

Regular expression injection High

This regular expression is constructed from a
command-line argument
.
const matches = fileContent.matchAll(rx);

console.log([...matches][0][1].trim());

0 comments on commit ba3ee48

Please sign in to comment.