Skip to content

Commit c7cc904

Browse files
authored
fix: publishing from default branch via workflow dispatch (#57)
1 parent e049557 commit c7cc904

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

dist/publish/index.js

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

dist/publish/index.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.

src/publish.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,43 @@ describe('publish', () => {
115115
)
116116
})
117117

118+
test('publishes if all rulesets are applied when triggered through workflow dispatch', async () => {
119+
Object.defineProperty(github, 'context', {
120+
value: {
121+
ref: 'refs/heads/wallet-accounts/10.x',
122+
repo,
123+
eventName: 'workflow_dispatch',
124+
payload: {},
125+
sha: 'abc123',
126+
},
127+
})
128+
129+
when(client.rest.repos.getBranchRules)
130+
.calledWith({
131+
...repo,
132+
branch: 'wallet-accounts/10.x',
133+
})
134+
.mockResolvedValue({
135+
data: [{ ruleset_id: 42 }, { ruleset_id: 73 }],
136+
} as any)
137+
138+
when(core.getMultilineInput)
139+
.calledWith('required-branch-rulesets')
140+
.mockReturnValue(['42', '73'])
141+
142+
await publish()
143+
144+
expect(execFileSync).toHaveBeenCalledWith(
145+
'npx',
146+
['lerna', 'publish', 'from-package', '--yes', '--no-private'],
147+
{ encoding: 'utf8' }
148+
)
149+
})
150+
118151
test('does not publish if required ruleset is missing when triggerd by workflow dispatch', async () => {
119152
Object.defineProperty(github, 'context', {
120153
value: {
121-
ref: 'wallet-accounts/10.x',
154+
ref: 'refs/heads/wallet-accounts/10.x',
122155
repo,
123156
eventName: 'workflow_dispatch',
124157
payload: {},

src/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function publish() {
2828
}
2929

3030
if (requiredRulesets.length > 0) {
31-
const publishBranch = pr?.base.ref ?? github.context.ref
31+
const publishBranch = pr?.base.ref ?? github.context.ref.replace(/^refs\/heads\//, '')
3232
const { data: rules } = await client.rest.repos.getBranchRules({
3333
...repo,
3434
branch: publishBranch,

0 commit comments

Comments
 (0)