@ornikar/repo-config 13.1.1 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [13.2.0](https://github.com/ornikar/shared-configs/compare/@ornikar/repo-config@13.1.1...@ornikar/repo-config@13.2.0) (2023-11-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **repo-config:** add husky no push on main prepush hook [no issue] ([#1032](https://github.com/ornikar/shared-configs/issues/1032)) ([390dcce](https://github.com/ornikar/shared-configs/commit/390dcce9fef422bbc6e47ff3911f2400d875dc0a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## [13.1.1](https://github.com/ornikar/shared-configs/compare/@ornikar/repo-config@13.1.0...@ornikar/repo-config@13.1.1) (2023-11-14)
|
|
7
16
|
|
|
8
17
|
**Note:** Version bump only for package @ornikar/repo-config
|
|
@@ -6,8 +6,42 @@ const fs = require('node:fs');
|
|
|
6
6
|
const path = require('node:path');
|
|
7
7
|
const husky = require('husky');
|
|
8
8
|
const { readYarnConfigFile } = require('../yarn');
|
|
9
|
+
const { noPushOnMain } = require('./no-push-on-main');
|
|
9
10
|
const { phrasePrePush } = require('./phrase-pre-push');
|
|
10
11
|
|
|
12
|
+
function createPrepushHook(commands, prePushHookPostContent) {
|
|
13
|
+
const script = `
|
|
14
|
+
# get current branch name
|
|
15
|
+
currentBranch=$(git rev-parse --abbrev-ref HEAD)
|
|
16
|
+
|
|
17
|
+
# get current branch ref
|
|
18
|
+
branch_ref=$(git symbolic-ref HEAD)
|
|
19
|
+
|
|
20
|
+
# autodetect main branch (usually master or main)
|
|
21
|
+
mainBranch=$(LANG=en_US git remote show origin | grep "HEAD branch" | cut -d' ' -f5)
|
|
22
|
+
|
|
23
|
+
# z40 is the value matching the empty blob/commit/tree SHA (zero x 40)
|
|
24
|
+
z40=0000000000000000000000000000000000000000
|
|
25
|
+
|
|
26
|
+
while read local_ref local_sha remote_ref remote_sha
|
|
27
|
+
do
|
|
28
|
+
if [[ "$local_ref" == "$branch_ref" ]]
|
|
29
|
+
then
|
|
30
|
+
${noPushOnMain.trim().split('\n').join('\n ')}
|
|
31
|
+
${commands.join(' && ')}${
|
|
32
|
+
(prePushHookPostContent || '') &&
|
|
33
|
+
`
|
|
34
|
+
if [ "$?" = 0 ]
|
|
35
|
+
then
|
|
36
|
+
${prePushHookPostContent}
|
|
37
|
+
fi`
|
|
38
|
+
}
|
|
39
|
+
fi
|
|
40
|
+
done
|
|
41
|
+
`;
|
|
42
|
+
return `${script.trim()}\n`;
|
|
43
|
+
}
|
|
44
|
+
|
|
11
45
|
const ensureLegacyHuskyConfigDeleted = () => {
|
|
12
46
|
try {
|
|
13
47
|
fs.unlinkSync(path.resolve('husky.config.js'));
|
|
@@ -135,39 +169,28 @@ fi
|
|
|
135
169
|
writeHook('post-rewrite', postHookContent);
|
|
136
170
|
}
|
|
137
171
|
|
|
138
|
-
const
|
|
139
|
-
const prePushHook = [];
|
|
172
|
+
const prePushHookCommands = [];
|
|
140
173
|
|
|
141
174
|
if (shouldRunTest()) {
|
|
142
175
|
if (pkg.scripts.test === 'node --test') {
|
|
143
|
-
|
|
176
|
+
prePushHookCommands.push('CI=true yarn test');
|
|
144
177
|
} else {
|
|
145
|
-
|
|
146
|
-
'# autodetect main branch (usually master or main)',
|
|
147
|
-
'mainBranch=$(LANG=en_US git remote show origin | grep "HEAD branch" | cut -d\' \' -f5)',
|
|
148
|
-
'',
|
|
149
|
-
);
|
|
150
|
-
prePushHook.push('CI=true yarn test --changedSince=origin/$mainBranch');
|
|
178
|
+
prePushHookCommands.push('CI=true yarn test --changedSince=origin/$mainBranch');
|
|
151
179
|
}
|
|
152
180
|
}
|
|
153
181
|
|
|
154
182
|
if (shouldRunChecks()) {
|
|
155
|
-
|
|
183
|
+
prePushHookCommands.push('yarn run checks');
|
|
156
184
|
}
|
|
157
185
|
|
|
158
|
-
if (
|
|
186
|
+
if (prePushHookCommands.length > 0) {
|
|
159
187
|
let prePushHookPostContent = '';
|
|
160
188
|
const phraseConfigPath = '.phrase.yml';
|
|
161
189
|
if (fs.existsSync(phraseConfigPath)) {
|
|
162
190
|
prePushHookPostContent += phrasePrePush;
|
|
163
191
|
}
|
|
164
192
|
|
|
165
|
-
writeHook(
|
|
166
|
-
'pre-push',
|
|
167
|
-
(prePushHookPreCommands ? [...prePushHookPreCommands, ''].join('\n') : '') +
|
|
168
|
-
prePushHook.join(' && ') +
|
|
169
|
-
prePushHookPostContent,
|
|
170
|
-
);
|
|
193
|
+
writeHook('pre-push', createPrepushHook(prePushHookCommands, prePushHookPostContent));
|
|
171
194
|
} else {
|
|
172
195
|
ensureHookDeleted('pre-push');
|
|
173
196
|
}
|
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
exports.phrasePrePush = `
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
if [ "$remote_sha" = $z40 ]
|
|
5
|
+
then
|
|
6
|
+
# New branch, examine all commits since first commit
|
|
7
|
+
range="$local_sha"
|
|
8
|
+
else
|
|
9
|
+
# Update to existing branch, examine new commits
|
|
10
|
+
range="$remote_sha..$local_sha"
|
|
11
|
+
fi
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else
|
|
17
|
-
# Update to existing branch, examine new commits
|
|
18
|
-
range="$remote_sha..$local_sha"
|
|
19
|
-
fi
|
|
20
|
-
|
|
21
|
-
# Check for Translations in commit
|
|
22
|
-
translation=\`git --glob-pathspecs diff "$range" -- "@ornikar/*/translations/**" "@ornikar/*/src/translations/**"\`
|
|
23
|
-
if [ -n "$translation" ]
|
|
24
|
-
then
|
|
25
|
-
branch_name=$(git branch --show-current)
|
|
26
|
-
echo >&2 "🦜 Found translation(s) in commit in $range"
|
|
27
|
-
echo >&2 "Pushing $branch_name to Phrase"
|
|
28
|
-
yarn phrase push
|
|
29
|
-
fi
|
|
30
|
-
fi
|
|
31
|
-
done
|
|
13
|
+
# Check for Translations in commit
|
|
14
|
+
translation=\`git --glob-pathspecs diff "$range" -- "@ornikar/*/translations/**" "@ornikar/*/src/translations/**"\`
|
|
15
|
+
if [ -n "$translation" ]
|
|
16
|
+
then
|
|
17
|
+
branch_name=$(git branch --show-current)
|
|
18
|
+
echo >&2 "🦜 Found translation(s) in commit in $range"
|
|
19
|
+
echo >&2 "Pushing $branch_name to Phrase"
|
|
20
|
+
yarn phrase push
|
|
21
|
+
fi
|
|
32
22
|
`;
|