diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 15be3f1..d0bafec 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,9 +2,9 @@
In order to publish a new version of the action, simply update the "version" in the package.json and merge into the main branch.
-If your changed files include `find-successful-workflow.js`, then you should also update the bundle in the `dist` folder using `npm run build`.
+If your changed files include `src/main.ts`, then you should also update the bundle in the `dist` folder using `npm run build`.
-The workflow at ./github/workflows/publish.yml will apply the new version in the form of tags, which is all that is needed to publish an Action.
+The workflow at `./github/workflows/publish.yml` will apply the new version in the form of tags, which is all that is needed to publish an Action.
Example of tags applied:
diff --git a/README.md b/README.md
index a86b4cf..24f7d2f 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
-Set SHAs Action
+Set SHAs Action
-✨ A Github Action which sets the base and head SHAs required for the `nx affected` commands in CI
+✨ A GitHub Action which sets the base and head SHAs required for the `nx affected` commands in CI
- [Example Usage](#example-usage)
- [Configuration Options](#configuration-options)
@@ -141,7 +141,7 @@ This Action supports usage of your own self-hosted runners, but since it uses Gi
jobs:
myjob:
runs-on: self-hosted
- container: my-org/my-amazing-image:v1.2.3-fresh
+ container: my-org/my-amazing-image:v1.2.3-fresh
name: My Job
steps:
- uses: actions/checkout@v4
diff --git a/action.yml b/action.yml
index 2d10fc5..00a2f14 100644
--- a/action.yml
+++ b/action.yml
@@ -2,6 +2,9 @@ name: 'Nx set SHAs'
description: 'Derives SHAs for base and head for use in nx affected commands, optionally setting them as env variables for the current job'
inputs:
+ token:
+ description: 'The GitHub token used to perform git operations'
+ default: ${{ github.token }}
main-branch-name:
description: 'The name of the main branch in your repo, used as the target of PRs. E.g. main, master etc'
default: 'main'
@@ -27,46 +30,15 @@ inputs:
outputs:
base:
description: The value intended for use with --base or NX_BASE in all subsequent `nx affected` commands within the current workflow
- value: ${{ steps.setSHAs.outputs.base }}
head:
description: The value intended for use with --head or NX_HEAD in all subsequent `nx affected` commands within the current workflow
- value: ${{ steps.setSHAs.outputs.head }}
noPreviousBuild:
description: "Used to check if a previous run was found in order to perform additional logic later on in your workflow, the only possible values is the string 'true', otherwise it won't be set"
- value: ${{ steps.setSHAs.outputs.noPreviousBuild }}
runs:
- using: 'composite'
- steps:
- - name: Set base and head SHAs used for nx affected
- id: setSHAs
- shell: bash
- env:
- gh_token: ${{ github.token }}
- main_branch_name: ${{ inputs.main-branch-name }}
- error_on_no_successful_workflow: ${{ inputs.error-on-no-successful-workflow }}
- last_successful_event: ${{ inputs.last-successful-event }}
- working_directory: ${{ inputs.working-directory }}
- working_id: ${{ inputs.workflow-id }}
- run: node "$GITHUB_ACTION_PATH/dist/index.js" "$gh_token" "$main_branch_name" "$error_on_no_successful_workflow" "$last_successful_event" "$working_directory" "$working_id"
+ using: 'node20'
+ main: 'dist/index.js'
- - name: Log base and head SHAs used for nx affected
- shell: bash
- run: |
- echo "Base SHA"
- echo ${{ steps.setSHAs.outputs.base }}
- echo ""
- echo "Head SHA"
- echo ${{ steps.setSHAs.outputs.head }}
- echo ""
-
- - name: Optionally set the derived SHAs as NX_BASE and NX_HEAD environment variables for the current job
- shell: bash
- if: ${{ inputs.set-environment-variables-for-job == 'true' }}
- run: |
- echo "NX_BASE=${{ steps.setSHAs.outputs.base }}" >> $GITHUB_ENV
- echo "NX_HEAD=${{ steps.setSHAs.outputs.head }}" >> $GITHUB_ENV
- echo "NX_BASE and NX_HEAD environment variables have been set for the current Job"
branding:
icon: 'terminal'
color: 'blue'
diff --git a/dist/index.js b/dist/index.js
index 01d3178..07e7c72 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -37838,7 +37838,7 @@ function wrappy (fn, cb) {
/***/ }),
-/***/ 5468:
+/***/ 399:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
@@ -37861,13 +37861,12 @@ const fs_1 = __nccwpck_require__(7147);
const https_proxy_agent_1 = __nccwpck_require__(7219);
const proxy_from_env_1 = __nccwpck_require__(3329);
const { runId, repo: { repo, owner }, eventName, } = github.context;
-process.env.GITHUB_TOKEN = process.argv[2];
-const mainBranchName = process.argv[3];
-const errorOnNoSuccessfulWorkflow = process.argv[4];
-const lastSuccessfulEvent = process.argv[5];
-const workingDirectory = process.argv[6];
-const workflowId = process.argv[7];
-const fallbackSHA = process.argv[8];
+const mainBranchName = core.getInput('main-branch-name');
+const errorOnNoSuccessfulWorkflow = core.getBooleanInput('error-on-no-successful-workflow');
+const lastSuccessfulEvent = core.getInput('last-successful-event');
+const workingDirectory = core.getInput('working-directory');
+const workflowId = core.getInput('workflow-id');
+const fallbackSHA = core.getInput('fallback-sha');
const defaultWorkingDirectory = '.';
const ProxifiedClient = action_1.Octokit.plugin(proxyPlugin);
let BASE_SHA;
@@ -37884,7 +37883,7 @@ let BASE_SHA;
const headResult = (0, child_process_1.spawnSync)('git', ['rev-parse', 'HEAD'], {
encoding: 'utf-8',
});
- const HEAD_SHA = headResult.stdout;
+ let HEAD_SHA = headResult.stdout;
if ((['pull_request', 'pull_request_target'].includes(eventName) &&
!github.context.payload.pull_request.merged) ||
eventName == 'merge_group') {
@@ -37907,7 +37906,7 @@ let BASE_SHA;
return;
}
if (!BASE_SHA) {
- if (errorOnNoSuccessfulWorkflow === 'true') {
+ if (errorOnNoSuccessfulWorkflow) {
reportFailure(mainBranchName);
return;
}
@@ -37940,8 +37939,24 @@ let BASE_SHA;
process.stdout.write(`Commit: ${BASE_SHA}\n`);
}
}
- core.setOutput('base', stripNewLineEndings(BASE_SHA));
- core.setOutput('head', stripNewLineEndings(HEAD_SHA));
+ BASE_SHA = stripNewLineEndings(BASE_SHA);
+ HEAD_SHA = stripNewLineEndings(HEAD_SHA);
+ // Log base and head SHAs used for nx affected
+ process.stdout.write('\n');
+ process.stdout.write('Base SHA');
+ process.stdout.write(BASE_SHA);
+ process.stdout.write('\n');
+ process.stdout.write('Head SHA');
+ process.stdout.write(HEAD_SHA);
+ process.stdout.write('\n');
+ // Optionally set the derived SHAs as NX_BASE and NX_HEAD environment variables for the current job
+ if (core.getBooleanInput('set-environment-variables-for-job')) {
+ core.exportVariable('NX_BASE', BASE_SHA);
+ core.exportVariable('NX_HEAD', HEAD_SHA);
+ process.stdout.write('NX_BASE and NX_HEAD environment variables have been set for the current Job');
+ }
+ core.setOutput('base', BASE_SHA);
+ core.setOutput('head', HEAD_SHA);
}))();
function reportFailure(branchName) {
core.setFailed(`
@@ -38383,7 +38398,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
-/******/ var __webpack_exports__ = __nccwpck_require__(5468);
+/******/ var __webpack_exports__ = __nccwpck_require__(399);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
diff --git a/package.json b/package.json
index 7412322..3a705f6 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"license": "MIT",
"description": "This package.json is here purely to control the version of the Action, in combination with https://github.com/JamesHenry/publish-shell-action",
"scripts": {
- "build": "ncc build find-successful-workflow.ts --license licenses.txt",
+ "build": "ncc build src/main.ts -o dist --license licenses.txt",
"prepare": "is-ci || husky install",
"format:check": "prettier --check .",
"format": "prettier --write ."
diff --git a/find-successful-workflow.ts b/src/main.ts
similarity index 86%
rename from find-successful-workflow.ts
rename to src/main.ts
index c2c1324..a6b657c 100644
--- a/find-successful-workflow.ts
+++ b/src/main.ts
@@ -11,13 +11,14 @@ const {
repo: { repo, owner },
eventName,
} = github.context;
-process.env.GITHUB_TOKEN = process.argv[2];
-const mainBranchName = process.argv[3];
-const errorOnNoSuccessfulWorkflow = process.argv[4];
-const lastSuccessfulEvent = process.argv[5];
-const workingDirectory = process.argv[6];
-const workflowId = process.argv[7];
-const fallbackSHA = process.argv[8];
+const mainBranchName = core.getInput('main-branch-name');
+const errorOnNoSuccessfulWorkflow = core.getBooleanInput(
+ 'error-on-no-successful-workflow',
+);
+const lastSuccessfulEvent = core.getInput('last-successful-event');
+const workingDirectory = core.getInput('working-directory');
+const workflowId = core.getInput('workflow-id');
+const fallbackSHA = core.getInput('fallback-sha');
const defaultWorkingDirectory = '.';
const ProxifiedClient = Octokit.plugin(proxyPlugin);
@@ -38,7 +39,7 @@ let BASE_SHA: string;
const headResult = spawnSync('git', ['rev-parse', 'HEAD'], {
encoding: 'utf-8',
});
- const HEAD_SHA = headResult.stdout;
+ let HEAD_SHA = headResult.stdout;
if (
(['pull_request', 'pull_request_target'].includes(eventName) &&
@@ -73,7 +74,7 @@ let BASE_SHA: string;
}
if (!BASE_SHA) {
- if (errorOnNoSuccessfulWorkflow === 'true') {
+ if (errorOnNoSuccessfulWorkflow) {
reportFailure(mainBranchName);
return;
} else {
@@ -122,8 +123,30 @@ let BASE_SHA: string;
process.stdout.write(`Commit: ${BASE_SHA}\n`);
}
}
- core.setOutput('base', stripNewLineEndings(BASE_SHA));
- core.setOutput('head', stripNewLineEndings(HEAD_SHA));
+
+ BASE_SHA = stripNewLineEndings(BASE_SHA);
+ HEAD_SHA = stripNewLineEndings(HEAD_SHA);
+
+ // Log base and head SHAs used for nx affected
+ process.stdout.write('\n');
+ process.stdout.write('Base SHA');
+ process.stdout.write(BASE_SHA);
+ process.stdout.write('\n');
+ process.stdout.write('Head SHA');
+ process.stdout.write(HEAD_SHA);
+ process.stdout.write('\n');
+
+ // Optionally set the derived SHAs as NX_BASE and NX_HEAD environment variables for the current job
+ if (core.getBooleanInput('set-environment-variables-for-job')) {
+ core.exportVariable('NX_BASE', BASE_SHA);
+ core.exportVariable('NX_HEAD', HEAD_SHA);
+ process.stdout.write(
+ 'NX_BASE and NX_HEAD environment variables have been set for the current Job',
+ );
+ }
+
+ core.setOutput('base', BASE_SHA);
+ core.setOutput('head', HEAD_SHA);
})();
function reportFailure(branchName: string): void {