From c00c27e3195ab881018b40697129e5791d5e2dcf Mon Sep 17 00:00:00 2001 From: Aditia Prasetio Date: Thu, 14 Mar 2024 15:23:36 +0700 Subject: [PATCH] add possibility to change filename package.json (#239) * add possibility to change filename * Update README.md add documentation for package filename --- README.md | 10 ++++++++++ index.js | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15eafb615..867ceb1f5 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,16 @@ Param to parse the location of the desired package.json (optional). Example: PACKAGEJSON_DIR: 'frontend' ``` +#### **PACKAGE_FILENAME:** +Param to use another file for detect version (optional). Example: +```yaml +- name: 'Automated Version Bump' + uses: 'phips28/gh-action-bump-version@master' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PACKAGE_FILENAME: 'app.json' +``` + #### **TARGET-BRANCH:** Set a custom target branch to use when bumping the version. Useful in cases such as updating the version on master after a tag has been set (optional). Example: ```yaml diff --git a/index.js b/index.js index 232f23143..bc089a6a3 100644 --- a/index.js +++ b/index.js @@ -266,8 +266,9 @@ const pkg = getPackageJson(); })(); function getPackageJson() { - const pathToPackage = path.join(workspace, 'package.json'); - if (!existsSync(pathToPackage)) throw new Error("package.json could not be found in your project's root."); + const packageJSONFileName = process.env.PACKAGE_FILENAME || 'package.json'; + const pathToPackage = path.join(workspace, packageJSONFileName); + if (!existsSync(pathToPackage)) throw new Error(packageJSONFileName + " could not be found in your project's root."); return require(pathToPackage); }