Skip to content

Commit 5ba8bac

Browse files
authored
chore: add prettier config (#157)
* feat: add prettier config * feat: format files and prettier check
1 parent bcc7f3a commit 5ba8bac

File tree

11 files changed

+175
-130
lines changed

11 files changed

+175
-130
lines changed

.github/workflows/format.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Check Formatting
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
check-format:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set Node.js 18.x
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
20+
- name: Install
21+
run: yarn --frozen-lockfile
22+
23+
- name: Check formatting with Prettier
24+
run: npx prettier --check .

.husky/pre-commit

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
npx --no-install lint-staged --allow-empty
55

66
node tools/pre-commit.js
7-

.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
dist
3+
/yarn.lock
4+
/.vscode
5+
/.idea
6+
/.github
7+
/.husky
8+
/.yarn
9+
/.env

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"endOfLine": "lf",
4+
"tabWidth": 2
5+
}

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,37 @@ jobs:
7676
# Common names for this branch include main and master.
7777
#
7878
# Default: main
79-
main-branch-name: ""
79+
main-branch-name: ''
8080

8181
# Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job.
8282
#
8383
# Default: true
84-
set-environment-variables-for-job: ""
84+
set-environment-variables-for-job: ''
8585

8686
# By default, if no successful workflow run is found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead.
8787
#
8888
# Default: false
89-
error-on-no-successful-workflow: ""
89+
error-on-no-successful-workflow: ''
9090

9191
# Fallback SHA to use if no successful workflow run is found. This can be useful in scenarios where you need a specific commit as a reference for comparison, especially in newly set up repositories or those with sparse workflow runs.
9292
#
9393
# Default: ""
94-
fallback-sha: ""
94+
fallback-sha: ''
9595

9696
# The type of event to check for the last successful commit corresponding to that workflow-id, e.g. push, pull_request, release etc.
9797
#
9898
# Default: push
99-
last-successful-event: ""
99+
last-successful-event: ''
100100

101101
# The path where your repository is. This is only required for cases where the repository code is checked out or moved to a specific path.
102102
#
103103
# Default: .
104-
working-directory: ""
104+
working-directory: ''
105105

106106
# The ID of the github action workflow to check for successful run or the name of the file name containing the workflow.
107107
# E.g. 'ci.yml'. If not provided, current workflow id will be used
108108
#
109-
workflow-id: ""
109+
workflow-id: ''
110110
```
111111
112112
<!-- end configuration-options -->
@@ -123,8 +123,8 @@ jobs:
123123
runs-on: ubuntu-latest
124124
name: My Job
125125
permissions:
126-
contents: "read"
127-
actions: "read"
126+
contents: 'read'
127+
actions: 'read'
128128
```
129129

130130
<!-- end permissions-in-v2 -->

action.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
name: "Nx set SHAs"
2-
description: "Derives SHAs for base and head for use in nx affected commands, optionally setting them as env variables for the current job"
1+
name: 'Nx set SHAs'
2+
description: 'Derives SHAs for base and head for use in nx affected commands, optionally setting them as env variables for the current job'
33

