Skip to content

Commit 4d53601

Browse files
committed
fix(ci): prevent false-success publish + force sync to origin/master
1 parent 477e618 commit 4d53601

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

.github/workflows/publish.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ on:
66

77
jobs:
88
publish:
9+
concurrency:
10+
group: publish
11+
cancel-in-progress: false
912
runs-on: ubuntu-latest
1013
env:
1114
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
1215
steps:
13-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
1419
- name: Setup Node
1520
uses: actions/setup-node@v4
1621
with:

packages/foo-api-ci-tools/dist/git.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/foo-api-ci-tools/dist/git.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/foo-api-ci-tools/dist/shell.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/foo-api-ci-tools/dist/shell.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/foo-api-ci-tools/src/git.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export const config = () => {
1111

1212
export const checkout = (branch = 'master') => {
1313
shell(`git remote set-url origin ${GIT_URL}`);
14-
shell('git fetch');
15-
shell(`git checkout ${branch} && git pull`);
14+
// Ensure we are exactly at the remote head (no shallow/merge weirdness in CI)
15+
shell(`git fetch --tags --prune origin ${branch}`);
16+
shell(`git checkout ${branch}`);
17+
shell(`git reset --hard origin/${branch}`);
1618
};
1719

1820
export const add = () => {

packages/foo-api-ci-tools/src/shell.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ export default (command: string) => {
44
const result = shell.exec(command);
55
const isGrep = command.includes('grep');
66
const isGitCommit = command.includes('git commit');
7+
const isLernaPublish = command.includes('lerna publish');
78

89
// for some reason grep commands can return exit code `123`
910
// when nothing was returned (and everything is fine)
1011
if (!isGitCommit && result.code !== 0 && (!isGrep || result.code !== 123)) {
1112
throw Error(result.stderr);
1213
}
1314

15+
// Lerna can sometimes exit 0 while still refusing to publish (e.g. EBEHIND).
16+
// Treat that as a hard failure so CI doesn't falsely report success.
17+
if (isLernaPublish && (result.stderr || '').includes('EBEHIND')) {
18+
throw Error(result.stderr);
19+
}
20+
1421
return result.stdout;
1522
};

0 commit comments

Comments
 (0)