Skip to content

Commit

Permalink
Added ability to use custom directories
Browse files Browse the repository at this point in the history
This bring the ability to configure a custom directory in the case that the package is not in the root folder. It also checks in case that the user added the whole package json file and it strips it out.
  • Loading branch information
Bullrich authored and pascalgn committed Jul 21, 2020
1 parent f93f535 commit c908b8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
tag_name: "v%s"
tag_message: "v%s"
commit_pattern: "^Release (\\S+)"
package_path: "."
env: # More info about the environment variables in the README
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings
Expand All @@ -43,6 +44,7 @@ These inputs are optional: that means that if you don't enter them, default valu
- `tag_name`: the name pattern of the new tag
- `tag_message`: the message pattern of the new tag
- `commit_pattern`: pattern that the commit message needs to follow
- `package_path`: custom directory in the case that the package is not in the root.

### Environment variables

Expand Down
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

const process = require("process");
const { join } = require("path");
const { join, dirname } = require("path");
const { spawn } = require("child_process");
const { readFile } = require("fs");

async function main() {
const dir = process.env.GITHUB_WORKSPACE || "/github/workspace";
const dir = getPackageDirectory();

const eventFile =
process.env.GITHUB_EVENT_PATH || "/github/workflow/event.json";
Expand Down Expand Up @@ -40,6 +40,16 @@ function getEnv(name) {
return process.env[name] || process.env[`INPUT_${name}`];
}

function getPackageDirectory() {
const workspace = process.env.GITHUB_WORKSPACE || "/github/workspace";
const packageLocation = join(workspace, placeholderEnv("PACKAGE_PATH", "."));
if(packageLocation.includes("package.json")){
return dirname(packageLocation);
}

return packageLocation;
}

function placeholderEnv(name, defaultValue) {
const str = getEnv(name);
if (!str) {
Expand Down

0 comments on commit c908b8e

Please sign in to comment.