44
inputs:
55
main-branch-name:
6-
description: "The name of the main branch in your repo, used as the target of PRs. E.g. main, master etc"
7-
default: "main"
6+
description: 'The name of the main branch in your repo, used as the target of PRs. E.g. main, master etc'
7+
default: 'main'
88
set-environment-variables-for-job:
9-
description: "Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job"
10-
default: "true"
9+
description: 'Applies the derived SHAs for base and head as NX_BASE and NX_HEAD environment variables within the current Job'
10+
default: 'true'
1111
error-on-no-successful-workflow:
12-
description: "By default, if no successful workflow is found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead."
13-
default: "false"
12+
description: 'By default, if no successful workflow is found on the main branch to determine the SHA, we will log a warning and use HEAD~1. Enable this option to error and exit instead.'
13+
default: 'false'
1414
fallback-sha:
15-
description: "Fallback SHA to use if no successful workflow run is found."
15+
description: 'Fallback SHA to use if no successful workflow run is found.'
1616
required: false
17-
default: ""
17+
default: ''
1818
last-successful-event:
19-
description: "The type of event to check for the last successful commit corresponding to that workflow-id, e.g. push, pull_request, release etc"
20-
default: "push"
19+
description: 'The type of event to check for the last successful commit corresponding to that workflow-id, e.g. push, pull_request, release etc'
20+
default: 'push'
2121
working-directory:
22-
description: "The directory where your repository is located"
23-
default: "."
22+
description: 'The directory where your repository is located'
23+
default: '.'
2424
workflow-id:
25-
description: "The ID of the workflow to track or name of the file name. E.g. ci.yml. Defaults to current workflow"
25+
description: 'The ID of the workflow to track or name of the file name. E.g. ci.yml. Defaults to current workflow'
2626

2727
outputs:
2828
base:
@@ -36,7 +36,7 @@ outputs:
3636
value: ${{ steps.setSHAs.outputs.noPreviousBuild }}
3737

3838
runs:
39-
using: "composite"
39+
using: 'composite'
4040
steps:
4141
- name: Set base and head SHAs used for nx affected
4242
id: setSHAs
@@ -68,5 +68,5 @@ runs:
6868
echo "NX_HEAD=${{ steps.setSHAs.outputs.head }}" >> $GITHUB_ENV
6969
echo "NX_BASE and NX_HEAD environment variables have been set for the current Job"
7070
branding:
71-
icon: "terminal"
72-
color: "blue"
71+
icon: 'terminal'
72+
color: 'blue'

dist/index.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37868,7 +37868,7 @@ const lastSuccessfulEvent = process.argv[5];
3786837868
const workingDirectory = process.argv[6];
3786937869
const workflowId = process.argv[7];
3787037870
const fallbackSHA = process.argv[8];
37871-
const defaultWorkingDirectory = ".";
37871+
const defaultWorkingDirectory = '.';
3787237872
const ProxifiedClient = action_1.Octokit.plugin(proxyPlugin);
3787337873
let BASE_SHA;
3787437874
(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -37877,20 +37877,20 @@ let BASE_SHA;
3787737877
process.chdir(workingDirectory);
3787837878
}
3787937879
else {
37880-
process.stdout.write("\n");
37880+
process.stdout.write('\n');
3788137881
process.stdout.write(`WARNING: Working directory '${workingDirectory}' doesn't exist.\n`);
3788237882
}
3788337883
}
37884-
const headResult = (0, child_process_1.spawnSync)("git", ["rev-parse", "HEAD"], {
37885-
encoding: "utf-8",
37884+
const headResult = (0, child_process_1.spawnSync)('git', ['rev-parse', 'HEAD'], {
37885+
encoding: 'utf-8',
3788637886
});
3788737887
const HEAD_SHA = headResult.stdout;
37888-
if ((["pull_request", "pull_request_target"].includes(eventName) &&
37888+
if ((['pull_request', 'pull_request_target'].includes(eventName) &&
3788937889
!github.context.payload.pull_request.merged) ||
37890-
eventName == "merge_group") {
37890+
eventName == 'merge_group') {
3789137891
try {
3789237892
const mergeBaseRef = yield findMergeBaseRef();
37893-
const baseResult = (0, child_process_1.spawnSync)("git", ["merge-base", `origin/${mainBranchName}`, mergeBaseRef], { encoding: "utf-8" });
37893+
const baseResult = (0, child_process_1.spawnSync)('git', ['merge-base', `origin/${mainBranchName}`, mergeBaseRef], { encoding: 'utf-8' });
3789437894
BASE_SHA = baseResult.stdout;
3789537895
}
3789637896
catch (e) {
@@ -37907,41 +37907,41 @@ let BASE_SHA;
3790737907
return;
3790837908
}
3790937909
if (!BASE_SHA) {
37910-
if (errorOnNoSuccessfulWorkflow === "true") {
37910+
if (errorOnNoSuccessfulWorkflow === 'true') {
3791137911
reportFailure(mainBranchName);
3791237912
return;
3791337913
}
3791437914
else {
37915-
process.stdout.write("\n");
37915+
process.stdout.write('\n');
3791637916
process.stdout.write(`WARNING: Unable to find a successful workflow run on 'origin/${mainBranchName}', or the latest successful workflow was connected to a commit which no longer exists on that branch (e.g. if that branch was rebased)\n`);
3791737917
if (fallbackSHA) {
3791837918
BASE_SHA = fallbackSHA;
3791937919
process.stdout.write(`Using provided fallback SHA: ${fallbackSHA}\n`);
3792037920
}
3792137921
else {
3792237922
process.stdout.write(`We are therefore defaulting to use HEAD~1 on 'origin/${mainBranchName}'\n`);
37923-
process.stdout.write("\n");
37923+
process.stdout.write('\n');
3792437924
process.stdout.write(`NOTE: You can instead make this a hard error by setting 'error-on-no-successful-workflow' on the action in your workflow.\n`);
37925-
process.stdout.write("\n");
37926-
const commitCountOutput = (0, child_process_1.spawnSync)("git", ["rev-list", "--count", `origin/${mainBranchName}`], { encoding: "utf-8" }).stdout;
37925+
process.stdout.write('\n');
37926+
const commitCountOutput = (0, child_process_1.spawnSync)('git', ['rev-list', '--count', `origin/${mainBranchName}`], { encoding: 'utf-8' }).stdout;
3792737927
const commitCount = parseInt(stripNewLineEndings(commitCountOutput), 10);
37928-
const LAST_COMMIT_CMD = `origin/${mainBranchName}${commitCount > 1 ? "~1" : ""}`;
37929-
const baseRes = (0, child_process_1.spawnSync)("git", ["rev-parse", LAST_COMMIT_CMD], {
37930-
encoding: "utf-8",
37928+
const LAST_COMMIT_CMD = `origin/${mainBranchName}${commitCount > 1 ? '~1' : ''}`;
37929+
const baseRes = (0, child_process_1.spawnSync)('git', ['rev-parse', LAST_COMMIT_CMD], {
37930+
encoding: 'utf-8',
3793137931
});
3793237932
BASE_SHA = baseRes.stdout;
3793337933
}
37934-
core.setOutput("noPreviousBuild", "true");
37934+
core.setOutput('noPreviousBuild', 'true');
3793537935
}
3793637936
}
3793737937
else {
37938-
process.stdout.write("\n");
37938+
process.stdout.write('\n');
3793937939
process.stdout.write(`Found the last successful workflow run on 'origin/${mainBranchName}'\n`);
3794037940
process.stdout.write(`Commit: ${BASE_SHA}\n`);
3794137941
}
3794237942
}
37943-
core.setOutput("base", stripNewLineEndings(BASE_SHA));
37944-
core.setOutput("head", stripNewLineEndings(HEAD_SHA));
37943+
core.setOutput('base', stripNewLineEndings(BASE_SHA));
37944+
core.setOutput('head', stripNewLineEndings(HEAD_SHA));
3794537945
}))();
3794637946
function reportFailure(branchName) {
3794737947
core.setFailed(`
@@ -37953,7 +37953,7 @@ function reportFailure(branchName) {
3795337953
- If no, then you might have changed your git history and those commits no longer exist.`);
3795437954
}
3795537955
function proxyPlugin(octokit) {
37956-
octokit.hook.before("request", (options) => {
37956+
octokit.hook.before('request', (options) => {
3795737957
const proxy = (0, proxy_from_env_1.getProxyForUrl)(options.baseUrl);
3795837958
if (proxy) {
3795937959
options.request.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
@@ -37975,7 +37975,7 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
3797537975
run_id,
3797637976
})
3797737977
.then(({ data: { workflow_id } }) => workflow_id);
37978-
process.stdout.write("\n");
37978+
process.stdout.write('\n');
3797937979
process.stdout.write(`Workflow Id not provided. Using workflow '${workflow_id}'\n`);
3798037980
}
3798137981
// fetch all workflow runs on a given repo/branch/workflow with push and success
@@ -37984,26 +37984,26 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
3798437984
owner,
3798537985
repo,
3798637986
// on some workflow runs we do not have branch property
37987-
branch: lastSuccessfulEvent === "push" ||
37988-
lastSuccessfulEvent === "workflow_dispatch"
37987+
branch: lastSuccessfulEvent === 'push' ||
37988+
lastSuccessfulEvent === 'workflow_dispatch'
3798937989
? branch
3799037990
: undefined,
3799137991
workflow_id,
3799237992
event: lastSuccessfulEvent,
37993-
status: "success",
37993+
status: 'success',
3799437994
})
3799537995
.then(({ data: { workflow_runs } }) => workflow_runs.map((run) => run.head_sha));
3799637996
return yield findExistingCommit(octokit, branch, shas);
3799737997
});
3799837998
}
3799937999
function findMergeBaseRef() {
3800038000
return __awaiter(this, void 0, void 0, function* () {
38001-
if (eventName == "merge_group") {
38001+
if (eventName == 'merge_group') {
3800238002
const mergeQueueBranch = yield findMergeQueueBranch();
3800338003
return `origin/${mergeQueueBranch}`;
3800438004
}
3800538005
else {
38006-
return "HEAD";
38006+
return 'HEAD';
3800738007
}
3800838008
});
3800938009
}
@@ -38016,9 +38016,9 @@ function findMergeQueueBranch() {
3801638016
return __awaiter(this, void 0, void 0, function* () {
3801738017
const pull_number = findMergeQueuePr();
3801838018
if (!pull_number) {
38019-
throw new Error("Failed to determine PR number");
38019+
throw new Error('Failed to determine PR number');
3802038020
}
38021-
process.stdout.write("\n");
38021+
process.stdout.write('\n');
3802238022
process.stdout.write(`Found PR #${pull_number} from merge queue branch\n`);
3802338023
const octokit = new ProxifiedClient();
3802438024
const result = yield octokit.request(`GET /repos/${owner}/${repo}/pulls/${pull_number}`, { owner, repo, pull_number: +pull_number });
@@ -38044,17 +38044,17 @@ function findExistingCommit(octokit, branchName, shas) {
3804438044
function commitExists(octokit, branchName, commitSha) {
3804538045
return __awaiter(this, void 0, void 0, function* () {
3804638046
try {
38047-
(0, child_process_1.spawnSync)("git", ["cat-file", "-e", commitSha], {
38048-
stdio: ["pipe", "pipe", null],
38047+
(0, child_process_1.spawnSync)('git', ['cat-file', '-e', commitSha], {
38048+
stdio: ['pipe', 'pipe', null],
3804938049
});
3805038050
// Check the commit exists in general
38051-
yield octokit.request("GET /repos/{owner}/{repo}/commits/{commit_sha}", {
38051+
yield octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}', {
3805238052
owner,
3805338053
repo,
3805438054
commit_sha: commitSha,
3805538055
});
3805638056
// Check the commit exists on the expected main branch (it will not in the case of a rebased main branch)
38057-
const commits = yield octokit.request("GET /repos/{owner}/{repo}/commits", {
38057+
const commits = yield octokit.request('GET /repos/{owner}/{repo}/commits', {
3805838058
owner,
3805938059
repo,
3806038060
sha: branchName,
@@ -38071,7 +38071,7 @@ function commitExists(octokit, branchName, commitSha) {
3807138071
* Strips LF line endings from given string
3807238072
*/
3807338073
function stripNewLineEndings(string) {
38074-
return string.replace("\n", "");
38074+
return string.replace('\n', '');
3807538075
}
3807638076

3807738077

0 commit comments

Comments
 (0)